LSL_Api.cs 715 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617961896199620962196229623962496259626962796289629963096319632963396349635963696379638963996409641964296439644964596469647964896499650965196529653965496559656965796589659966096619662966396649665966696679668966996709671967296739674967596769677967896799680968196829683968496859686968796889689969096919692969396949695969696979698969997009701970297039704970597069707970897099710971197129713971497159716971797189719972097219722972397249725972697279728972997309731973297339734973597369737973897399740974197429743974497459746974797489749975097519752975397549755975697579758975997609761976297639764976597669767976897699770977197729773977497759776977797789779978097819782978397849785978697879788978997909791979297939794979597969797979897999800980198029803980498059806980798089809981098119812981398149815981698179818981998209821982298239824982598269827982898299830983198329833983498359836983798389839984098419842984398449845984698479848984998509851985298539854985598569857985898599860986198629863986498659866986798689869987098719872987398749875987698779878987998809881988298839884988598869887988898899890989198929893989498959896989798989899990099019902990399049905990699079908990999109911991299139914991599169917991899199920992199229923992499259926992799289929993099319932993399349935993699379938993999409941994299439944994599469947994899499950995199529953995499559956995799589959996099619962996399649965996699679968996999709971997299739974997599769977997899799980998199829983998499859986998799889989999099919992999399949995999699979998999910000100011000210003100041000510006100071000810009100101001110012100131001410015100161001710018100191002010021100221002310024100251002610027100281002910030100311003210033100341003510036100371003810039100401004110042100431004410045100461004710048100491005010051100521005310054100551005610057100581005910060100611006210063100641006510066100671006810069100701007110072100731007410075100761007710078100791008010081100821008310084100851008610087100881008910090100911009210093100941009510096100971009810099101001010110102101031010410105101061010710108101091011010111101121011310114101151011610117101181011910120101211012210123101241012510126101271012810129101301013110132101331013410135101361013710138101391014010141101421014310144101451014610147101481014910150101511015210153101541015510156101571015810159101601016110162101631016410165101661016710168101691017010171101721017310174101751017610177101781017910180101811018210183101841018510186101871018810189101901019110192101931019410195101961019710198101991020010201102021020310204102051020610207102081020910210102111021210213102141021510216102171021810219102201022110222102231022410225102261022710228102291023010231102321023310234102351023610237102381023910240102411024210243102441024510246102471024810249102501025110252102531025410255102561025710258102591026010261102621026310264102651026610267102681026910270102711027210273102741027510276102771027810279102801028110282102831028410285102861028710288102891029010291102921029310294102951029610297102981029910300103011030210303103041030510306103071030810309103101031110312103131031410315103161031710318103191032010321103221032310324103251032610327103281032910330103311033210333103341033510336103371033810339103401034110342103431034410345103461034710348103491035010351103521035310354103551035610357103581035910360103611036210363103641036510366103671036810369103701037110372103731037410375103761037710378103791038010381103821038310384103851038610387103881038910390103911039210393103941039510396103971039810399104001040110402104031040410405104061040710408104091041010411104121041310414104151041610417104181041910420104211042210423104241042510426104271042810429104301043110432104331043410435104361043710438104391044010441104421044310444104451044610447104481044910450104511045210453104541045510456104571045810459104601046110462104631046410465104661046710468104691047010471104721047310474104751047610477104781047910480104811048210483104841048510486104871048810489104901049110492104931049410495104961049710498104991050010501105021050310504105051050610507105081050910510105111051210513105141051510516105171051810519105201052110522105231052410525105261052710528105291053010531105321053310534105351053610537105381053910540105411054210543105441054510546105471054810549105501055110552105531055410555105561055710558105591056010561105621056310564105651056610567105681056910570105711057210573105741057510576105771057810579105801058110582105831058410585105861058710588105891059010591105921059310594105951059610597105981059910600106011060210603106041060510606106071060810609106101061110612106131061410615106161061710618106191062010621106221062310624106251062610627106281062910630106311063210633106341063510636106371063810639106401064110642106431064410645106461064710648106491065010651106521065310654106551065610657106581065910660106611066210663106641066510666106671066810669106701067110672106731067410675106761067710678106791068010681106821068310684106851068610687106881068910690106911069210693106941069510696106971069810699107001070110702107031070410705107061070710708107091071010711107121071310714107151071610717107181071910720107211072210723107241072510726107271072810729107301073110732107331073410735107361073710738107391074010741107421074310744107451074610747107481074910750107511075210753107541075510756107571075810759107601076110762107631076410765107661076710768107691077010771107721077310774107751077610777107781077910780107811078210783107841078510786107871078810789107901079110792107931079410795107961079710798107991080010801108021080310804108051080610807108081080910810108111081210813108141081510816108171081810819108201082110822108231082410825108261082710828108291083010831108321083310834108351083610837108381083910840108411084210843108441084510846108471084810849108501085110852108531085410855108561085710858108591086010861108621086310864108651086610867108681086910870108711087210873108741087510876108771087810879108801088110882108831088410885108861088710888108891089010891108921089310894108951089610897108981089910900109011090210903109041090510906109071090810909109101091110912109131091410915109161091710918109191092010921109221092310924109251092610927109281092910930109311093210933109341093510936109371093810939109401094110942109431094410945109461094710948109491095010951109521095310954109551095610957109581095910960109611096210963109641096510966109671096810969109701097110972109731097410975109761097710978109791098010981109821098310984109851098610987109881098910990109911099210993109941099510996109971099810999110001100111002110031100411005110061100711008110091101011011110121101311014110151101611017110181101911020110211102211023110241102511026110271102811029110301103111032110331103411035110361103711038110391104011041110421104311044110451104611047110481104911050110511105211053110541105511056110571105811059110601106111062110631106411065110661106711068110691107011071110721107311074110751107611077110781107911080110811108211083110841108511086110871108811089110901109111092110931109411095110961109711098110991110011101111021110311104111051110611107111081110911110111111111211113111141111511116111171111811119111201112111122111231112411125111261112711128111291113011131111321113311134111351113611137111381113911140111411114211143111441114511146111471114811149111501115111152111531115411155111561115711158111591116011161111621116311164111651116611167111681116911170111711117211173111741117511176111771117811179111801118111182111831118411185111861118711188111891119011191111921119311194111951119611197111981119911200112011120211203112041120511206112071120811209112101121111212112131121411215112161121711218112191122011221112221122311224112251122611227112281122911230112311123211233112341123511236112371123811239112401124111242112431124411245112461124711248112491125011251112521125311254112551125611257112581125911260112611126211263112641126511266112671126811269112701127111272112731127411275112761127711278112791128011281112821128311284112851128611287112881128911290112911129211293112941129511296112971129811299113001130111302113031130411305113061130711308113091131011311113121131311314113151131611317113181131911320113211132211323113241132511326113271132811329113301133111332113331133411335113361133711338113391134011341113421134311344113451134611347113481134911350113511135211353113541135511356113571135811359113601136111362113631136411365113661136711368113691137011371113721137311374113751137611377113781137911380113811138211383113841138511386113871138811389113901139111392113931139411395113961139711398113991140011401114021140311404114051140611407114081140911410114111141211413114141141511416114171141811419114201142111422114231142411425114261142711428114291143011431114321143311434114351143611437114381143911440114411144211443114441144511446114471144811449114501145111452114531145411455114561145711458114591146011461114621146311464114651146611467114681146911470114711147211473114741147511476114771147811479114801148111482114831148411485114861148711488114891149011491114921149311494114951149611497114981149911500115011150211503115041150511506115071150811509115101151111512115131151411515115161151711518115191152011521115221152311524115251152611527115281152911530115311153211533115341153511536115371153811539115401154111542115431154411545115461154711548115491155011551115521155311554115551155611557115581155911560115611156211563115641156511566115671156811569115701157111572115731157411575115761157711578115791158011581115821158311584115851158611587115881158911590115911159211593115941159511596115971159811599116001160111602116031160411605116061160711608116091161011611116121161311614116151161611617116181161911620116211162211623116241162511626116271162811629116301163111632116331163411635116361163711638116391164011641116421164311644116451164611647116481164911650116511165211653116541165511656116571165811659116601166111662116631166411665116661166711668116691167011671116721167311674116751167611677116781167911680116811168211683116841168511686116871168811689116901169111692116931169411695116961169711698116991170011701117021170311704117051170611707117081170911710117111171211713117141171511716117171171811719117201172111722117231172411725117261172711728117291173011731117321173311734117351173611737117381173911740117411174211743117441174511746117471174811749117501175111752117531175411755117561175711758117591176011761117621176311764117651176611767117681176911770117711177211773117741177511776117771177811779117801178111782117831178411785117861178711788117891179011791117921179311794117951179611797117981179911800118011180211803118041180511806118071180811809118101181111812118131181411815118161181711818118191182011821118221182311824118251182611827118281182911830118311183211833118341183511836118371183811839118401184111842118431184411845118461184711848118491185011851118521185311854118551185611857118581185911860118611186211863118641186511866118671186811869118701187111872118731187411875118761187711878118791188011881118821188311884118851188611887118881188911890118911189211893118941189511896118971189811899119001190111902119031190411905119061190711908119091191011911119121191311914119151191611917119181191911920119211192211923119241192511926119271192811929119301193111932119331193411935119361193711938119391194011941119421194311944119451194611947119481194911950119511195211953119541195511956119571195811959119601196111962119631196411965119661196711968119691197011971119721197311974119751197611977119781197911980119811198211983119841198511986119871198811989119901199111992119931199411995119961199711998119991200012001120021200312004120051200612007120081200912010120111201212013120141201512016120171201812019120201202112022120231202412025120261202712028120291203012031120321203312034120351203612037120381203912040120411204212043120441204512046120471204812049120501205112052120531205412055120561205712058120591206012061120621206312064120651206612067120681206912070120711207212073120741207512076120771207812079120801208112082120831208412085120861208712088120891209012091120921209312094120951209612097120981209912100121011210212103121041210512106121071210812109121101211112112121131211412115121161211712118121191212012121121221212312124121251212612127121281212912130121311213212133121341213512136121371213812139121401214112142121431214412145121461214712148121491215012151121521215312154121551215612157121581215912160121611216212163121641216512166121671216812169121701217112172121731217412175121761217712178121791218012181121821218312184121851218612187121881218912190121911219212193121941219512196121971219812199122001220112202122031220412205122061220712208122091221012211122121221312214122151221612217122181221912220122211222212223122241222512226122271222812229122301223112232122331223412235122361223712238122391224012241122421224312244122451224612247122481224912250122511225212253122541225512256122571225812259122601226112262122631226412265122661226712268122691227012271122721227312274122751227612277122781227912280122811228212283122841228512286122871228812289122901229112292122931229412295122961229712298122991230012301123021230312304123051230612307123081230912310123111231212313123141231512316123171231812319123201232112322123231232412325123261232712328123291233012331123321233312334123351233612337123381233912340123411234212343123441234512346123471234812349123501235112352123531235412355123561235712358123591236012361123621236312364123651236612367123681236912370123711237212373123741237512376123771237812379123801238112382123831238412385123861238712388123891239012391123921239312394123951239612397123981239912400124011240212403124041240512406124071240812409124101241112412124131241412415124161241712418124191242012421124221242312424124251242612427124281242912430124311243212433124341243512436124371243812439124401244112442124431244412445124461244712448124491245012451124521245312454124551245612457124581245912460124611246212463124641246512466124671246812469124701247112472124731247412475124761247712478124791248012481124821248312484124851248612487124881248912490124911249212493124941249512496124971249812499125001250112502125031250412505125061250712508125091251012511125121251312514125151251612517125181251912520125211252212523125241252512526125271252812529125301253112532125331253412535125361253712538125391254012541125421254312544125451254612547125481254912550125511255212553125541255512556125571255812559125601256112562125631256412565125661256712568125691257012571125721257312574125751257612577125781257912580125811258212583125841258512586125871258812589125901259112592125931259412595125961259712598125991260012601126021260312604126051260612607126081260912610126111261212613126141261512616126171261812619126201262112622126231262412625126261262712628126291263012631126321263312634126351263612637126381263912640126411264212643126441264512646126471264812649126501265112652126531265412655126561265712658126591266012661126621266312664126651266612667126681266912670126711267212673126741267512676126771267812679126801268112682126831268412685126861268712688126891269012691126921269312694126951269612697126981269912700127011270212703127041270512706127071270812709127101271112712127131271412715127161271712718127191272012721127221272312724127251272612727127281272912730127311273212733127341273512736127371273812739127401274112742127431274412745127461274712748127491275012751127521275312754127551275612757127581275912760127611276212763127641276512766127671276812769127701277112772127731277412775127761277712778127791278012781127821278312784127851278612787127881278912790127911279212793127941279512796127971279812799128001280112802128031280412805128061280712808128091281012811128121281312814128151281612817128181281912820128211282212823128241282512826128271282812829128301283112832128331283412835128361283712838128391284012841128421284312844128451284612847128481284912850128511285212853128541285512856128571285812859128601286112862128631286412865128661286712868128691287012871128721287312874128751287612877128781287912880128811288212883128841288512886128871288812889128901289112892128931289412895128961289712898128991290012901129021290312904129051290612907129081290912910129111291212913129141291512916129171291812919129201292112922129231292412925129261292712928129291293012931129321293312934129351293612937129381293912940129411294212943129441294512946129471294812949129501295112952129531295412955129561295712958129591296012961129621296312964129651296612967129681296912970129711297212973129741297512976129771297812979129801298112982129831298412985129861298712988129891299012991129921299312994129951299612997129981299913000130011300213003130041300513006130071300813009130101301113012130131301413015130161301713018130191302013021130221302313024130251302613027130281302913030130311303213033130341303513036130371303813039130401304113042130431304413045130461304713048130491305013051130521305313054130551305613057130581305913060130611306213063130641306513066130671306813069130701307113072130731307413075130761307713078130791308013081130821308313084130851308613087130881308913090130911309213093130941309513096130971309813099131001310113102131031310413105131061310713108131091311013111131121311313114131151311613117131181311913120131211312213123131241312513126131271312813129131301313113132131331313413135131361313713138131391314013141131421314313144131451314613147131481314913150131511315213153131541315513156131571315813159131601316113162131631316413165131661316713168131691317013171131721317313174131751317613177131781317913180131811318213183131841318513186131871318813189131901319113192131931319413195131961319713198131991320013201132021320313204132051320613207132081320913210132111321213213132141321513216132171321813219132201322113222132231322413225132261322713228132291323013231132321323313234132351323613237132381323913240132411324213243132441324513246132471324813249132501325113252132531325413255132561325713258132591326013261132621326313264132651326613267132681326913270132711327213273132741327513276132771327813279132801328113282132831328413285132861328713288132891329013291132921329313294132951329613297132981329913300133011330213303133041330513306133071330813309133101331113312133131331413315133161331713318133191332013321133221332313324133251332613327133281332913330133311333213333133341333513336133371333813339133401334113342133431334413345133461334713348133491335013351133521335313354133551335613357133581335913360133611336213363133641336513366133671336813369133701337113372133731337413375133761337713378133791338013381133821338313384133851338613387133881338913390133911339213393133941339513396133971339813399134001340113402134031340413405134061340713408134091341013411134121341313414134151341613417134181341913420134211342213423134241342513426134271342813429134301343113432134331343413435134361343713438134391344013441134421344313444134451344613447134481344913450134511345213453134541345513456134571345813459134601346113462134631346413465134661346713468134691347013471134721347313474134751347613477134781347913480134811348213483134841348513486134871348813489134901349113492134931349413495134961349713498134991350013501135021350313504135051350613507135081350913510135111351213513135141351513516135171351813519135201352113522135231352413525135261352713528135291353013531135321353313534135351353613537135381353913540135411354213543135441354513546135471354813549135501355113552135531355413555135561355713558135591356013561135621356313564135651356613567135681356913570135711357213573135741357513576135771357813579135801358113582135831358413585135861358713588135891359013591135921359313594135951359613597135981359913600136011360213603136041360513606136071360813609136101361113612136131361413615136161361713618136191362013621136221362313624136251362613627136281362913630136311363213633136341363513636136371363813639136401364113642136431364413645136461364713648136491365013651136521365313654136551365613657136581365913660136611366213663136641366513666136671366813669136701367113672136731367413675136761367713678136791368013681136821368313684136851368613687136881368913690136911369213693136941369513696136971369813699137001370113702137031370413705137061370713708137091371013711137121371313714137151371613717137181371913720137211372213723137241372513726137271372813729137301373113732137331373413735137361373713738137391374013741137421374313744137451374613747137481374913750137511375213753137541375513756137571375813759137601376113762137631376413765137661376713768137691377013771137721377313774137751377613777137781377913780137811378213783137841378513786137871378813789137901379113792137931379413795137961379713798137991380013801138021380313804138051380613807138081380913810138111381213813138141381513816138171381813819138201382113822138231382413825138261382713828138291383013831138321383313834138351383613837138381383913840138411384213843138441384513846138471384813849138501385113852138531385413855138561385713858138591386013861138621386313864138651386613867138681386913870138711387213873138741387513876138771387813879138801388113882138831388413885138861388713888138891389013891138921389313894138951389613897138981389913900139011390213903139041390513906139071390813909139101391113912139131391413915139161391713918139191392013921139221392313924139251392613927139281392913930139311393213933139341393513936139371393813939139401394113942139431394413945139461394713948139491395013951139521395313954139551395613957139581395913960139611396213963139641396513966139671396813969139701397113972139731397413975139761397713978139791398013981139821398313984139851398613987139881398913990139911399213993139941399513996139971399813999140001400114002140031400414005140061400714008140091401014011140121401314014140151401614017140181401914020140211402214023140241402514026140271402814029140301403114032140331403414035140361403714038140391404014041140421404314044140451404614047140481404914050140511405214053140541405514056140571405814059140601406114062140631406414065140661406714068140691407014071140721407314074140751407614077140781407914080140811408214083140841408514086140871408814089140901409114092140931409414095140961409714098140991410014101141021410314104141051410614107141081410914110141111411214113141141411514116141171411814119141201412114122141231412414125141261412714128141291413014131141321413314134141351413614137141381413914140141411414214143141441414514146141471414814149141501415114152141531415414155141561415714158141591416014161141621416314164141651416614167141681416914170141711417214173141741417514176141771417814179141801418114182141831418414185141861418714188141891419014191141921419314194141951419614197141981419914200142011420214203142041420514206142071420814209142101421114212142131421414215142161421714218142191422014221142221422314224142251422614227142281422914230142311423214233142341423514236142371423814239142401424114242142431424414245142461424714248142491425014251142521425314254142551425614257142581425914260142611426214263142641426514266142671426814269142701427114272142731427414275142761427714278142791428014281142821428314284142851428614287142881428914290142911429214293142941429514296142971429814299143001430114302143031430414305143061430714308143091431014311143121431314314143151431614317143181431914320143211432214323143241432514326143271432814329143301433114332143331433414335143361433714338143391434014341143421434314344143451434614347143481434914350143511435214353143541435514356143571435814359143601436114362143631436414365143661436714368143691437014371143721437314374143751437614377143781437914380143811438214383143841438514386143871438814389143901439114392143931439414395143961439714398143991440014401144021440314404144051440614407144081440914410144111441214413144141441514416144171441814419144201442114422144231442414425144261442714428144291443014431144321443314434144351443614437144381443914440144411444214443144441444514446144471444814449144501445114452144531445414455144561445714458144591446014461144621446314464144651446614467144681446914470144711447214473144741447514476144771447814479144801448114482144831448414485144861448714488144891449014491144921449314494144951449614497144981449914500145011450214503145041450514506145071450814509145101451114512145131451414515145161451714518145191452014521145221452314524145251452614527145281452914530145311453214533145341453514536145371453814539145401454114542145431454414545145461454714548145491455014551145521455314554145551455614557145581455914560145611456214563145641456514566145671456814569145701457114572145731457414575145761457714578145791458014581145821458314584145851458614587145881458914590145911459214593145941459514596145971459814599146001460114602146031460414605146061460714608146091461014611146121461314614146151461614617146181461914620146211462214623146241462514626146271462814629146301463114632146331463414635146361463714638146391464014641146421464314644146451464614647146481464914650146511465214653146541465514656146571465814659146601466114662146631466414665146661466714668146691467014671146721467314674146751467614677146781467914680146811468214683146841468514686146871468814689146901469114692146931469414695146961469714698146991470014701147021470314704147051470614707147081470914710147111471214713147141471514716147171471814719147201472114722147231472414725147261472714728147291473014731147321473314734147351473614737147381473914740147411474214743147441474514746147471474814749147501475114752147531475414755147561475714758147591476014761147621476314764147651476614767147681476914770147711477214773147741477514776147771477814779147801478114782147831478414785147861478714788147891479014791147921479314794147951479614797147981479914800148011480214803148041480514806148071480814809148101481114812148131481414815148161481714818148191482014821148221482314824148251482614827148281482914830148311483214833148341483514836148371483814839148401484114842148431484414845148461484714848148491485014851148521485314854148551485614857148581485914860148611486214863148641486514866148671486814869148701487114872148731487414875148761487714878148791488014881148821488314884148851488614887148881488914890148911489214893148941489514896148971489814899149001490114902149031490414905149061490714908149091491014911149121491314914149151491614917149181491914920149211492214923149241492514926149271492814929149301493114932149331493414935149361493714938149391494014941149421494314944149451494614947149481494914950149511495214953149541495514956149571495814959149601496114962149631496414965149661496714968149691497014971149721497314974149751497614977149781497914980149811498214983149841498514986149871498814989149901499114992149931499414995149961499714998149991500015001150021500315004150051500615007150081500915010150111501215013150141501515016150171501815019150201502115022150231502415025150261502715028150291503015031150321503315034150351503615037150381503915040150411504215043150441504515046150471504815049150501505115052150531505415055150561505715058150591506015061150621506315064150651506615067150681506915070150711507215073150741507515076150771507815079150801508115082150831508415085150861508715088150891509015091150921509315094150951509615097150981509915100151011510215103151041510515106151071510815109151101511115112151131511415115151161511715118151191512015121151221512315124151251512615127151281512915130151311513215133151341513515136151371513815139151401514115142151431514415145151461514715148151491515015151151521515315154151551515615157151581515915160151611516215163151641516515166151671516815169151701517115172151731517415175151761517715178151791518015181151821518315184151851518615187151881518915190151911519215193151941519515196151971519815199152001520115202152031520415205152061520715208152091521015211152121521315214152151521615217152181521915220152211522215223152241522515226152271522815229152301523115232152331523415235152361523715238152391524015241152421524315244152451524615247152481524915250152511525215253152541525515256152571525815259152601526115262152631526415265152661526715268152691527015271152721527315274152751527615277152781527915280152811528215283152841528515286152871528815289152901529115292152931529415295152961529715298152991530015301153021530315304153051530615307153081530915310153111531215313153141531515316153171531815319153201532115322153231532415325153261532715328153291533015331153321533315334153351533615337153381533915340153411534215343153441534515346153471534815349153501535115352153531535415355153561535715358153591536015361153621536315364153651536615367153681536915370153711537215373153741537515376153771537815379153801538115382153831538415385153861538715388153891539015391153921539315394153951539615397153981539915400154011540215403154041540515406154071540815409154101541115412154131541415415154161541715418154191542015421154221542315424154251542615427154281542915430154311543215433154341543515436154371543815439154401544115442154431544415445154461544715448154491545015451154521545315454154551545615457154581545915460154611546215463154641546515466154671546815469154701547115472154731547415475154761547715478154791548015481154821548315484154851548615487154881548915490154911549215493154941549515496154971549815499155001550115502155031550415505155061550715508155091551015511155121551315514155151551615517155181551915520155211552215523155241552515526155271552815529155301553115532155331553415535155361553715538155391554015541155421554315544155451554615547155481554915550155511555215553155541555515556155571555815559155601556115562155631556415565155661556715568155691557015571155721557315574155751557615577155781557915580155811558215583155841558515586155871558815589155901559115592155931559415595155961559715598155991560015601156021560315604156051560615607156081560915610156111561215613156141561515616156171561815619156201562115622156231562415625156261562715628156291563015631156321563315634156351563615637156381563915640156411564215643156441564515646156471564815649156501565115652156531565415655156561565715658156591566015661156621566315664156651566615667156681566915670156711567215673156741567515676156771567815679156801568115682156831568415685156861568715688156891569015691156921569315694156951569615697156981569915700157011570215703157041570515706157071570815709157101571115712157131571415715157161571715718157191572015721157221572315724157251572615727157281572915730157311573215733157341573515736157371573815739157401574115742157431574415745157461574715748157491575015751157521575315754157551575615757157581575915760157611576215763157641576515766157671576815769157701577115772157731577415775157761577715778157791578015781157821578315784157851578615787157881578915790157911579215793157941579515796157971579815799158001580115802158031580415805158061580715808158091581015811158121581315814158151581615817158181581915820158211582215823158241582515826158271582815829158301583115832158331583415835158361583715838158391584015841158421584315844158451584615847158481584915850158511585215853158541585515856158571585815859158601586115862158631586415865158661586715868158691587015871158721587315874158751587615877158781587915880158811588215883158841588515886158871588815889158901589115892158931589415895158961589715898158991590015901159021590315904159051590615907159081590915910159111591215913159141591515916159171591815919159201592115922159231592415925159261592715928159291593015931159321593315934159351593615937159381593915940159411594215943159441594515946159471594815949159501595115952159531595415955159561595715958159591596015961159621596315964159651596615967159681596915970159711597215973159741597515976159771597815979159801598115982159831598415985159861598715988159891599015991159921599315994159951599615997159981599916000160011600216003160041600516006160071600816009160101601116012160131601416015160161601716018160191602016021160221602316024160251602616027160281602916030160311603216033160341603516036160371603816039160401604116042160431604416045160461604716048160491605016051160521605316054160551605616057160581605916060160611606216063160641606516066160671606816069160701607116072160731607416075160761607716078160791608016081160821608316084160851608616087160881608916090160911609216093160941609516096160971609816099161001610116102161031610416105161061610716108161091611016111161121611316114161151611616117161181611916120161211612216123161241612516126161271612816129161301613116132161331613416135161361613716138161391614016141161421614316144161451614616147161481614916150161511615216153161541615516156161571615816159161601616116162161631616416165161661616716168161691617016171161721617316174161751617616177161781617916180161811618216183161841618516186161871618816189161901619116192161931619416195161961619716198161991620016201162021620316204162051620616207162081620916210162111621216213162141621516216162171621816219162201622116222162231622416225162261622716228162291623016231162321623316234162351623616237162381623916240162411624216243162441624516246162471624816249162501625116252162531625416255162561625716258162591626016261162621626316264162651626616267162681626916270162711627216273162741627516276162771627816279162801628116282162831628416285162861628716288162891629016291162921629316294162951629616297162981629916300163011630216303163041630516306163071630816309163101631116312163131631416315163161631716318163191632016321163221632316324163251632616327163281632916330163311633216333163341633516336163371633816339163401634116342163431634416345163461634716348163491635016351163521635316354163551635616357163581635916360163611636216363163641636516366163671636816369163701637116372163731637416375163761637716378163791638016381163821638316384163851638616387163881638916390163911639216393163941639516396163971639816399164001640116402164031640416405164061640716408164091641016411164121641316414164151641616417164181641916420164211642216423164241642516426164271642816429164301643116432164331643416435164361643716438164391644016441164421644316444164451644616447164481644916450164511645216453164541645516456164571645816459164601646116462164631646416465164661646716468164691647016471164721647316474164751647616477164781647916480164811648216483164841648516486164871648816489164901649116492164931649416495164961649716498164991650016501165021650316504165051650616507165081650916510165111651216513165141651516516165171651816519165201652116522165231652416525165261652716528165291653016531165321653316534165351653616537165381653916540165411654216543165441654516546165471654816549165501655116552165531655416555165561655716558165591656016561165621656316564165651656616567165681656916570165711657216573165741657516576165771657816579165801658116582165831658416585165861658716588165891659016591165921659316594165951659616597165981659916600166011660216603166041660516606166071660816609166101661116612166131661416615166161661716618166191662016621166221662316624166251662616627166281662916630166311663216633166341663516636166371663816639166401664116642166431664416645166461664716648166491665016651166521665316654166551665616657166581665916660166611666216663166641666516666166671666816669166701667116672166731667416675166761667716678166791668016681166821668316684166851668616687166881668916690166911669216693166941669516696166971669816699167001670116702167031670416705167061670716708167091671016711167121671316714167151671616717167181671916720167211672216723167241672516726167271672816729167301673116732167331673416735167361673716738167391674016741167421674316744167451674616747167481674916750167511675216753167541675516756167571675816759167601676116762167631676416765167661676716768167691677016771167721677316774167751677616777167781677916780167811678216783167841678516786167871678816789167901679116792167931679416795167961679716798167991680016801168021680316804168051680616807168081680916810168111681216813168141681516816168171681816819168201682116822168231682416825168261682716828168291683016831168321683316834168351683616837168381683916840168411684216843168441684516846168471684816849168501685116852168531685416855168561685716858168591686016861168621686316864168651686616867168681686916870168711687216873168741687516876168771687816879168801688116882168831688416885168861688716888168891689016891168921689316894168951689616897168981689916900169011690216903169041690516906169071690816909169101691116912169131691416915169161691716918169191692016921169221692316924169251692616927169281692916930169311693216933169341693516936169371693816939169401694116942169431694416945169461694716948169491695016951169521695316954169551695616957169581695916960169611696216963169641696516966169671696816969169701697116972169731697416975169761697716978169791698016981169821698316984169851698616987169881698916990169911699216993169941699516996169971699816999170001700117002170031700417005170061700717008170091701017011170121701317014170151701617017170181701917020170211702217023170241702517026170271702817029170301703117032170331703417035170361703717038170391704017041170421704317044170451704617047170481704917050170511705217053170541705517056170571705817059170601706117062170631706417065170661706717068170691707017071170721707317074170751707617077170781707917080170811708217083170841708517086170871708817089170901709117092170931709417095170961709717098170991710017101171021710317104171051710617107171081710917110171111711217113171141711517116171171711817119171201712117122171231712417125171261712717128171291713017131171321713317134171351713617137171381713917140171411714217143171441714517146171471714817149171501715117152171531715417155171561715717158171591716017161171621716317164171651716617167171681716917170171711717217173171741717517176171771717817179171801718117182171831718417185171861718717188171891719017191171921719317194171951719617197171981719917200172011720217203172041720517206172071720817209172101721117212172131721417215172161721717218172191722017221172221722317224172251722617227172281722917230172311723217233172341723517236172371723817239172401724117242172431724417245172461724717248172491725017251172521725317254172551725617257172581725917260172611726217263172641726517266172671726817269172701727117272172731727417275172761727717278172791728017281172821728317284172851728617287172881728917290172911729217293172941729517296172971729817299173001730117302173031730417305173061730717308173091731017311173121731317314173151731617317173181731917320173211732217323173241732517326173271732817329173301733117332173331733417335173361733717338173391734017341173421734317344173451734617347173481734917350173511735217353173541735517356173571735817359173601736117362173631736417365173661736717368173691737017371173721737317374173751737617377173781737917380173811738217383173841738517386173871738817389173901739117392173931739417395173961739717398173991740017401174021740317404174051740617407174081740917410174111741217413174141741517416174171741817419174201742117422174231742417425174261742717428174291743017431174321743317434174351743617437174381743917440174411744217443174441744517446174471744817449174501745117452174531745417455174561745717458174591746017461174621746317464174651746617467174681746917470174711747217473174741747517476174771747817479174801748117482174831748417485174861748717488174891749017491174921749317494174951749617497174981749917500175011750217503175041750517506175071750817509175101751117512175131751417515175161751717518175191752017521175221752317524175251752617527175281752917530175311753217533175341753517536175371753817539175401754117542175431754417545175461754717548175491755017551175521755317554175551755617557175581755917560175611756217563175641756517566175671756817569175701757117572175731757417575175761757717578175791758017581175821758317584175851758617587175881758917590175911759217593175941759517596175971759817599176001760117602176031760417605176061760717608176091761017611176121761317614176151761617617176181761917620176211762217623176241762517626176271762817629176301763117632176331763417635176361763717638176391764017641176421764317644176451764617647176481764917650176511765217653176541765517656176571765817659176601766117662176631766417665176661766717668176691767017671176721767317674176751767617677176781767917680176811768217683176841768517686176871768817689176901769117692176931769417695176961769717698176991770017701177021770317704177051770617707177081770917710177111771217713177141771517716177171771817719177201772117722177231772417725177261772717728177291773017731177321773317734177351773617737177381773917740177411774217743177441774517746177471774817749177501775117752177531775417755177561775717758177591776017761177621776317764177651776617767177681776917770177711777217773177741777517776177771777817779177801778117782177831778417785177861778717788177891779017791177921779317794177951779617797177981779917800178011780217803178041780517806178071780817809178101781117812178131781417815178161781717818178191782017821178221782317824178251782617827178281782917830178311783217833178341783517836178371783817839178401784117842178431784417845178461784717848178491785017851178521785317854178551785617857178581785917860178611786217863178641786517866178671786817869178701787117872178731787417875178761787717878178791788017881178821788317884178851788617887178881788917890178911789217893178941789517896178971789817899179001790117902179031790417905179061790717908179091791017911179121791317914179151791617917179181791917920179211792217923179241792517926179271792817929179301793117932179331793417935179361793717938179391794017941179421794317944179451794617947179481794917950179511795217953179541795517956179571795817959179601796117962179631796417965179661796717968179691797017971179721797317974179751797617977179781797917980179811798217983179841798517986179871798817989179901799117992179931799417995179961799717998179991800018001180021800318004180051800618007180081800918010180111801218013180141801518016180171801818019180201802118022180231802418025180261802718028180291803018031180321803318034180351803618037180381803918040180411804218043180441804518046180471804818049180501805118052180531805418055180561805718058180591806018061180621806318064180651806618067180681806918070180711807218073180741807518076180771807818079180801808118082180831808418085180861808718088180891809018091180921809318094180951809618097180981809918100181011810218103181041810518106181071810818109181101811118112181131811418115181161811718118181191812018121181221812318124181251812618127181281812918130181311813218133181341813518136181371813818139181401814118142181431814418145181461814718148181491815018151181521815318154181551815618157181581815918160181611816218163181641816518166181671816818169181701817118172181731817418175181761817718178181791818018181181821818318184181851818618187181881818918190181911819218193
  1. /*
  2. * Copyright (c) Contributors, http://opensimulator.org/
  3. * See CONTRIBUTORS.TXT for a full list of copyright holders.
  4. *
  5. * Redistribution and use in source and binary forms, with or without
  6. * modification, are permitted provided that the following conditions are met:
  7. * * Redistributions of source code must retain the above copyright
  8. * notice, this list of conditions and the following disclaimer.
  9. * * Redistributions in binary form must reproduce the above copyright
  10. * notice, this list of conditions and the following disclaimer in the
  11. * documentation and/or other materials provided with the distribution.
  12. * * Neither the name of the OpenSimulator Project nor the
  13. * names of its contributors may be used to endorse or promote products
  14. * derived from this software without specific prior written permission.
  15. *
  16. * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
  17. * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  18. * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  19. * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
  20. * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  21. * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  22. * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  23. * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  24. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  25. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  26. */
  27. using System;
  28. using System.Collections;
  29. using System.Collections.Generic;
  30. using System.Collections.Specialized;
  31. using System.Diagnostics;
  32. using System.Drawing;
  33. using System.Drawing.Imaging;
  34. using System.Runtime.Remoting.Lifetime;
  35. using System.Text;
  36. using System.Threading;
  37. using System.Text.RegularExpressions;
  38. using System.Timers;
  39. using Nini.Config;
  40. using log4net;
  41. using OpenMetaverse;
  42. using OpenMetaverse.Assets;
  43. using OpenMetaverse.StructuredData; // LitJson is hidden on this
  44. using OpenMetaverse.Packets;
  45. using OpenMetaverse.Rendering;
  46. using OpenSim;
  47. using OpenSim.Framework;
  48. using OpenSim.Region.CoreModules;
  49. using OpenSim.Region.CoreModules.World.Land;
  50. using OpenSim.Region.CoreModules.World.Terrain;
  51. using OpenSim.Region.Framework.Interfaces;
  52. using OpenSim.Region.Framework.Scenes;
  53. using OpenSim.Region.Framework.Scenes.Serialization;
  54. using OpenSim.Region.Framework.Scenes.Animation;
  55. using OpenSim.Region.Framework.Scenes.Scripting;
  56. using OpenSim.Region.PhysicsModules.SharedBase;
  57. using OpenSim.Region.ScriptEngine.Shared;
  58. using OpenSim.Region.ScriptEngine.Shared.Api.Plugins;
  59. using OpenSim.Region.ScriptEngine.Shared.ScriptBase;
  60. using OpenSim.Region.ScriptEngine.Interfaces;
  61. using OpenSim.Region.ScriptEngine.Shared.Api.Interfaces;
  62. using OpenSim.Services.Interfaces;
  63. using GridRegion = OpenSim.Services.Interfaces.GridRegion;
  64. using PresenceInfo = OpenSim.Services.Interfaces.PresenceInfo;
  65. using PrimType = OpenSim.Region.Framework.Scenes.PrimType;
  66. using AssetLandmark = OpenSim.Framework.AssetLandmark;
  67. using RegionFlags = OpenSim.Framework.RegionFlags;
  68. using LSL_Float = OpenSim.Region.ScriptEngine.Shared.LSL_Types.LSLFloat;
  69. using LSL_Integer = OpenSim.Region.ScriptEngine.Shared.LSL_Types.LSLInteger;
  70. using LSL_Key = OpenSim.Region.ScriptEngine.Shared.LSL_Types.LSLString;
  71. using LSL_List = OpenSim.Region.ScriptEngine.Shared.LSL_Types.list;
  72. using LSL_Rotation = OpenSim.Region.ScriptEngine.Shared.LSL_Types.Quaternion;
  73. using LSL_String = OpenSim.Region.ScriptEngine.Shared.LSL_Types.LSLString;
  74. using LSL_Vector = OpenSim.Region.ScriptEngine.Shared.LSL_Types.Vector3;
  75. using System.Reflection;
  76. using Timer = System.Timers.Timer;
  77. using System.Linq;
  78. using PermissionMask = OpenSim.Framework.PermissionMask;
  79. namespace OpenSim.Region.ScriptEngine.Shared.Api
  80. {
  81. // MUST be a ref type
  82. public class UserInfoCacheEntry
  83. {
  84. public int time;
  85. public UserAccount account;
  86. public PresenceInfo pinfo;
  87. }
  88. /// <summary>
  89. /// Contains all LSL ll-functions. This class will be in Default AppDomain.
  90. /// </summary>
  91. public class LSL_Api : MarshalByRefObject, ILSL_Api, IScriptApi
  92. {
  93. private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
  94. public int LlRequestAgentDataCacheTimeoutMs { get; set; }
  95. protected IScriptEngine m_ScriptEngine;
  96. protected SceneObjectPart m_host;
  97. /// <summary>
  98. /// The item that hosts this script
  99. /// </summary>
  100. protected TaskInventoryItem m_item;
  101. protected bool throwErrorOnNotImplemented = false;
  102. protected AsyncCommandManager AsyncCommands = null;
  103. protected float m_ScriptDelayFactor = 1.0f;
  104. protected float m_ScriptDistanceFactor = 1.0f;
  105. protected float m_MinTimerInterval = 0.5f;
  106. protected float m_recoilScaleFactor = 0.0f;
  107. protected double m_timer = Util.GetTimeStampMS();
  108. protected bool m_waitingForScriptAnswer = false;
  109. protected bool m_automaticLinkPermission = false;
  110. protected IMessageTransferModule m_TransferModule = null;
  111. protected int m_notecardLineReadCharsMax = 255;
  112. protected int m_scriptConsoleChannel = 0;
  113. protected bool m_scriptConsoleChannelEnabled = false;
  114. protected bool m_debuggerSafe = false;
  115. protected IUrlModule m_UrlModule = null;
  116. protected IMaterialsModule m_materialsModule = null;
  117. protected Dictionary<UUID, UserInfoCacheEntry> m_userInfoCache = new Dictionary<UUID, UserInfoCacheEntry>();
  118. protected int EMAIL_PAUSE_TIME = 20; // documented delay value for smtp.
  119. protected int m_sleepMsOnSetTexture = 200;
  120. protected int m_sleepMsOnSetLinkTexture = 200;
  121. protected int m_sleepMsOnScaleTexture = 200;
  122. protected int m_sleepMsOnOffsetTexture = 200;
  123. protected int m_sleepMsOnRotateTexture = 200;
  124. protected int m_sleepMsOnSetPos = 200;
  125. protected int m_sleepMsOnSetRot = 200;
  126. protected int m_sleepMsOnSetLocalRot = 200;
  127. protected int m_sleepMsOnPreloadSound = 1000;
  128. protected int m_sleepMsOnMakeExplosion = 100;
  129. protected int m_sleepMsOnMakeFountain = 100;
  130. protected int m_sleepMsOnMakeSmoke = 100;
  131. protected int m_sleepMsOnMakeFire = 100;
  132. protected int m_sleepMsOnRezAtRoot = 100;
  133. protected int m_sleepMsOnInstantMessage = 2000;
  134. protected int m_sleepMsOnEmail = 20000;
  135. protected int m_sleepMsOnCreateLink = 1000;
  136. protected int m_sleepMsOnGiveInventory = 3000;
  137. protected int m_sleepMsOnRequestAgentData = 100;
  138. protected int m_sleepMsOnRequestInventoryData = 1000;
  139. protected int m_sleepMsOnSetDamage = 5000;
  140. protected int m_sleepMsOnTextBox = 1000;
  141. protected int m_sleepMsOnAdjustSoundVolume = 100;
  142. protected int m_sleepMsOnEjectFromLand = 1000;
  143. protected int m_sleepMsOnAddToLandPassList = 100;
  144. protected int m_sleepMsOnDialog = 1000;
  145. protected int m_sleepMsOnRemoteLoadScript = 3000;
  146. protected int m_sleepMsOnRemoteLoadScriptPin = 3000;
  147. protected int m_sleepMsOnOpenRemoteDataChannel = 1000;
  148. protected int m_sleepMsOnSendRemoteData = 3000;
  149. protected int m_sleepMsOnRemoteDataReply = 3000;
  150. protected int m_sleepMsOnCloseRemoteDataChannel = 1000;
  151. protected int m_sleepMsOnSetPrimitiveParams = 200;
  152. protected int m_sleepMsOnSetLinkPrimitiveParams = 200;
  153. protected int m_sleepMsOnXorBase64Strings = 300;
  154. protected int m_sleepMsOnSetParcelMusicURL = 2000;
  155. protected int m_sleepMsOnGetPrimMediaParams = 1000;
  156. protected int m_sleepMsOnGetLinkMedia = 1000;
  157. protected int m_sleepMsOnSetPrimMediaParams = 1000;
  158. protected int m_sleepMsOnSetLinkMedia = 1000;
  159. protected int m_sleepMsOnClearPrimMedia = 1000;
  160. protected int m_sleepMsOnClearLinkMedia = 1000;
  161. protected int m_sleepMsOnRequestSimulatorData = 1000;
  162. protected int m_sleepMsOnLoadURL = 10000;
  163. protected int m_sleepMsOnParcelMediaCommandList = 2000;
  164. protected int m_sleepMsOnParcelMediaQuery = 2000;
  165. protected int m_sleepMsOnModPow = 1000;
  166. protected int m_sleepMsOnSetPrimURL = 2000;
  167. protected int m_sleepMsOnRefreshPrimURL = 20000;
  168. protected int m_sleepMsOnMapDestination = 1000;
  169. protected int m_sleepMsOnAddToLandBanList = 100;
  170. protected int m_sleepMsOnRemoveFromLandPassList = 100;
  171. protected int m_sleepMsOnRemoveFromLandBanList = 100;
  172. protected int m_sleepMsOnResetLandBanList = 100;
  173. protected int m_sleepMsOnResetLandPassList = 100;
  174. protected int m_sleepMsOnGetParcelPrimOwners = 2000;
  175. protected int m_sleepMsOnGetNumberOfNotecardLines = 100;
  176. protected int m_sleepMsOnGetNotecardLine = 100;
  177. protected string m_internalObjectHost = "lsl.opensim.local";
  178. protected bool m_restrictEmail = false;
  179. protected ISoundModule m_SoundModule = null;
  180. protected float m_avatarHeightCorrection = 0.2f;
  181. protected bool m_useSimpleBoxesInGetBoundingBox = false;
  182. protected bool m_addStatsInGetBoundingBox = false;
  183. //LSL Avatar Bounding Box (lABB), lower (1) and upper (2),
  184. //standing (Std), Groundsitting (Grs), Sitting (Sit),
  185. //along X, Y and Z axes, constants (0) and coefficients (1)
  186. protected float m_lABB1StdX0 = -0.275f;
  187. protected float m_lABB2StdX0 = 0.275f;
  188. protected float m_lABB1StdY0 = -0.35f;
  189. protected float m_lABB2StdY0 = 0.35f;
  190. protected float m_lABB1StdZ0 = -0.1f;
  191. protected float m_lABB1StdZ1 = -0.5f;
  192. protected float m_lABB2StdZ0 = 0.1f;
  193. protected float m_lABB2StdZ1 = 0.5f;
  194. protected float m_lABB1GrsX0 = -0.3875f;
  195. protected float m_lABB2GrsX0 = 0.3875f;
  196. protected float m_lABB1GrsY0 = -0.5f;
  197. protected float m_lABB2GrsY0 = 0.5f;
  198. protected float m_lABB1GrsZ0 = -0.05f;
  199. protected float m_lABB1GrsZ1 = -0.375f;
  200. protected float m_lABB2GrsZ0 = 0.5f;
  201. protected float m_lABB2GrsZ1 = 0.0f;
  202. protected float m_lABB1SitX0 = -0.5875f;
  203. protected float m_lABB2SitX0 = 0.1875f;
  204. protected float m_lABB1SitY0 = -0.35f;
  205. protected float m_lABB2SitY0 = 0.35f;
  206. protected float m_lABB1SitZ0 = -0.35f;
  207. protected float m_lABB1SitZ1 = -0.375f;
  208. protected float m_lABB2SitZ0 = -0.25f;
  209. protected float m_lABB2SitZ1 = 0.25f;
  210. protected float m_primSafetyCoeffX = 2.414214f;
  211. protected float m_primSafetyCoeffY = 2.414214f;
  212. protected float m_primSafetyCoeffZ = 1.618034f;
  213. protected bool m_useCastRayV3 = false;
  214. protected float m_floatToleranceInCastRay = 0.00001f;
  215. protected float m_floatTolerance2InCastRay = 0.001f;
  216. protected DetailLevel m_primLodInCastRay = DetailLevel.Medium;
  217. protected DetailLevel m_sculptLodInCastRay = DetailLevel.Medium;
  218. protected DetailLevel m_meshLodInCastRay = DetailLevel.Highest;
  219. protected DetailLevel m_avatarLodInCastRay = DetailLevel.Medium;
  220. protected int m_maxHitsInCastRay = 16;
  221. protected int m_maxHitsPerPrimInCastRay = 16;
  222. protected int m_maxHitsPerObjectInCastRay = 16;
  223. protected bool m_detectExitsInCastRay = false;
  224. protected bool m_doAttachmentsInCastRay = false;
  225. protected int m_msThrottleInCastRay = 200;
  226. protected int m_msPerRegionInCastRay = 40;
  227. protected int m_msPerAvatarInCastRay = 10;
  228. protected int m_msMinInCastRay = 2;
  229. protected int m_msMaxInCastRay = 40;
  230. protected static List<CastRayCall> m_castRayCalls = new List<CastRayCall>();
  231. protected bool m_useMeshCacheInCastRay = true;
  232. protected static Dictionary<ulong, FacetedMesh> m_cachedMeshes = new Dictionary<ulong, FacetedMesh>();
  233. // protected Timer m_ShoutSayTimer;
  234. protected int m_SayShoutCount = 0;
  235. DateTime m_lastSayShoutCheck;
  236. private Dictionary<string, string> MovementAnimationsForLSL =
  237. new Dictionary<string, string> {
  238. {"CROUCH", "Crouching"},
  239. {"CROUCHWALK", "CrouchWalking"},
  240. {"FALLDOWN", "Falling Down"},
  241. {"FLY", "Flying"},
  242. {"FLYSLOW", "FlyingSlow"},
  243. {"HOVER", "Hovering"},
  244. {"HOVER_UP", "Hovering Up"},
  245. {"HOVER_DOWN", "Hovering Down"},
  246. {"JUMP", "Jumping"},
  247. {"LAND", "Landing"},
  248. {"PREJUMP", "PreJumping"},
  249. {"RUN", "Running"},
  250. {"SIT","Sitting"},
  251. {"SITGROUND","Sitting on Ground"},
  252. {"STAND", "Standing"},
  253. {"STANDUP", "Standing Up"},
  254. {"STRIDE","Striding"},
  255. {"SOFT_LAND", "Soft Landing"},
  256. {"TURNLEFT", "Turning Left"},
  257. {"TURNRIGHT", "Turning Right"},
  258. {"WALK", "Walking"}
  259. };
  260. //An array of HTTP/1.1 headers that are not allowed to be used
  261. //as custom headers by llHTTPRequest.
  262. private string[] HttpStandardHeaders =
  263. {
  264. "Accept", "Accept-Charset", "Accept-Encoding", "Accept-Language",
  265. "Accept-Ranges", "Age", "Allow", "Authorization", "Cache-Control",
  266. "Connection", "Content-Encoding", "Content-Language",
  267. "Content-Length", "Content-Location", "Content-MD5",
  268. "Content-Range", "Content-Type", "Date", "ETag", "Expect",
  269. "Expires", "From", "Host", "If-Match", "If-Modified-Since",
  270. "If-None-Match", "If-Range", "If-Unmodified-Since", "Last-Modified",
  271. "Location", "Max-Forwards", "Pragma", "Proxy-Authenticate",
  272. "Proxy-Authorization", "Range", "Referer", "Retry-After", "Server",
  273. "TE", "Trailer", "Transfer-Encoding", "Upgrade", "User-Agent",
  274. "Vary", "Via", "Warning", "WWW-Authenticate"
  275. };
  276. public void Initialize(
  277. IScriptEngine scriptEngine, SceneObjectPart host, TaskInventoryItem item)
  278. {
  279. m_lastSayShoutCheck = DateTime.UtcNow;
  280. m_ScriptEngine = scriptEngine;
  281. m_host = host;
  282. m_item = item;
  283. m_debuggerSafe = m_ScriptEngine.Config.GetBoolean("DebuggerSafe", false);
  284. LoadConfig();
  285. m_TransferModule =
  286. m_ScriptEngine.World.RequestModuleInterface<IMessageTransferModule>();
  287. m_UrlModule = m_ScriptEngine.World.RequestModuleInterface<IUrlModule>();
  288. m_SoundModule = m_ScriptEngine.World.RequestModuleInterface<ISoundModule>();
  289. m_materialsModule = m_ScriptEngine.World.RequestModuleInterface<IMaterialsModule>();
  290. AsyncCommands = new AsyncCommandManager(m_ScriptEngine);
  291. }
  292. /// <summary>
  293. /// Load configuration items that affect script, object and run-time behavior. */
  294. /// </summary>
  295. private void LoadConfig()
  296. {
  297. LlRequestAgentDataCacheTimeoutMs = 20000;
  298. IConfig seConfig = m_ScriptEngine.Config;
  299. if (seConfig != null)
  300. {
  301. m_ScriptDelayFactor =
  302. seConfig.GetFloat("ScriptDelayFactor", m_ScriptDelayFactor);
  303. m_ScriptDistanceFactor =
  304. seConfig.GetFloat("ScriptDistanceLimitFactor", m_ScriptDistanceFactor);
  305. m_MinTimerInterval =
  306. seConfig.GetFloat("MinTimerInterval", m_MinTimerInterval);
  307. m_automaticLinkPermission =
  308. seConfig.GetBoolean("AutomaticLinkPermission", m_automaticLinkPermission);
  309. m_notecardLineReadCharsMax =
  310. seConfig.GetInt("NotecardLineReadCharsMax", m_notecardLineReadCharsMax);
  311. // Rezzing an object with a velocity can create recoil. This feature seems to have been
  312. // removed from recent versions of SL. The code computes recoil (vel*mass) and scales
  313. // it by this factor. May be zero to turn off recoil all together.
  314. m_recoilScaleFactor = m_ScriptEngine.Config.GetFloat("RecoilScaleFactor", m_recoilScaleFactor);
  315. }
  316. if (m_notecardLineReadCharsMax > 65535)
  317. m_notecardLineReadCharsMax = 65535;
  318. // load limits for particular subsystems.
  319. IConfigSource seConfigSource = m_ScriptEngine.ConfigSource;
  320. if (seConfigSource != null)
  321. {
  322. IConfig lslConfig = seConfigSource.Configs["LL-Functions"];
  323. if (lslConfig != null)
  324. {
  325. m_restrictEmail = lslConfig.GetBoolean("RestrictEmail", m_restrictEmail);
  326. m_avatarHeightCorrection = lslConfig.GetFloat("AvatarHeightCorrection", m_avatarHeightCorrection);
  327. m_useSimpleBoxesInGetBoundingBox = lslConfig.GetBoolean("UseSimpleBoxesInGetBoundingBox", m_useSimpleBoxesInGetBoundingBox);
  328. m_addStatsInGetBoundingBox = lslConfig.GetBoolean("AddStatsInGetBoundingBox", m_addStatsInGetBoundingBox);
  329. m_lABB1StdX0 = lslConfig.GetFloat("LowerAvatarBoundingBoxStandingXconst", m_lABB1StdX0);
  330. m_lABB2StdX0 = lslConfig.GetFloat("UpperAvatarBoundingBoxStandingXconst", m_lABB2StdX0);
  331. m_lABB1StdY0 = lslConfig.GetFloat("LowerAvatarBoundingBoxStandingYconst", m_lABB1StdY0);
  332. m_lABB2StdY0 = lslConfig.GetFloat("UpperAvatarBoundingBoxStandingYconst", m_lABB2StdY0);
  333. m_lABB1StdZ0 = lslConfig.GetFloat("LowerAvatarBoundingBoxStandingZconst", m_lABB1StdZ0);
  334. m_lABB1StdZ1 = lslConfig.GetFloat("LowerAvatarBoundingBoxStandingZcoeff", m_lABB1StdZ1);
  335. m_lABB2StdZ0 = lslConfig.GetFloat("UpperAvatarBoundingBoxStandingZconst", m_lABB2StdZ0);
  336. m_lABB2StdZ1 = lslConfig.GetFloat("UpperAvatarBoundingBoxStandingZcoeff", m_lABB2StdZ1);
  337. m_lABB1GrsX0 = lslConfig.GetFloat("LowerAvatarBoundingBoxGroundsittingXconst", m_lABB1GrsX0);
  338. m_lABB2GrsX0 = lslConfig.GetFloat("UpperAvatarBoundingBoxGroundsittingXconst", m_lABB2GrsX0);
  339. m_lABB1GrsY0 = lslConfig.GetFloat("LowerAvatarBoundingBoxGroundsittingYconst", m_lABB1GrsY0);
  340. m_lABB2GrsY0 = lslConfig.GetFloat("UpperAvatarBoundingBoxGroundsittingYconst", m_lABB2GrsY0);
  341. m_lABB1GrsZ0 = lslConfig.GetFloat("LowerAvatarBoundingBoxGroundsittingZconst", m_lABB1GrsZ0);
  342. m_lABB1GrsZ1 = lslConfig.GetFloat("LowerAvatarBoundingBoxGroundsittingZcoeff", m_lABB1GrsZ1);
  343. m_lABB2GrsZ0 = lslConfig.GetFloat("UpperAvatarBoundingBoxGroundsittingZconst", m_lABB2GrsZ0);
  344. m_lABB2GrsZ1 = lslConfig.GetFloat("UpperAvatarBoundingBoxGroundsittingZcoeff", m_lABB2GrsZ1);
  345. m_lABB1SitX0 = lslConfig.GetFloat("LowerAvatarBoundingBoxSittingXconst", m_lABB1SitX0);
  346. m_lABB2SitX0 = lslConfig.GetFloat("UpperAvatarBoundingBoxSittingXconst", m_lABB2SitX0);
  347. m_lABB1SitY0 = lslConfig.GetFloat("LowerAvatarBoundingBoxSittingYconst", m_lABB1SitY0);
  348. m_lABB2SitY0 = lslConfig.GetFloat("UpperAvatarBoundingBoxSittingYconst", m_lABB2SitY0);
  349. m_lABB1SitZ0 = lslConfig.GetFloat("LowerAvatarBoundingBoxSittingZconst", m_lABB1SitZ0);
  350. m_lABB1SitZ1 = lslConfig.GetFloat("LowerAvatarBoundingBoxSittingZcoeff", m_lABB1SitZ1);
  351. m_lABB2SitZ0 = lslConfig.GetFloat("UpperAvatarBoundingBoxSittingZconst", m_lABB2SitZ0);
  352. m_lABB2SitZ1 = lslConfig.GetFloat("UpperAvatarBoundingBoxSittingZcoeff", m_lABB2SitZ1);
  353. m_primSafetyCoeffX = lslConfig.GetFloat("PrimBoundingBoxSafetyCoefficientX", m_primSafetyCoeffX);
  354. m_primSafetyCoeffY = lslConfig.GetFloat("PrimBoundingBoxSafetyCoefficientY", m_primSafetyCoeffY);
  355. m_primSafetyCoeffZ = lslConfig.GetFloat("PrimBoundingBoxSafetyCoefficientZ", m_primSafetyCoeffZ);
  356. m_useCastRayV3 = lslConfig.GetBoolean("UseLlCastRayV3", m_useCastRayV3);
  357. m_floatToleranceInCastRay = lslConfig.GetFloat("FloatToleranceInLlCastRay", m_floatToleranceInCastRay);
  358. m_floatTolerance2InCastRay = lslConfig.GetFloat("FloatTolerance2InLlCastRay", m_floatTolerance2InCastRay);
  359. m_primLodInCastRay = (DetailLevel)lslConfig.GetInt("PrimDetailLevelInLlCastRay", (int)m_primLodInCastRay);
  360. m_sculptLodInCastRay = (DetailLevel)lslConfig.GetInt("SculptDetailLevelInLlCastRay", (int)m_sculptLodInCastRay);
  361. m_meshLodInCastRay = (DetailLevel)lslConfig.GetInt("MeshDetailLevelInLlCastRay", (int)m_meshLodInCastRay);
  362. m_avatarLodInCastRay = (DetailLevel)lslConfig.GetInt("AvatarDetailLevelInLlCastRay", (int)m_avatarLodInCastRay);
  363. m_maxHitsInCastRay = lslConfig.GetInt("MaxHitsInLlCastRay", m_maxHitsInCastRay);
  364. m_maxHitsPerPrimInCastRay = lslConfig.GetInt("MaxHitsPerPrimInLlCastRay", m_maxHitsPerPrimInCastRay);
  365. m_maxHitsPerObjectInCastRay = lslConfig.GetInt("MaxHitsPerObjectInLlCastRay", m_maxHitsPerObjectInCastRay);
  366. m_detectExitsInCastRay = lslConfig.GetBoolean("DetectExitHitsInLlCastRay", m_detectExitsInCastRay);
  367. m_doAttachmentsInCastRay = lslConfig.GetBoolean("DoAttachmentsInLlCastRay", m_doAttachmentsInCastRay);
  368. m_msThrottleInCastRay = lslConfig.GetInt("ThrottleTimeInMsInLlCastRay", m_msThrottleInCastRay);
  369. m_msPerRegionInCastRay = lslConfig.GetInt("AvailableTimeInMsPerRegionInLlCastRay", m_msPerRegionInCastRay);
  370. m_msPerAvatarInCastRay = lslConfig.GetInt("AvailableTimeInMsPerAvatarInLlCastRay", m_msPerAvatarInCastRay);
  371. m_msMinInCastRay = lslConfig.GetInt("RequiredAvailableTimeInMsInLlCastRay", m_msMinInCastRay);
  372. m_msMaxInCastRay = lslConfig.GetInt("MaximumAvailableTimeInMsInLlCastRay", m_msMaxInCastRay);
  373. m_useMeshCacheInCastRay = lslConfig.GetBoolean("UseMeshCacheInLlCastRay", m_useMeshCacheInCastRay);
  374. }
  375. IConfig smtpConfig = seConfigSource.Configs["SMTP"];
  376. if (smtpConfig != null)
  377. {
  378. // there's an smtp config, so load in the snooze time.
  379. EMAIL_PAUSE_TIME = smtpConfig.GetInt("email_pause_time", EMAIL_PAUSE_TIME);
  380. m_internalObjectHost = smtpConfig.GetString("internal_object_host", m_internalObjectHost);
  381. }
  382. }
  383. m_sleepMsOnEmail = EMAIL_PAUSE_TIME * 1000;
  384. }
  385. public override Object InitializeLifetimeService()
  386. {
  387. ILease lease = (ILease)base.InitializeLifetimeService();
  388. if (lease.CurrentState == LeaseState.Initial)
  389. {
  390. lease.InitialLeaseTime = TimeSpan.FromMinutes(0);
  391. // lease.RenewOnCallTime = TimeSpan.FromSeconds(10.0);
  392. // lease.SponsorshipTimeout = TimeSpan.FromMinutes(1.0);
  393. }
  394. return lease;
  395. }
  396. protected SceneObjectPart MonitoringObject()
  397. {
  398. UUID m = m_host.ParentGroup.MonitoringObject;
  399. if (m == UUID.Zero)
  400. return null;
  401. SceneObjectPart p = m_ScriptEngine.World.GetSceneObjectPart(m);
  402. if (p == null)
  403. m_host.ParentGroup.MonitoringObject = UUID.Zero;
  404. return p;
  405. }
  406. protected virtual void ScriptSleep(int delay)
  407. {
  408. delay = (int)(delay * m_ScriptDelayFactor);
  409. if (delay < 10)
  410. return;
  411. Sleep(delay);
  412. }
  413. protected virtual void Sleep(int delay)
  414. {
  415. if (m_item == null) // Some unit tests don't set this
  416. Thread.Sleep(delay);
  417. else
  418. m_ScriptEngine.SleepScript(m_item.ItemID, delay);
  419. }
  420. /// <summary>
  421. /// Check for co-operative termination.
  422. /// </summary>
  423. /// <param name='delay'>If called with 0, then just the check is performed with no wait.</param>
  424. public Scene World
  425. {
  426. get { return m_ScriptEngine.World; }
  427. }
  428. [DebuggerNonUserCode]
  429. public void state(string newState)
  430. {
  431. m_ScriptEngine.SetState(m_item.ItemID, newState);
  432. }
  433. /// <summary>
  434. /// Reset the named script. The script must be present
  435. /// in the same prim.
  436. /// </summary>
  437. [DebuggerNonUserCode]
  438. public void llResetScript()
  439. {
  440. m_host.AddScriptLPS(1);
  441. // We need to tell the URL module, if we hav one, to release
  442. // the allocated URLs
  443. if (m_UrlModule != null)
  444. m_UrlModule.ScriptRemoved(m_item.ItemID);
  445. m_ScriptEngine.ApiResetScript(m_item.ItemID);
  446. }
  447. public void llResetOtherScript(string name)
  448. {
  449. UUID item;
  450. if ((item = GetScriptByName(name)) == UUID.Zero)
  451. {
  452. m_host.AddScriptLPS(1);
  453. Error("llResetOtherScript", "Can't find script '" + name + "'");
  454. return;
  455. }
  456. if(item == m_item.ItemID)
  457. llResetScript();
  458. else
  459. {
  460. m_host.AddScriptLPS(1);
  461. m_ScriptEngine.ResetScript(item);
  462. }
  463. }
  464. public LSL_Integer llGetScriptState(string name)
  465. {
  466. UUID item;
  467. m_host.AddScriptLPS(1);
  468. if ((item = GetScriptByName(name)) != UUID.Zero)
  469. {
  470. return m_ScriptEngine.GetScriptState(item) ?1:0;
  471. }
  472. Error("llGetScriptState", "Can't find script '" + name + "'");
  473. // If we didn't find it, then it's safe to
  474. // assume it is not running.
  475. return 0;
  476. }
  477. public void llSetScriptState(string name, int run)
  478. {
  479. UUID item;
  480. m_host.AddScriptLPS(1);
  481. // These functions are supposed to be robust,
  482. // so get the state one step at a time.
  483. if ((item = GetScriptByName(name)) != UUID.Zero)
  484. {
  485. m_ScriptEngine.SetScriptState(item, run == 0 ? false : true, item == m_item.ItemID);
  486. }
  487. else
  488. {
  489. Error("llSetScriptState", "Can't find script '" + name + "'");
  490. }
  491. }
  492. public List<ScenePresence> GetLinkAvatars(int linkType)
  493. {
  494. List<ScenePresence> ret = new List<ScenePresence>();
  495. if (m_host == null || m_host.ParentGroup == null || m_host.ParentGroup.IsDeleted)
  496. return ret;
  497. // List<ScenePresence> avs = m_host.ParentGroup.GetLinkedAvatars();
  498. // this needs check
  499. List<ScenePresence> avs = m_host.ParentGroup.GetSittingAvatars();
  500. switch (linkType)
  501. {
  502. case ScriptBaseClass.LINK_SET:
  503. return avs;
  504. case ScriptBaseClass.LINK_ROOT:
  505. return ret;
  506. case ScriptBaseClass.LINK_ALL_OTHERS:
  507. return avs;
  508. case ScriptBaseClass.LINK_ALL_CHILDREN:
  509. return avs;
  510. case ScriptBaseClass.LINK_THIS:
  511. return ret;
  512. default:
  513. if (linkType < 0)
  514. return ret;
  515. int partCount = m_host.ParentGroup.GetPartCount();
  516. if (linkType <= partCount)
  517. {
  518. return ret;
  519. }
  520. else
  521. {
  522. linkType = linkType - partCount;
  523. if (linkType > avs.Count)
  524. {
  525. return ret;
  526. }
  527. else
  528. {
  529. ret.Add(avs[linkType-1]);
  530. return ret;
  531. }
  532. }
  533. }
  534. }
  535. /// <summary>
  536. /// Get a given link entity from a linkset (linked objects and any sitting avatars).
  537. /// </summary>
  538. /// <remarks>
  539. /// If there are any ScenePresence's in the linkset (i.e. because they are sat upon one of the prims), then
  540. /// these are counted as extra entities that correspond to linknums beyond the number of prims in the linkset.
  541. /// The ScenePresences receive linknums in the order in which they sat.
  542. /// </remarks>
  543. /// <returns>
  544. /// The link entity. null if not found.
  545. /// </returns>
  546. /// <param name='part'></param>
  547. /// <param name='linknum'>
  548. /// Can be either a non-negative integer or ScriptBaseClass.LINK_THIS (-4).
  549. /// If ScriptBaseClass.LINK_THIS then the entity containing the script is returned.
  550. /// If the linkset has one entity and a linknum of zero is given, then the single entity is returned. If any
  551. /// positive integer is given in this case then null is returned.
  552. /// If the linkset has more than one entity and a linknum greater than zero but equal to or less than the number
  553. /// of entities, then the entity which corresponds to that linknum is returned.
  554. /// Otherwise, if a positive linknum is given which is greater than the number of entities in the linkset, then
  555. /// null is returned.
  556. /// </param>
  557. public ISceneEntity GetLinkEntity(SceneObjectPart part, int linknum)
  558. {
  559. if (linknum < 0)
  560. {
  561. if (linknum == ScriptBaseClass.LINK_THIS)
  562. return part;
  563. else
  564. return null;
  565. }
  566. int actualPrimCount = part.ParentGroup.PrimCount;
  567. List<ScenePresence> sittingAvatars = part.ParentGroup.GetSittingAvatars();
  568. int adjustedPrimCount = actualPrimCount + sittingAvatars.Count;
  569. // Special case for a single prim. In this case the linknum is zero. However, this will not match a single
  570. // prim that has any avatars sat upon it (in which case the root prim is link 1).
  571. if (linknum == 0)
  572. {
  573. if (actualPrimCount == 1 && sittingAvatars.Count == 0)
  574. return part;
  575. return null;
  576. }
  577. // Special case to handle a single prim with sitting avatars. GetLinkPart() would only match zero but
  578. // here we must match 1 (ScriptBaseClass.LINK_ROOT).
  579. else if (linknum == ScriptBaseClass.LINK_ROOT && actualPrimCount == 1)
  580. {
  581. if (sittingAvatars.Count > 0)
  582. return part.ParentGroup.RootPart;
  583. else
  584. return null;
  585. }
  586. else if (linknum <= adjustedPrimCount)
  587. {
  588. if (linknum <= actualPrimCount)
  589. {
  590. return part.ParentGroup.GetLinkNumPart(linknum);
  591. }
  592. else
  593. {
  594. return sittingAvatars[linknum - actualPrimCount - 1];
  595. }
  596. }
  597. else
  598. {
  599. return null;
  600. }
  601. }
  602. public List<SceneObjectPart> GetLinkParts(int linkType)
  603. {
  604. return GetLinkParts(m_host, linkType);
  605. }
  606. public static List<SceneObjectPart> GetLinkParts(SceneObjectPart part, int linkType)
  607. {
  608. List<SceneObjectPart> ret = new List<SceneObjectPart>();
  609. if (part == null || part.ParentGroup == null || part.ParentGroup.IsDeleted)
  610. return ret;
  611. switch (linkType)
  612. {
  613. case ScriptBaseClass.LINK_SET:
  614. return new List<SceneObjectPart>(part.ParentGroup.Parts);
  615. case ScriptBaseClass.LINK_ROOT:
  616. ret.Add(part.ParentGroup.RootPart);
  617. return ret;
  618. case ScriptBaseClass.LINK_ALL_OTHERS:
  619. ret = new List<SceneObjectPart>(part.ParentGroup.Parts);
  620. if (ret.Contains(part))
  621. ret.Remove(part);
  622. return ret;
  623. case ScriptBaseClass.LINK_ALL_CHILDREN:
  624. ret = new List<SceneObjectPart>(part.ParentGroup.Parts);
  625. if (ret.Contains(part.ParentGroup.RootPart))
  626. ret.Remove(part.ParentGroup.RootPart);
  627. return ret;
  628. case ScriptBaseClass.LINK_THIS:
  629. ret.Add(part);
  630. return ret;
  631. default:
  632. if (linkType < 0)
  633. return ret;
  634. SceneObjectPart target = part.ParentGroup.GetLinkNumPart(linkType);
  635. if (target == null)
  636. return ret;
  637. ret.Add(target);
  638. return ret;
  639. }
  640. }
  641. public List<ISceneEntity> GetLinkEntities(int linkType)
  642. {
  643. return GetLinkEntities(m_host, linkType);
  644. }
  645. public List<ISceneEntity> GetLinkEntities(SceneObjectPart part, int linkType)
  646. {
  647. List<ISceneEntity> ret;
  648. switch (linkType)
  649. {
  650. case ScriptBaseClass.LINK_SET:
  651. return new List<ISceneEntity>(part.ParentGroup.Parts);
  652. case ScriptBaseClass.LINK_ROOT:
  653. return new List<ISceneEntity>() { part.ParentGroup.RootPart };
  654. case ScriptBaseClass.LINK_ALL_OTHERS:
  655. ret = new List<ISceneEntity>(part.ParentGroup.Parts);
  656. if (ret.Contains(part))
  657. ret.Remove(part);
  658. return ret;
  659. case ScriptBaseClass.LINK_ALL_CHILDREN:
  660. ret = new List<ISceneEntity>(part.ParentGroup.Parts);
  661. if (ret.Contains(part.ParentGroup.RootPart))
  662. ret.Remove(part.ParentGroup.RootPart);
  663. List<ScenePresence> avs = part.ParentGroup.GetSittingAvatars();
  664. if(avs!= null && avs.Count > 0)
  665. ret.AddRange(avs);
  666. return ret;
  667. case ScriptBaseClass.LINK_THIS:
  668. return new List<ISceneEntity>() { part };
  669. default:
  670. if (linkType < 0)
  671. return new List<ISceneEntity>();
  672. ISceneEntity target = GetLinkEntity(part, linkType);
  673. if (target == null)
  674. return new List<ISceneEntity>();
  675. return new List<ISceneEntity>() { target };
  676. }
  677. }
  678. //These are the implementations of the various ll-functions used by the LSL scripts.
  679. public LSL_Float llSin(double f)
  680. {
  681. m_host.AddScriptLPS(1);
  682. return (double)Math.Sin(f);
  683. }
  684. public LSL_Float llCos(double f)
  685. {
  686. m_host.AddScriptLPS(1);
  687. return (double)Math.Cos(f);
  688. }
  689. public LSL_Float llTan(double f)
  690. {
  691. m_host.AddScriptLPS(1);
  692. return (double)Math.Tan(f);
  693. }
  694. public LSL_Float llAtan2(double x, double y)
  695. {
  696. m_host.AddScriptLPS(1);
  697. return (double)Math.Atan2(x, y);
  698. }
  699. public LSL_Float llSqrt(double f)
  700. {
  701. m_host.AddScriptLPS(1);
  702. return (double)Math.Sqrt(f);
  703. }
  704. public LSL_Float llPow(double fbase, double fexponent)
  705. {
  706. m_host.AddScriptLPS(1);
  707. return (double)Math.Pow(fbase, fexponent);
  708. }
  709. public LSL_Integer llAbs(int i)
  710. {
  711. // changed to replicate LSL behaviour whereby minimum int value is returned untouched.
  712. m_host.AddScriptLPS(1);
  713. if (i == Int32.MinValue)
  714. return i;
  715. else
  716. return (int)Math.Abs(i);
  717. }
  718. public LSL_Float llFabs(double f)
  719. {
  720. m_host.AddScriptLPS(1);
  721. return (double)Math.Abs(f);
  722. }
  723. public LSL_Float llFrand(double mag)
  724. {
  725. m_host.AddScriptLPS(1);
  726. lock (Util.RandomClass)
  727. {
  728. return Util.RandomClass.NextDouble() * mag;
  729. }
  730. }
  731. public LSL_Integer llFloor(double f)
  732. {
  733. m_host.AddScriptLPS(1);
  734. return (int)Math.Floor(f);
  735. }
  736. public LSL_Integer llCeil(double f)
  737. {
  738. m_host.AddScriptLPS(1);
  739. return (int)Math.Ceiling(f);
  740. }
  741. // Xantor 01/May/2008 fixed midpointrounding (2.5 becomes 3.0 instead of 2.0, default = ToEven)
  742. public LSL_Integer llRound(double f)
  743. {
  744. m_host.AddScriptLPS(1);
  745. return (int)Math.Round(f, MidpointRounding.AwayFromZero);
  746. }
  747. //This next group are vector operations involving squaring and square root. ckrinke
  748. public LSL_Float llVecMag(LSL_Vector v)
  749. {
  750. m_host.AddScriptLPS(1);
  751. return LSL_Vector.Mag(v);
  752. }
  753. public LSL_Vector llVecNorm(LSL_Vector v)
  754. {
  755. m_host.AddScriptLPS(1);
  756. return LSL_Vector.Norm(v);
  757. }
  758. private double VecDist(LSL_Vector a, LSL_Vector b)
  759. {
  760. double dx = a.x - b.x;
  761. double dy = a.y - b.y;
  762. double dz = a.z - b.z;
  763. return Math.Sqrt(dx * dx + dy * dy + dz * dz);
  764. }
  765. public LSL_Float llVecDist(LSL_Vector a, LSL_Vector b)
  766. {
  767. m_host.AddScriptLPS(1);
  768. return VecDist(a, b);
  769. }
  770. //Now we start getting into quaternions which means sin/cos, matrices and vectors. ckrinke
  771. // Utility function for llRot2Euler
  772. public LSL_Vector llRot2Euler(LSL_Rotation q1)
  773. {
  774. m_host.AddScriptLPS(1);
  775. LSL_Vector eul = new LSL_Vector();
  776. double sqw = q1.s*q1.s;
  777. double sqx = q1.x*q1.x;
  778. double sqy = q1.z*q1.z;
  779. double sqz = q1.y*q1.y;
  780. double unit = sqx + sqy + sqz + sqw; // if normalised is one, otherwise is correction factor
  781. double test = q1.x*q1.z + q1.y*q1.s;
  782. if (test > 0.4999*unit) { // singularity at north pole
  783. eul.z = 2 * Math.Atan2(q1.x,q1.s);
  784. eul.y = Math.PI/2;
  785. eul.x = 0;
  786. return eul;
  787. }
  788. if (test < -0.4999*unit) { // singularity at south pole
  789. eul.z = -2 * Math.Atan2(q1.x,q1.s);
  790. eul.y = -Math.PI/2;
  791. eul.x = 0;
  792. return eul;
  793. }
  794. eul.z = Math.Atan2(2*q1.z*q1.s-2*q1.x*q1.y , sqx - sqy - sqz + sqw);
  795. eul.y = Math.Asin(2*test/unit);
  796. eul.x = Math.Atan2(2*q1.x*q1.s-2*q1.z*q1.y , -sqx + sqy - sqz + sqw);
  797. return eul;
  798. }
  799. /* From wiki:
  800. The Euler angle vector (in radians) is converted to a rotation by doing the rotations around the 3 axes
  801. in Z, Y, X order. So llEuler2Rot(<1.0, 2.0, 3.0> * DEG_TO_RAD) generates a rotation by taking the zero rotation,
  802. a vector pointing along the X axis, first rotating it 3 degrees around the global Z axis, then rotating the resulting
  803. vector 2 degrees around the global Y axis, and finally rotating that 1 degree around the global X axis.
  804. */
  805. /* How we arrived at this llEuler2Rot
  806. *
  807. * Experiment in SL to determine conventions:
  808. * llEuler2Rot(<PI,0,0>)=<1,0,0,0>
  809. * llEuler2Rot(<0,PI,0>)=<0,1,0,0>
  810. * llEuler2Rot(<0,0,PI>)=<0,0,1,0>
  811. *
  812. * Important facts about Quaternions
  813. * - multiplication is non-commutative (a*b != b*a)
  814. * - http://en.wikipedia.org/wiki/Quaternion#Basis_multiplication
  815. *
  816. * Above SL experiment gives (c1,c2,c3,s1,s2,s3 as defined in our llEuler2Rot):
  817. * Qx = c1+i*s1
  818. * Qy = c2+j*s2;
  819. * Qz = c3+k*s3;
  820. *
  821. * Rotations applied in order (from above) Z, Y, X
  822. * Q = (Qz * Qy) * Qx
  823. * ((c1+i*s1)*(c2+j*s2))*(c3+k*s3)
  824. * (c1*c2+i*s1*c2+j*c1*s2+ij*s1*s2)*(c3+k*s3)
  825. * (c1*c2+i*s1*c2+j*c1*s2+k*s1*s2)*(c3+k*s3)
  826. * c1*c2*c3+i*s1*c2*c3+j*c1*s2*c3+k*s1*s2*c3+k*c1*c2*s3+ik*s1*c2*s3+jk*c1*s2*s3+kk*s1*s2*s3
  827. * c1*c2*c3+i*s1*c2*c3+j*c1*s2*c3+k*s1*s2*c3+k*c1*c2*s3 -j*s1*c2*s3 +i*c1*s2*s3 -s1*s2*s3
  828. * regroup: x=i*(s1*c2*c3+c1*s2*s3)
  829. * y=j*(c1*s2*c3-s1*c2*s3)
  830. * z=k*(s1*s2*c3+c1*c2*s3)
  831. * s= c1*c2*c3-s1*s2*s3
  832. *
  833. * This implementation agrees with the functions found here:
  834. * http://lslwiki.net/lslwiki/wakka.php?wakka=LibraryRotationFunctions
  835. * And with the results in SL.
  836. *
  837. * It's also possible to calculate llEuler2Rot by direct multiplication of
  838. * the Qz, Qy, and Qx vectors (as above - and done in the "accurate" function
  839. * from the wiki).
  840. * Apparently in some cases this is better from a numerical precision perspective?
  841. */
  842. public LSL_Rotation llEuler2Rot(LSL_Vector v)
  843. {
  844. m_host.AddScriptLPS(1);
  845. double x,y,z,s;
  846. v.x *= 0.5;
  847. v.y *= 0.5;
  848. v.z *= 0.5;
  849. double c1 = Math.Cos(v.x);
  850. double c2 = Math.Cos(v.y);
  851. double c1c2 = c1 * c2;
  852. double s1 = Math.Sin(v.x);
  853. double s2 = Math.Sin(v.y);
  854. double s1s2 = s1 * s2;
  855. double c1s2 = c1 * s2;
  856. double s1c2 = s1 * c2;
  857. double c3 = Math.Cos(v.z);
  858. double s3 = Math.Sin(v.z);
  859. x = s1c2 * c3 + c1s2 * s3;
  860. y = c1s2 * c3 - s1c2 * s3;
  861. z = s1s2 * c3 + c1c2 * s3;
  862. s = c1c2 * c3 - s1s2 * s3;
  863. return new LSL_Rotation(x, y, z, s);
  864. }
  865. public LSL_Rotation llAxes2Rot(LSL_Vector fwd, LSL_Vector left, LSL_Vector up)
  866. {
  867. m_host.AddScriptLPS(1);
  868. double s;
  869. double tr = fwd.x + left.y + up.z + 1.0;
  870. if (tr >= 1.0)
  871. {
  872. s = 0.5 / Math.Sqrt(tr);
  873. return new LSL_Rotation(
  874. (left.z - up.y) * s,
  875. (up.x - fwd.z) * s,
  876. (fwd.y - left.x) * s,
  877. 0.25 / s);
  878. }
  879. else
  880. {
  881. double max = (left.y > up.z) ? left.y : up.z;
  882. if (max < fwd.x)
  883. {
  884. s = Math.Sqrt(fwd.x - (left.y + up.z) + 1.0);
  885. double x = s * 0.5;
  886. s = 0.5 / s;
  887. return new LSL_Rotation(
  888. x,
  889. (fwd.y + left.x) * s,
  890. (up.x + fwd.z) * s,
  891. (left.z - up.y) * s);
  892. }
  893. else if (max == left.y)
  894. {
  895. s = Math.Sqrt(left.y - (up.z + fwd.x) + 1.0);
  896. double y = s * 0.5;
  897. s = 0.5 / s;
  898. return new LSL_Rotation(
  899. (fwd.y + left.x) * s,
  900. y,
  901. (left.z + up.y) * s,
  902. (up.x - fwd.z) * s);
  903. }
  904. else
  905. {
  906. s = Math.Sqrt(up.z - (fwd.x + left.y) + 1.0);
  907. double z = s * 0.5;
  908. s = 0.5 / s;
  909. return new LSL_Rotation(
  910. (up.x + fwd.z) * s,
  911. (left.z + up.y) * s,
  912. z,
  913. (fwd.y - left.x) * s);
  914. }
  915. }
  916. }
  917. public LSL_Vector llRot2Fwd(LSL_Rotation r)
  918. {
  919. m_host.AddScriptLPS(1);
  920. double x, y, z, m;
  921. m = r.x * r.x + r.y * r.y + r.z * r.z + r.s * r.s;
  922. // m is always greater than zero
  923. // if m is not equal to 1 then Rotation needs to be normalized
  924. if (Math.Abs(1.0 - m) > 0.000001) // allow a little slop here for calculation precision
  925. {
  926. m = 1.0 / Math.Sqrt(m);
  927. r.x *= m;
  928. r.y *= m;
  929. r.z *= m;
  930. r.s *= m;
  931. }
  932. // Fast Algebric Calculations instead of Vectors & Quaternions Product
  933. x = r.x * r.x - r.y * r.y - r.z * r.z + r.s * r.s;
  934. y = 2 * (r.x * r.y + r.z * r.s);
  935. z = 2 * (r.x * r.z - r.y * r.s);
  936. return (new LSL_Vector(x, y, z));
  937. }
  938. public LSL_Vector llRot2Left(LSL_Rotation r)
  939. {
  940. m_host.AddScriptLPS(1);
  941. double x, y, z, m;
  942. m = r.x * r.x + r.y * r.y + r.z * r.z + r.s * r.s;
  943. // m is always greater than zero
  944. // if m is not equal to 1 then Rotation needs to be normalized
  945. if (Math.Abs(1.0 - m) > 0.000001) // allow a little slop here for calculation precision
  946. {
  947. m = 1.0 / Math.Sqrt(m);
  948. r.x *= m;
  949. r.y *= m;
  950. r.z *= m;
  951. r.s *= m;
  952. }
  953. // Fast Algebric Calculations instead of Vectors & Quaternions Product
  954. x = 2 * (r.x * r.y - r.z * r.s);
  955. y = -r.x * r.x + r.y * r.y - r.z * r.z + r.s * r.s;
  956. z = 2 * (r.x * r.s + r.y * r.z);
  957. return (new LSL_Vector(x, y, z));
  958. }
  959. public LSL_Vector llRot2Up(LSL_Rotation r)
  960. {
  961. m_host.AddScriptLPS(1);
  962. double x, y, z, m;
  963. m = r.x * r.x + r.y * r.y + r.z * r.z + r.s * r.s;
  964. // m is always greater than zero
  965. // if m is not equal to 1 then Rotation needs to be normalized
  966. if (Math.Abs(1.0 - m) > 0.000001) // allow a little slop here for calculation precision
  967. {
  968. m = 1.0 / Math.Sqrt(m);
  969. r.x *= m;
  970. r.y *= m;
  971. r.z *= m;
  972. r.s *= m;
  973. }
  974. // Fast Algebric Calculations instead of Vectors & Quaternions Product
  975. x = 2 * (r.x * r.z + r.y * r.s);
  976. y = 2 * (-r.x * r.s + r.y * r.z);
  977. z = -r.x * r.x - r.y * r.y + r.z * r.z + r.s * r.s;
  978. return (new LSL_Vector(x, y, z));
  979. }
  980. public LSL_Rotation llRotBetween(LSL_Vector a, LSL_Vector b)
  981. {
  982. //A and B should both be normalized
  983. m_host.AddScriptLPS(1);
  984. /* This method is more accurate than the SL one, and thus causes problems
  985. for scripts that deal with the SL inaccuracy around 180-degrees -.- .._.
  986. double dotProduct = LSL_Vector.Dot(a, b);
  987. LSL_Vector crossProduct = LSL_Vector.Cross(a, b);
  988. double magProduct = LSL_Vector.Mag(a) * LSL_Vector.Mag(b);
  989. double angle = Math.Acos(dotProduct / magProduct);
  990. LSL_Vector axis = LSL_Vector.Norm(crossProduct);
  991. double s = Math.Sin(angle / 2);
  992. double x = axis.x * s;
  993. double y = axis.y * s;
  994. double z = axis.z * s;
  995. double w = Math.Cos(angle / 2);
  996. if (Double.IsNaN(x) || Double.IsNaN(y) || Double.IsNaN(z) || Double.IsNaN(w))
  997. return new LSL_Rotation(0.0f, 0.0f, 0.0f, 1.0f);
  998. return new LSL_Rotation((float)x, (float)y, (float)z, (float)w);
  999. */
  1000. // This method mimics the 180 errors found in SL
  1001. // See www.euclideanspace.com... angleBetween
  1002. LSL_Vector vec_a = a;
  1003. LSL_Vector vec_b = b;
  1004. // Eliminate zero length
  1005. LSL_Float vec_a_mag = LSL_Vector.Mag(vec_a);
  1006. LSL_Float vec_b_mag = LSL_Vector.Mag(vec_b);
  1007. if (vec_a_mag < 0.00001 ||
  1008. vec_b_mag < 0.00001)
  1009. {
  1010. return new LSL_Rotation(0.0f, 0.0f, 0.0f, 1.0f);
  1011. }
  1012. // Normalize
  1013. vec_a = llVecNorm(vec_a);
  1014. vec_b = llVecNorm(vec_b);
  1015. // Calculate axis and rotation angle
  1016. LSL_Vector axis = vec_a % vec_b;
  1017. LSL_Float cos_theta = vec_a * vec_b;
  1018. // Check if parallel
  1019. if (cos_theta > 0.99999)
  1020. {
  1021. return new LSL_Rotation(0.0f, 0.0f, 0.0f, 1.0f);
  1022. }
  1023. // Check if anti-parallel
  1024. else if (cos_theta < -0.99999)
  1025. {
  1026. LSL_Vector orthog_axis = new LSL_Vector(1.0, 0.0, 0.0) - (vec_a.x / (vec_a * vec_a) * vec_a);
  1027. if (LSL_Vector.Mag(orthog_axis) < 0.000001) orthog_axis = new LSL_Vector(0.0, 0.0, 1.0);
  1028. return new LSL_Rotation((float)orthog_axis.x, (float)orthog_axis.y, (float)orthog_axis.z, 0.0);
  1029. }
  1030. else // other rotation
  1031. {
  1032. LSL_Float theta = (LSL_Float)Math.Acos(cos_theta) * 0.5f;
  1033. axis = llVecNorm(axis);
  1034. double x, y, z, s, t;
  1035. s = Math.Cos(theta);
  1036. t = Math.Sin(theta);
  1037. x = axis.x * t;
  1038. y = axis.y * t;
  1039. z = axis.z * t;
  1040. return new LSL_Rotation(x,y,z,s);
  1041. }
  1042. }
  1043. public void llWhisper(int channelID, string text)
  1044. {
  1045. m_host.AddScriptLPS(1);
  1046. if (text.Length > 1023)
  1047. text = text.Substring(0, 1023);
  1048. World.SimChat(Utils.StringToBytes(text),
  1049. ChatTypeEnum.Whisper, channelID, m_host.AbsolutePosition, m_host.Name, m_host.UUID, false);
  1050. IWorldComm wComm = m_ScriptEngine.World.RequestModuleInterface<IWorldComm>();
  1051. if (wComm != null)
  1052. wComm.DeliverMessage(ChatTypeEnum.Whisper, channelID, m_host.Name, m_host.UUID, text);
  1053. }
  1054. private void CheckSayShoutTime()
  1055. {
  1056. DateTime now = DateTime.UtcNow;
  1057. if ((now - m_lastSayShoutCheck).Ticks > 10000000) // 1sec
  1058. {
  1059. m_lastSayShoutCheck = now;
  1060. m_SayShoutCount = 0;
  1061. }
  1062. else
  1063. m_SayShoutCount++;
  1064. }
  1065. public void llSay(int channelID, string text)
  1066. {
  1067. m_host.AddScriptLPS(1);
  1068. if (channelID == 0)
  1069. // m_SayShoutCount++;
  1070. CheckSayShoutTime();
  1071. if (m_SayShoutCount >= 11)
  1072. ScriptSleep(2000);
  1073. if (m_scriptConsoleChannelEnabled && (channelID == m_scriptConsoleChannel))
  1074. {
  1075. Console.WriteLine(text);
  1076. }
  1077. else
  1078. {
  1079. if (text.Length > 1023)
  1080. text = text.Substring(0, 1023);
  1081. World.SimChat(Utils.StringToBytes(text),
  1082. ChatTypeEnum.Say, channelID, m_host.AbsolutePosition, m_host.Name, m_host.UUID, false);
  1083. IWorldComm wComm = m_ScriptEngine.World.RequestModuleInterface<IWorldComm>();
  1084. if (wComm != null)
  1085. wComm.DeliverMessage(ChatTypeEnum.Say, channelID, m_host.Name, m_host.UUID, text);
  1086. }
  1087. }
  1088. public void llShout(int channelID, string text)
  1089. {
  1090. m_host.AddScriptLPS(1);
  1091. if (channelID == 0)
  1092. // m_SayShoutCount++;
  1093. CheckSayShoutTime();
  1094. if (m_SayShoutCount >= 11)
  1095. ScriptSleep(2000);
  1096. if (text.Length > 1023)
  1097. text = text.Substring(0, 1023);
  1098. World.SimChat(Utils.StringToBytes(text),
  1099. ChatTypeEnum.Shout, channelID, m_host.AbsolutePosition, m_host.Name, m_host.UUID, true);
  1100. IWorldComm wComm = m_ScriptEngine.World.RequestModuleInterface<IWorldComm>();
  1101. if (wComm != null)
  1102. wComm.DeliverMessage(ChatTypeEnum.Shout, channelID, m_host.Name, m_host.UUID, text);
  1103. }
  1104. public void llRegionSay(int channelID, string text)
  1105. {
  1106. if (channelID == 0)
  1107. {
  1108. Error("llRegionSay", "Cannot use on channel 0");
  1109. return;
  1110. }
  1111. if (text.Length > 1023)
  1112. text = text.Substring(0, 1023);
  1113. m_host.AddScriptLPS(1);
  1114. // debug channel is also sent to avatars
  1115. if (channelID == ScriptBaseClass.DEBUG_CHANNEL)
  1116. {
  1117. World.SimChat(Utils.StringToBytes(text),
  1118. ChatTypeEnum.Shout, channelID, m_host.ParentGroup.RootPart.AbsolutePosition, m_host.Name, m_host.UUID, true);
  1119. }
  1120. IWorldComm wComm = m_ScriptEngine.World.RequestModuleInterface<IWorldComm>();
  1121. if (wComm != null)
  1122. wComm.DeliverMessage(ChatTypeEnum.Region, channelID, m_host.Name, m_host.UUID, text);
  1123. }
  1124. public void llRegionSayTo(string target, int channel, string msg)
  1125. {
  1126. if (msg.Length > 1023)
  1127. msg = msg.Substring(0, 1023);
  1128. m_host.AddScriptLPS(1);
  1129. if (channel == ScriptBaseClass.DEBUG_CHANNEL)
  1130. return;
  1131. UUID TargetID;
  1132. UUID.TryParse(target, out TargetID);
  1133. IWorldComm wComm = m_ScriptEngine.World.RequestModuleInterface<IWorldComm>();
  1134. if (wComm != null)
  1135. wComm.DeliverMessageTo(TargetID, channel, m_host.AbsolutePosition, m_host.Name, m_host.UUID, msg);
  1136. }
  1137. public LSL_Integer llListen(int channelID, string name, string ID, string msg)
  1138. {
  1139. m_host.AddScriptLPS(1);
  1140. UUID keyID;
  1141. UUID.TryParse(ID, out keyID);
  1142. IWorldComm wComm = m_ScriptEngine.World.RequestModuleInterface<IWorldComm>();
  1143. if (wComm != null)
  1144. return wComm.Listen(m_host.LocalId, m_item.ItemID, m_host.UUID, channelID, name, keyID, msg);
  1145. else
  1146. return -1;
  1147. }
  1148. public void llListenControl(int number, int active)
  1149. {
  1150. m_host.AddScriptLPS(1);
  1151. IWorldComm wComm = m_ScriptEngine.World.RequestModuleInterface<IWorldComm>();
  1152. if (wComm != null)
  1153. wComm.ListenControl(m_item.ItemID, number, active);
  1154. }
  1155. public void llListenRemove(int number)
  1156. {
  1157. m_host.AddScriptLPS(1);
  1158. IWorldComm wComm = m_ScriptEngine.World.RequestModuleInterface<IWorldComm>();
  1159. if (wComm != null)
  1160. wComm.ListenRemove(m_item.ItemID, number);
  1161. }
  1162. public void llSensor(string name, string id, int type, double range, double arc)
  1163. {
  1164. m_host.AddScriptLPS(1);
  1165. UUID keyID = UUID.Zero;
  1166. UUID.TryParse(id, out keyID);
  1167. AsyncCommands.SensorRepeatPlugin.SenseOnce(m_host.LocalId, m_item.ItemID, name, keyID, type, range, arc, m_host);
  1168. }
  1169. public void llSensorRepeat(string name, string id, int type, double range, double arc, double rate)
  1170. {
  1171. m_host.AddScriptLPS(1);
  1172. UUID keyID = UUID.Zero;
  1173. UUID.TryParse(id, out keyID);
  1174. AsyncCommands.SensorRepeatPlugin.SetSenseRepeatEvent(m_host.LocalId, m_item.ItemID, name, keyID, type, range, arc, rate, m_host);
  1175. }
  1176. public void llSensorRemove()
  1177. {
  1178. m_host.AddScriptLPS(1);
  1179. AsyncCommands.SensorRepeatPlugin.UnSetSenseRepeaterEvents(m_host.LocalId, m_item.ItemID);
  1180. }
  1181. public string resolveName(UUID objecUUID)
  1182. {
  1183. // try avatar username surname
  1184. UserAccount account = World.UserAccountService.GetUserAccount(World.RegionInfo.ScopeID, objecUUID);
  1185. if (account != null)
  1186. {
  1187. string avatarname = account.Name;
  1188. return avatarname;
  1189. }
  1190. // try an scene object
  1191. SceneObjectPart SOP = World.GetSceneObjectPart(objecUUID);
  1192. if (SOP != null)
  1193. {
  1194. string objectname = SOP.Name;
  1195. return objectname;
  1196. }
  1197. EntityBase SensedObject;
  1198. World.Entities.TryGetValue(objecUUID, out SensedObject);
  1199. if (SensedObject == null)
  1200. {
  1201. IGroupsModule groups = World.RequestModuleInterface<IGroupsModule>();
  1202. if (groups != null)
  1203. {
  1204. GroupRecord gr = groups.GetGroupRecord(objecUUID);
  1205. if (gr != null)
  1206. return gr.GroupName;
  1207. }
  1208. return String.Empty;
  1209. }
  1210. return SensedObject.Name;
  1211. }
  1212. public LSL_String llDetectedName(int number)
  1213. {
  1214. m_host.AddScriptLPS(1);
  1215. DetectParams detectedParams = m_ScriptEngine.GetDetectParams(m_item.ItemID, number);
  1216. if (detectedParams == null)
  1217. return String.Empty;
  1218. return detectedParams.Name;
  1219. }
  1220. public LSL_Key llDetectedKey(int number)
  1221. {
  1222. m_host.AddScriptLPS(1);
  1223. DetectParams detectedParams = m_ScriptEngine.GetDetectParams(m_item.ItemID, number);
  1224. if (detectedParams == null)
  1225. return String.Empty;
  1226. return detectedParams.Key.ToString();
  1227. }
  1228. public LSL_Key llDetectedOwner(int number)
  1229. {
  1230. m_host.AddScriptLPS(1);
  1231. DetectParams detectedParams = m_ScriptEngine.GetDetectParams(m_item.ItemID, number);
  1232. if (detectedParams == null)
  1233. return String.Empty;
  1234. return detectedParams.Owner.ToString();
  1235. }
  1236. public LSL_Integer llDetectedType(int number)
  1237. {
  1238. m_host.AddScriptLPS(1);
  1239. DetectParams detectedParams = m_ScriptEngine.GetDetectParams(m_item.ItemID, number);
  1240. if (detectedParams == null)
  1241. return 0;
  1242. return new LSL_Integer(detectedParams.Type);
  1243. }
  1244. public LSL_Vector llDetectedPos(int number)
  1245. {
  1246. m_host.AddScriptLPS(1);
  1247. DetectParams detectedParams = m_ScriptEngine.GetDetectParams(m_item.ItemID, number);
  1248. if (detectedParams == null)
  1249. return new LSL_Vector();
  1250. return detectedParams.Position;
  1251. }
  1252. public LSL_Vector llDetectedVel(int number)
  1253. {
  1254. m_host.AddScriptLPS(1);
  1255. DetectParams detectedParams = m_ScriptEngine.GetDetectParams(m_item.ItemID, number);
  1256. if (detectedParams == null)
  1257. return new LSL_Vector();
  1258. return detectedParams.Velocity;
  1259. }
  1260. public LSL_Vector llDetectedGrab(int number)
  1261. {
  1262. m_host.AddScriptLPS(1);
  1263. DetectParams parms = m_ScriptEngine.GetDetectParams(m_item.ItemID, number);
  1264. if (parms == null)
  1265. return new LSL_Vector(0, 0, 0);
  1266. return parms.OffsetPos;
  1267. }
  1268. public LSL_Rotation llDetectedRot(int number)
  1269. {
  1270. m_host.AddScriptLPS(1);
  1271. DetectParams detectedParams = m_ScriptEngine.GetDetectParams(m_item.ItemID, number);
  1272. if (detectedParams == null)
  1273. return new LSL_Rotation();
  1274. return detectedParams.Rotation;
  1275. }
  1276. public LSL_Integer llDetectedGroup(int number)
  1277. {
  1278. m_host.AddScriptLPS(1);
  1279. DetectParams detectedParams = m_ScriptEngine.GetDetectParams(m_item.ItemID, number);
  1280. if (detectedParams == null)
  1281. return new LSL_Integer(0);
  1282. if (m_host.GroupID == detectedParams.Group)
  1283. return new LSL_Integer(1);
  1284. return new LSL_Integer(0);
  1285. }
  1286. public LSL_Integer llDetectedLinkNumber(int number)
  1287. {
  1288. m_host.AddScriptLPS(1);
  1289. DetectParams parms = m_ScriptEngine.GetDetectParams(m_item.ItemID, number);
  1290. if (parms == null)
  1291. return new LSL_Integer(0);
  1292. return new LSL_Integer(parms.LinkNum);
  1293. }
  1294. /// <summary>
  1295. /// See http://wiki.secondlife.com/wiki/LlDetectedTouchBinormal for details
  1296. /// </summary>
  1297. public LSL_Vector llDetectedTouchBinormal(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.TouchBinormal;
  1304. }
  1305. /// <summary>
  1306. /// See http://wiki.secondlife.com/wiki/LlDetectedTouchFace for details
  1307. /// </summary>
  1308. public LSL_Integer llDetectedTouchFace(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_Integer(-1);
  1314. return new LSL_Integer(detectedParams.TouchFace);
  1315. }
  1316. /// <summary>
  1317. /// See http://wiki.secondlife.com/wiki/LlDetectedTouchNormal for details
  1318. /// </summary>
  1319. public LSL_Vector llDetectedTouchNormal(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();
  1325. return detectedParams.TouchNormal;
  1326. }
  1327. /// <summary>
  1328. /// See http://wiki.secondlife.com/wiki/LlDetectedTouchPos for details
  1329. /// </summary>
  1330. public LSL_Vector llDetectedTouchPos(int index)
  1331. {
  1332. m_host.AddScriptLPS(1);
  1333. DetectParams detectedParams = m_ScriptEngine.GetDetectParams(m_item.ItemID, index);
  1334. if (detectedParams == null)
  1335. return new LSL_Vector();
  1336. return detectedParams.TouchPos;
  1337. }
  1338. /// <summary>
  1339. /// See http://wiki.secondlife.com/wiki/LlDetectedTouchST for details
  1340. /// </summary>
  1341. public LSL_Vector llDetectedTouchST(int index)
  1342. {
  1343. m_host.AddScriptLPS(1);
  1344. DetectParams detectedParams = m_ScriptEngine.GetDetectParams(m_item.ItemID, index);
  1345. if (detectedParams == null)
  1346. return new LSL_Vector(-1.0, -1.0, 0.0);
  1347. return detectedParams.TouchST;
  1348. }
  1349. /// <summary>
  1350. /// See http://wiki.secondlife.com/wiki/LlDetectedTouchUV for details
  1351. /// </summary>
  1352. public LSL_Vector llDetectedTouchUV(int index)
  1353. {
  1354. m_host.AddScriptLPS(1);
  1355. DetectParams detectedParams = m_ScriptEngine.GetDetectParams(m_item.ItemID, index);
  1356. if (detectedParams == null)
  1357. return new LSL_Vector(-1.0, -1.0, 0.0);
  1358. return detectedParams.TouchUV;
  1359. }
  1360. [DebuggerNonUserCode]
  1361. public virtual void llDie()
  1362. {
  1363. m_host.AddScriptLPS(1);
  1364. if (!m_host.ParentGroup.IsAttachment) throw new SelfDeleteException();
  1365. }
  1366. public LSL_Float llGround(LSL_Vector offset)
  1367. {
  1368. m_host.AddScriptLPS(1);
  1369. Vector3 pos = m_host.GetWorldPosition() + (Vector3)offset;
  1370. //Get the slope normal. This gives us the equation of the plane tangent to the slope.
  1371. LSL_Vector vsn = llGroundNormal(offset);
  1372. // Clamp to valid position
  1373. if (pos.X < 0)
  1374. pos.X = 0;
  1375. else if (pos.X >= World.Heightmap.Width)
  1376. pos.X = World.Heightmap.Width - 1;
  1377. if (pos.Y < 0)
  1378. pos.Y = 0;
  1379. else if (pos.Y >= World.Heightmap.Height)
  1380. pos.Y = World.Heightmap.Height - 1;
  1381. //Get the height for the integer coordinates from the Heightmap
  1382. float baseheight = (float)World.Heightmap[(int)pos.X, (int)pos.Y];
  1383. //Calculate the difference between the actual coordinates and the integer coordinates
  1384. float xdiff = pos.X - (float)((int)pos.X);
  1385. float ydiff = pos.Y - (float)((int)pos.Y);
  1386. //Use the equation of the tangent plane to adjust the height to account for slope
  1387. return (((vsn.x * xdiff) + (vsn.y * ydiff)) / (-1 * vsn.z)) + baseheight;
  1388. }
  1389. public LSL_Float llCloud(LSL_Vector offset)
  1390. {
  1391. m_host.AddScriptLPS(1);
  1392. float cloudCover = 0f;
  1393. ICloudModule module = World.RequestModuleInterface<ICloudModule>();
  1394. if (module != null)
  1395. {
  1396. Vector3 pos = m_host.GetWorldPosition();
  1397. int x = (int)(pos.X + offset.x);
  1398. int y = (int)(pos.Y + offset.y);
  1399. cloudCover = module.CloudCover(x, y, 0);
  1400. }
  1401. return cloudCover;
  1402. }
  1403. public LSL_Vector llWind(LSL_Vector offset)
  1404. {
  1405. m_host.AddScriptLPS(1);
  1406. LSL_Vector wind = new LSL_Vector(0, 0, 0);
  1407. IWindModule module = World.RequestModuleInterface<IWindModule>();
  1408. if (module != null)
  1409. {
  1410. Vector3 pos = m_host.GetWorldPosition();
  1411. int x = (int)(pos.X + offset.x);
  1412. int y = (int)(pos.Y + offset.y);
  1413. Vector3 windSpeed = module.WindSpeed(x, y, 0);
  1414. wind.x = windSpeed.X;
  1415. wind.y = windSpeed.Y;
  1416. }
  1417. return wind;
  1418. }
  1419. public void llSetStatus(int status, int value)
  1420. {
  1421. if (m_host == null || m_host.ParentGroup == null || m_host.ParentGroup.IsDeleted)
  1422. return;
  1423. m_host.AddScriptLPS(1);
  1424. int statusrotationaxis = 0;
  1425. if ((status & ScriptBaseClass.STATUS_PHYSICS) == ScriptBaseClass.STATUS_PHYSICS)
  1426. {
  1427. if (value != 0)
  1428. {
  1429. SceneObjectGroup group = m_host.ParentGroup;
  1430. bool allow = true;
  1431. int maxprims = World.m_linksetPhysCapacity;
  1432. bool checkShape = (maxprims > 0 && group.PrimCount > maxprims);
  1433. foreach (SceneObjectPart part in group.Parts)
  1434. {
  1435. if (part.PhysicsShapeType == (byte)PhysicsShapeType.None)
  1436. continue;
  1437. if (part.Scale.X > World.m_maxPhys || part.Scale.Y > World.m_maxPhys || part.Scale.Z > World.m_maxPhys)
  1438. {
  1439. allow = false;
  1440. break;
  1441. }
  1442. if (checkShape)
  1443. {
  1444. if (--maxprims < 0)
  1445. {
  1446. allow = false;
  1447. break;
  1448. }
  1449. }
  1450. }
  1451. if (!allow)
  1452. return;
  1453. if (m_host.ParentGroup.RootPart.PhysActor != null &&
  1454. m_host.ParentGroup.RootPart.PhysActor.IsPhysical)
  1455. return;
  1456. m_host.ScriptSetPhysicsStatus(true);
  1457. }
  1458. else
  1459. {
  1460. m_host.ScriptSetPhysicsStatus(false);
  1461. }
  1462. }
  1463. if ((status & ScriptBaseClass.STATUS_PHANTOM) == ScriptBaseClass.STATUS_PHANTOM)
  1464. {
  1465. m_host.ParentGroup.ScriptSetPhantomStatus(value != 0);
  1466. }
  1467. if ((status & ScriptBaseClass.STATUS_CAST_SHADOWS) == ScriptBaseClass.STATUS_CAST_SHADOWS)
  1468. {
  1469. m_host.AddFlag(PrimFlags.CastShadows);
  1470. }
  1471. if ((status & ScriptBaseClass.STATUS_ROTATE_X) == ScriptBaseClass.STATUS_ROTATE_X)
  1472. {
  1473. statusrotationaxis |= ScriptBaseClass.STATUS_ROTATE_X;
  1474. }
  1475. if ((status & ScriptBaseClass.STATUS_ROTATE_Y) == ScriptBaseClass.STATUS_ROTATE_Y)
  1476. {
  1477. statusrotationaxis |= ScriptBaseClass.STATUS_ROTATE_Y;
  1478. }
  1479. if ((status & ScriptBaseClass.STATUS_ROTATE_Z) == ScriptBaseClass.STATUS_ROTATE_Z)
  1480. {
  1481. statusrotationaxis |= ScriptBaseClass.STATUS_ROTATE_Z;
  1482. }
  1483. if ((status & ScriptBaseClass.STATUS_BLOCK_GRAB) == ScriptBaseClass.STATUS_BLOCK_GRAB)
  1484. m_host.BlockGrab = value != 0;
  1485. if ((status & ScriptBaseClass.STATUS_BLOCK_GRAB_OBJECT) == ScriptBaseClass.STATUS_BLOCK_GRAB_OBJECT)
  1486. m_host.ParentGroup.BlockGrabOverride = value != 0;
  1487. if ((status & ScriptBaseClass.STATUS_DIE_AT_EDGE) == ScriptBaseClass.STATUS_DIE_AT_EDGE)
  1488. {
  1489. if (value != 0)
  1490. m_host.SetDieAtEdge(true);
  1491. else
  1492. m_host.SetDieAtEdge(false);
  1493. }
  1494. if ((status & ScriptBaseClass.STATUS_RETURN_AT_EDGE) == ScriptBaseClass.STATUS_RETURN_AT_EDGE)
  1495. {
  1496. if (value != 0)
  1497. m_host.SetReturnAtEdge(true);
  1498. else
  1499. m_host.SetReturnAtEdge(false);
  1500. }
  1501. if ((status & ScriptBaseClass.STATUS_SANDBOX) == ScriptBaseClass.STATUS_SANDBOX)
  1502. {
  1503. if (value != 0)
  1504. m_host.SetStatusSandbox(true);
  1505. else
  1506. m_host.SetStatusSandbox(false);
  1507. }
  1508. if (statusrotationaxis != 0)
  1509. {
  1510. m_host.SetAxisRotation(statusrotationaxis, value);
  1511. }
  1512. }
  1513. private bool IsPhysical()
  1514. {
  1515. return ((m_host.GetEffectiveObjectFlags() & (uint)PrimFlags.Physics) == (uint)PrimFlags.Physics);
  1516. }
  1517. public LSL_Integer llGetStatus(int status)
  1518. {
  1519. m_host.AddScriptLPS(1);
  1520. // m_log.Debug(m_host.ToString() + " status is " + m_host.GetEffectiveObjectFlags().ToString());
  1521. switch (status)
  1522. {
  1523. case ScriptBaseClass.STATUS_PHYSICS:
  1524. return IsPhysical() ? 1 : 0;
  1525. case ScriptBaseClass.STATUS_PHANTOM:
  1526. if ((m_host.GetEffectiveObjectFlags() & (uint)PrimFlags.Phantom) == (uint)PrimFlags.Phantom)
  1527. {
  1528. return 1;
  1529. }
  1530. return 0;
  1531. case ScriptBaseClass.STATUS_CAST_SHADOWS:
  1532. if ((m_host.GetEffectiveObjectFlags() & (uint)PrimFlags.CastShadows) == (uint)PrimFlags.CastShadows)
  1533. {
  1534. return 1;
  1535. }
  1536. return 0;
  1537. case ScriptBaseClass.STATUS_BLOCK_GRAB:
  1538. return m_host.BlockGrab ? 1 : 0;
  1539. case ScriptBaseClass.STATUS_BLOCK_GRAB_OBJECT:
  1540. return m_host.ParentGroup.BlockGrabOverride ? 1 : 0;
  1541. case ScriptBaseClass.STATUS_DIE_AT_EDGE:
  1542. if (m_host.GetDieAtEdge())
  1543. return 1;
  1544. else
  1545. return 0;
  1546. case ScriptBaseClass.STATUS_RETURN_AT_EDGE:
  1547. if (m_host.GetReturnAtEdge())
  1548. return 1;
  1549. else
  1550. return 0;
  1551. case ScriptBaseClass.STATUS_ROTATE_X:
  1552. // if (m_host.GetAxisRotation(2) != 0)
  1553. if (m_host.GetAxisRotation((int)SceneObjectGroup.axisSelect.STATUS_ROTATE_X) != 0)
  1554. return 1;
  1555. else
  1556. return 0;
  1557. case ScriptBaseClass.STATUS_ROTATE_Y:
  1558. if (m_host.GetAxisRotation((int)SceneObjectGroup.axisSelect.STATUS_ROTATE_Y) != 0)
  1559. return 1;
  1560. else
  1561. return 0;
  1562. case ScriptBaseClass.STATUS_ROTATE_Z:
  1563. if (m_host.GetAxisRotation((int)SceneObjectGroup.axisSelect.STATUS_ROTATE_Z) != 0)
  1564. return 1;
  1565. else
  1566. return 0;
  1567. case ScriptBaseClass.STATUS_SANDBOX:
  1568. if (m_host.GetStatusSandbox())
  1569. return 1;
  1570. else
  1571. return 0;
  1572. }
  1573. return 0;
  1574. }
  1575. public LSL_Integer llScaleByFactor(double scaling_factor)
  1576. {
  1577. m_host.AddScriptLPS(1);
  1578. SceneObjectGroup group = m_host.ParentGroup;
  1579. if(scaling_factor < 1e-6)
  1580. return ScriptBaseClass.FALSE;
  1581. if(scaling_factor > 1e6)
  1582. return ScriptBaseClass.FALSE;
  1583. if (group == null || group.IsDeleted || group.inTransit)
  1584. return ScriptBaseClass.FALSE;
  1585. if (group.RootPart.PhysActor != null && group.RootPart.PhysActor.IsPhysical)
  1586. return ScriptBaseClass.FALSE;
  1587. if (group.RootPart.KeyframeMotion != null)
  1588. return ScriptBaseClass.FALSE;
  1589. if(group.GroupResize(scaling_factor))
  1590. return ScriptBaseClass.TRUE;
  1591. else
  1592. return ScriptBaseClass.FALSE;
  1593. }
  1594. public LSL_Float llGetMaxScaleFactor()
  1595. {
  1596. m_host.AddScriptLPS(1);
  1597. SceneObjectGroup group = m_host.ParentGroup;
  1598. if (group == null || group.IsDeleted || group.inTransit)
  1599. return 1.0f;
  1600. return (LSL_Float)group.GetMaxGroupResizeScale();
  1601. }
  1602. public LSL_Float llGetMinScaleFactor()
  1603. {
  1604. m_host.AddScriptLPS(1);
  1605. SceneObjectGroup group = m_host.ParentGroup;
  1606. if (group == null || group.IsDeleted || group.inTransit)
  1607. return 1.0f;
  1608. return (LSL_Float)group.GetMinGroupResizeScale();
  1609. }
  1610. public void llSetScale(LSL_Vector scale)
  1611. {
  1612. m_host.AddScriptLPS(1);
  1613. SetScale(m_host, scale);
  1614. }
  1615. protected void SetScale(SceneObjectPart part, LSL_Vector scale)
  1616. {
  1617. // TODO: this needs to trigger a persistance save as well
  1618. if (part == null || part.ParentGroup.IsDeleted)
  1619. return;
  1620. // First we need to check whether or not we need to clamp the size of a physics-enabled prim
  1621. PhysicsActor pa = part.ParentGroup.RootPart.PhysActor;
  1622. if (pa != null && pa.IsPhysical)
  1623. {
  1624. scale.x = Math.Max(World.m_minPhys, Math.Min(World.m_maxPhys, scale.x));
  1625. scale.y = Math.Max(World.m_minPhys, Math.Min(World.m_maxPhys, scale.y));
  1626. scale.z = Math.Max(World.m_minPhys, Math.Min(World.m_maxPhys, scale.z));
  1627. }
  1628. else
  1629. {
  1630. // If not physical, then we clamp the scale to the non-physical min/max
  1631. scale.x = Math.Max(World.m_minNonphys, Math.Min(World.m_maxNonphys, scale.x));
  1632. scale.y = Math.Max(World.m_minNonphys, Math.Min(World.m_maxNonphys, scale.y));
  1633. scale.z = Math.Max(World.m_minNonphys, Math.Min(World.m_maxNonphys, scale.z));
  1634. }
  1635. Vector3 tmp = part.Scale;
  1636. tmp.X = (float)scale.x;
  1637. tmp.Y = (float)scale.y;
  1638. tmp.Z = (float)scale.z;
  1639. part.Scale = tmp;
  1640. part.SendFullUpdateToAllClients();
  1641. }
  1642. public LSL_Vector llGetScale()
  1643. {
  1644. m_host.AddScriptLPS(1);
  1645. return new LSL_Vector(m_host.Scale.X, m_host.Scale.Y, m_host.Scale.Z);
  1646. }
  1647. public void llSetClickAction(int action)
  1648. {
  1649. m_host.AddScriptLPS(1);
  1650. m_host.ClickAction = (byte)action;
  1651. m_host.ParentGroup.HasGroupChanged = true;
  1652. m_host.ScheduleFullUpdate();
  1653. return;
  1654. }
  1655. public void llSetColor(LSL_Vector color, int face)
  1656. {
  1657. m_host.AddScriptLPS(1);
  1658. SetColor(m_host, color, face);
  1659. }
  1660. protected void SetColor(SceneObjectPart part, LSL_Vector color, int face)
  1661. {
  1662. if (part == null || part.ParentGroup == null || part.ParentGroup.IsDeleted)
  1663. return;
  1664. Primitive.TextureEntry tex = part.Shape.Textures;
  1665. int nsides = GetNumberOfSides(part);
  1666. Color4 texcolor;
  1667. if (face >= 0 && face < nsides)
  1668. {
  1669. texcolor = tex.CreateFace((uint)face).RGBA;
  1670. texcolor.R = Util.Clip((float)color.x, 0.0f, 1.0f);
  1671. texcolor.G = Util.Clip((float)color.y, 0.0f, 1.0f);
  1672. texcolor.B = Util.Clip((float)color.z, 0.0f, 1.0f);
  1673. tex.FaceTextures[face].RGBA = texcolor;
  1674. part.UpdateTextureEntry(tex);
  1675. return;
  1676. }
  1677. else if (face == ScriptBaseClass.ALL_SIDES)
  1678. {
  1679. for (uint i = 0; i < nsides; i++)
  1680. {
  1681. if (tex.FaceTextures[i] != null)
  1682. {
  1683. texcolor = tex.FaceTextures[i].RGBA;
  1684. texcolor.R = Util.Clip((float)color.x, 0.0f, 1.0f);
  1685. texcolor.G = Util.Clip((float)color.y, 0.0f, 1.0f);
  1686. texcolor.B = Util.Clip((float)color.z, 0.0f, 1.0f);
  1687. tex.FaceTextures[i].RGBA = texcolor;
  1688. }
  1689. texcolor = tex.DefaultTexture.RGBA;
  1690. texcolor.R = Util.Clip((float)color.x, 0.0f, 1.0f);
  1691. texcolor.G = Util.Clip((float)color.y, 0.0f, 1.0f);
  1692. texcolor.B = Util.Clip((float)color.z, 0.0f, 1.0f);
  1693. tex.DefaultTexture.RGBA = texcolor;
  1694. }
  1695. part.UpdateTextureEntry(tex);
  1696. return;
  1697. }
  1698. if (face == ScriptBaseClass.ALL_SIDES)
  1699. face = SceneObjectPart.ALL_SIDES;
  1700. m_host.SetFaceColorAlpha(face, color, null);
  1701. }
  1702. public void llSetContentType(LSL_Key reqid, LSL_Integer type)
  1703. {
  1704. m_host.AddScriptLPS(1);
  1705. if (m_UrlModule == null)
  1706. return;
  1707. UUID id;
  1708. if(!UUID.TryParse(reqid, out id))
  1709. return;
  1710. // Make sure the content type is text/plain to start with
  1711. m_UrlModule.HttpContentType(id, "text/plain");
  1712. // Is the object owner online and in the region
  1713. ScenePresence agent = World.GetScenePresence(m_host.ParentGroup.OwnerID);
  1714. if (agent == null || agent.IsChildAgent || agent.IsDeleted)
  1715. return; // Fail if the owner is not in the same region
  1716. // Is it the embeded browser?
  1717. string userAgent = m_UrlModule.GetHttpHeader(id, "user-agent");
  1718. if (userAgent.IndexOf("SecondLife") < 0)
  1719. return; // Not the embedded browser. Is this check good enough?
  1720. // Use the IP address of the client and check against the request
  1721. // seperate logins from the same IP will allow all of them to get non-text/plain as long
  1722. // as the owner is in the region. Same as SL!
  1723. string logonFromIPAddress = agent.ControllingClient.RemoteEndPoint.Address.ToString();
  1724. if (string.IsNullOrEmpty(logonFromIPAddress))
  1725. return;
  1726. string requestFromIPAddress = m_UrlModule.GetHttpHeader(id, "x-remote-ip");
  1727. //m_log.Debug("IP from header='" + requestFromIPAddress + "' IP from endpoint='" + logonFromIPAddress + "'");
  1728. if (requestFromIPAddress == null)
  1729. return;
  1730. requestFromIPAddress = requestFromIPAddress.Trim();
  1731. // If the request isnt from the same IP address then the request cannot be from the owner
  1732. if (!requestFromIPAddress.Equals(logonFromIPAddress))
  1733. return;
  1734. switch (type)
  1735. {
  1736. case ScriptBaseClass.CONTENT_TYPE_HTML:
  1737. m_UrlModule.HttpContentType(new UUID(id), "text/html");
  1738. break;
  1739. case ScriptBaseClass.CONTENT_TYPE_XML:
  1740. m_UrlModule.HttpContentType(new UUID(id), "application/xml");
  1741. break;
  1742. case ScriptBaseClass.CONTENT_TYPE_XHTML:
  1743. m_UrlModule.HttpContentType(new UUID(id), "application/xhtml+xml");
  1744. break;
  1745. case ScriptBaseClass.CONTENT_TYPE_ATOM:
  1746. m_UrlModule.HttpContentType(new UUID(id), "application/atom+xml");
  1747. break;
  1748. case ScriptBaseClass.CONTENT_TYPE_JSON:
  1749. m_UrlModule.HttpContentType(new UUID(id), "application/json");
  1750. break;
  1751. case ScriptBaseClass.CONTENT_TYPE_LLSD:
  1752. m_UrlModule.HttpContentType(new UUID(id), "application/llsd+xml");
  1753. break;
  1754. case ScriptBaseClass.CONTENT_TYPE_FORM:
  1755. m_UrlModule.HttpContentType(new UUID(id), "application/x-www-form-urlencoded");
  1756. break;
  1757. case ScriptBaseClass.CONTENT_TYPE_RSS:
  1758. m_UrlModule.HttpContentType(new UUID(id), "application/rss+xml");
  1759. break;
  1760. default:
  1761. m_UrlModule.HttpContentType(new UUID(id), "text/plain");
  1762. break;
  1763. }
  1764. }
  1765. public void SetTexGen(SceneObjectPart part, int face,int style)
  1766. {
  1767. if (part == null || part.ParentGroup == null || part.ParentGroup.IsDeleted)
  1768. return;
  1769. Primitive.TextureEntry tex = part.Shape.Textures;
  1770. MappingType textype;
  1771. textype = MappingType.Default;
  1772. if (style == (int)ScriptBaseClass.PRIM_TEXGEN_PLANAR)
  1773. textype = MappingType.Planar;
  1774. int nsides = GetNumberOfSides(part);
  1775. if (face >= 0 && face < nsides)
  1776. {
  1777. tex.CreateFace((uint) face);
  1778. tex.FaceTextures[face].TexMapType = textype;
  1779. part.UpdateTextureEntry(tex);
  1780. return;
  1781. }
  1782. else if (face == ScriptBaseClass.ALL_SIDES)
  1783. {
  1784. for (uint i = 0; i < nsides; i++)
  1785. {
  1786. if (tex.FaceTextures[i] != null)
  1787. {
  1788. tex.FaceTextures[i].TexMapType = textype;
  1789. }
  1790. }
  1791. tex.DefaultTexture.TexMapType = textype;
  1792. part.UpdateTextureEntry(tex);
  1793. return;
  1794. }
  1795. }
  1796. public void SetGlow(SceneObjectPart part, int face, float glow)
  1797. {
  1798. if (part == null || part.ParentGroup == null || part.ParentGroup.IsDeleted)
  1799. return;
  1800. Primitive.TextureEntry tex = part.Shape.Textures;
  1801. int nsides = GetNumberOfSides(part);
  1802. if (face >= 0 && face < nsides)
  1803. {
  1804. tex.CreateFace((uint) face);
  1805. tex.FaceTextures[face].Glow = glow;
  1806. part.UpdateTextureEntry(tex);
  1807. return;
  1808. }
  1809. else if (face == ScriptBaseClass.ALL_SIDES)
  1810. {
  1811. for (uint i = 0; i < nsides; i++)
  1812. {
  1813. if (tex.FaceTextures[i] != null)
  1814. {
  1815. tex.FaceTextures[i].Glow = glow;
  1816. }
  1817. }
  1818. tex.DefaultTexture.Glow = glow;
  1819. part.UpdateTextureEntry(tex);
  1820. return;
  1821. }
  1822. }
  1823. public void SetShiny(SceneObjectPart part, int face, int shiny, Bumpiness bump)
  1824. {
  1825. if (part == null || part.ParentGroup == null || part.ParentGroup.IsDeleted)
  1826. return;
  1827. Shininess sval = new Shininess();
  1828. switch (shiny)
  1829. {
  1830. case 0:
  1831. sval = Shininess.None;
  1832. break;
  1833. case 1:
  1834. sval = Shininess.Low;
  1835. break;
  1836. case 2:
  1837. sval = Shininess.Medium;
  1838. break;
  1839. case 3:
  1840. sval = Shininess.High;
  1841. break;
  1842. default:
  1843. sval = Shininess.None;
  1844. break;
  1845. }
  1846. int nsides = GetNumberOfSides(part);
  1847. Primitive.TextureEntry tex = part.Shape.Textures;
  1848. if (face >= 0 && face < nsides)
  1849. {
  1850. tex.CreateFace((uint) face);
  1851. tex.FaceTextures[face].Shiny = sval;
  1852. tex.FaceTextures[face].Bump = bump;
  1853. part.UpdateTextureEntry(tex);
  1854. return;
  1855. }
  1856. else if (face == ScriptBaseClass.ALL_SIDES)
  1857. {
  1858. for (uint i = 0; i < nsides; i++)
  1859. {
  1860. if (tex.FaceTextures[i] != null)
  1861. {
  1862. tex.FaceTextures[i].Shiny = sval;
  1863. tex.FaceTextures[i].Bump = bump;
  1864. }
  1865. }
  1866. tex.DefaultTexture.Shiny = sval;
  1867. tex.DefaultTexture.Bump = bump;
  1868. part.UpdateTextureEntry(tex);
  1869. return;
  1870. }
  1871. }
  1872. public void SetFullBright(SceneObjectPart part, int face, bool bright)
  1873. {
  1874. if (part == null || part.ParentGroup == null || part.ParentGroup.IsDeleted)
  1875. return;
  1876. int nsides = GetNumberOfSides(part);
  1877. Primitive.TextureEntry tex = part.Shape.Textures;
  1878. if (face >= 0 && face < nsides)
  1879. {
  1880. tex.CreateFace((uint) face);
  1881. tex.FaceTextures[face].Fullbright = bright;
  1882. part.UpdateTextureEntry(tex);
  1883. return;
  1884. }
  1885. else if (face == ScriptBaseClass.ALL_SIDES)
  1886. {
  1887. for (uint i = 0; i < nsides; i++)
  1888. {
  1889. if (tex.FaceTextures[i] != null)
  1890. {
  1891. tex.FaceTextures[i].Fullbright = bright;
  1892. }
  1893. }
  1894. tex.DefaultTexture.Fullbright = bright;
  1895. part.UpdateTextureEntry(tex);
  1896. return;
  1897. }
  1898. }
  1899. public LSL_Float llGetAlpha(int face)
  1900. {
  1901. m_host.AddScriptLPS(1);
  1902. return GetAlpha(m_host, face);
  1903. }
  1904. protected LSL_Float GetAlpha(SceneObjectPart part, int face)
  1905. {
  1906. Primitive.TextureEntry tex = part.Shape.Textures;
  1907. int nsides = GetNumberOfSides(part);
  1908. if (face == ScriptBaseClass.ALL_SIDES)
  1909. {
  1910. int i;
  1911. double sum = 0.0;
  1912. for (i = 0 ; i < nsides; i++)
  1913. sum += (double)tex.GetFace((uint)i).RGBA.A;
  1914. return sum;
  1915. }
  1916. if (face >= 0 && face < nsides)
  1917. {
  1918. return (double)tex.GetFace((uint)face).RGBA.A;
  1919. }
  1920. return 0.0;
  1921. }
  1922. public void llSetAlpha(double alpha, int face)
  1923. {
  1924. m_host.AddScriptLPS(1);
  1925. SetAlpha(m_host, alpha, face);
  1926. }
  1927. public void llSetLinkAlpha(int linknumber, double alpha, int face)
  1928. {
  1929. m_host.AddScriptLPS(1);
  1930. List<SceneObjectPart> parts = GetLinkParts(linknumber);
  1931. if (parts.Count > 0)
  1932. {
  1933. try
  1934. {
  1935. foreach (SceneObjectPart part in parts)
  1936. SetAlpha(part, alpha, face);
  1937. }
  1938. finally { }
  1939. }
  1940. }
  1941. protected void SetAlpha(SceneObjectPart part, double alpha, int face)
  1942. {
  1943. if (part == null || part.ParentGroup == null || part.ParentGroup.IsDeleted)
  1944. return;
  1945. Primitive.TextureEntry tex = part.Shape.Textures;
  1946. int nsides = GetNumberOfSides(part);
  1947. Color4 texcolor;
  1948. if (face >= 0 && face < nsides)
  1949. {
  1950. texcolor = tex.CreateFace((uint)face).RGBA;
  1951. texcolor.A = Util.Clip((float)alpha, 0.0f, 1.0f);
  1952. tex.FaceTextures[face].RGBA = texcolor;
  1953. part.UpdateTextureEntry(tex);
  1954. return;
  1955. }
  1956. else if (face == ScriptBaseClass.ALL_SIDES)
  1957. {
  1958. for (int i = 0; i < nsides; i++)
  1959. {
  1960. if (tex.FaceTextures[i] != null)
  1961. {
  1962. texcolor = tex.FaceTextures[i].RGBA;
  1963. texcolor.A = Util.Clip((float)alpha, 0.0f, 1.0f);
  1964. tex.FaceTextures[i].RGBA = texcolor;
  1965. }
  1966. }
  1967. // In some cases, the default texture can be null, eg when every face
  1968. // has a unique texture
  1969. if (tex.DefaultTexture != null)
  1970. {
  1971. texcolor = tex.DefaultTexture.RGBA;
  1972. texcolor.A = Util.Clip((float)alpha, 0.0f, 1.0f);
  1973. tex.DefaultTexture.RGBA = texcolor;
  1974. }
  1975. part.UpdateTextureEntry(tex);
  1976. return;
  1977. }
  1978. }
  1979. /// <summary>
  1980. /// Set flexi parameters of a part.
  1981. ///
  1982. /// FIXME: Much of this code should probably be within the part itself.
  1983. /// </summary>
  1984. /// <param name="part"></param>
  1985. /// <param name="flexi"></param>
  1986. /// <param name="softness"></param>
  1987. /// <param name="gravity"></param>
  1988. /// <param name="friction"></param>
  1989. /// <param name="wind"></param>
  1990. /// <param name="tension"></param>
  1991. /// <param name="Force"></param>
  1992. protected void SetFlexi(SceneObjectPart part, bool flexi, int softness, float gravity, float friction,
  1993. float wind, float tension, LSL_Vector Force)
  1994. {
  1995. if (part == null || part.ParentGroup == null || part.ParentGroup.IsDeleted)
  1996. return;
  1997. if (flexi)
  1998. {
  1999. part.Shape.FlexiEntry = true; // this setting flexi true isn't working, but the below parameters do
  2000. // work once the prim is already flexi
  2001. part.Shape.FlexiSoftness = softness;
  2002. part.Shape.FlexiGravity = gravity;
  2003. part.Shape.FlexiDrag = friction;
  2004. part.Shape.FlexiWind = wind;
  2005. part.Shape.FlexiTension = tension;
  2006. part.Shape.FlexiForceX = (float)Force.x;
  2007. part.Shape.FlexiForceY = (float)Force.y;
  2008. part.Shape.FlexiForceZ = (float)Force.z;
  2009. part.Shape.PathCurve = (byte)Extrusion.Flexible;
  2010. }
  2011. else
  2012. {
  2013. // Other values not set, they do not seem to be sent to the viewer
  2014. // Setting PathCurve appears to be what actually toggles the check box and turns Flexi on and off
  2015. part.Shape.PathCurve = (byte)Extrusion.Straight;
  2016. part.Shape.FlexiEntry = false;
  2017. }
  2018. part.ParentGroup.HasGroupChanged = true;
  2019. part.ScheduleFullUpdate();
  2020. }
  2021. /// <summary>
  2022. /// Set a light point on a part
  2023. /// </summary>
  2024. /// FIXME: Much of this code should probably be in SceneObjectGroup
  2025. ///
  2026. /// <param name="part"></param>
  2027. /// <param name="light"></param>
  2028. /// <param name="color"></param>
  2029. /// <param name="intensity"></param>
  2030. /// <param name="radius"></param>
  2031. /// <param name="falloff"></param>
  2032. protected void SetPointLight(SceneObjectPart part, bool light, LSL_Vector color, float intensity, float radius, float falloff)
  2033. {
  2034. if (part == null || part.ParentGroup == null || part.ParentGroup.IsDeleted)
  2035. return;
  2036. if (light)
  2037. {
  2038. part.Shape.LightEntry = true;
  2039. part.Shape.LightColorR = Util.Clip((float)color.x, 0.0f, 1.0f);
  2040. part.Shape.LightColorG = Util.Clip((float)color.y, 0.0f, 1.0f);
  2041. part.Shape.LightColorB = Util.Clip((float)color.z, 0.0f, 1.0f);
  2042. part.Shape.LightIntensity = Util.Clip((float)intensity, 0.0f, 1.0f);
  2043. part.Shape.LightRadius = Util.Clip((float)radius, 0.1f, 20.0f);
  2044. part.Shape.LightFalloff = Util.Clip((float)falloff, 0.01f, 2.0f);
  2045. }
  2046. else
  2047. {
  2048. part.Shape.LightEntry = false;
  2049. }
  2050. part.ParentGroup.HasGroupChanged = true;
  2051. part.ScheduleFullUpdate();
  2052. }
  2053. public LSL_Vector llGetColor(int face)
  2054. {
  2055. m_host.AddScriptLPS(1);
  2056. return GetColor(m_host, face);
  2057. }
  2058. protected LSL_Vector GetColor(SceneObjectPart part, int face)
  2059. {
  2060. Primitive.TextureEntry tex = part.Shape.Textures;
  2061. Color4 texcolor;
  2062. LSL_Vector rgb = new LSL_Vector();
  2063. int nsides = GetNumberOfSides(part);
  2064. if (face == ScriptBaseClass.ALL_SIDES)
  2065. {
  2066. int i;
  2067. for (i = 0; i < nsides; i++)
  2068. {
  2069. texcolor = tex.GetFace((uint)i).RGBA;
  2070. rgb.x += texcolor.R;
  2071. rgb.y += texcolor.G;
  2072. rgb.z += texcolor.B;
  2073. }
  2074. float invnsides = 1.0f / (float)nsides;
  2075. rgb.x *= invnsides;
  2076. rgb.y *= invnsides;
  2077. rgb.z *= invnsides;
  2078. return rgb;
  2079. }
  2080. if (face >= 0 && face < nsides)
  2081. {
  2082. texcolor = tex.GetFace((uint)face).RGBA;
  2083. rgb.x = texcolor.R;
  2084. rgb.y = texcolor.G;
  2085. rgb.z = texcolor.B;
  2086. return rgb;
  2087. }
  2088. else
  2089. {
  2090. return new LSL_Vector();
  2091. }
  2092. }
  2093. public void llSetTexture(string texture, int face)
  2094. {
  2095. m_host.AddScriptLPS(1);
  2096. SetTexture(m_host, texture, face);
  2097. ScriptSleep(m_sleepMsOnSetTexture);
  2098. }
  2099. public void llSetLinkTexture(int linknumber, string texture, int face)
  2100. {
  2101. m_host.AddScriptLPS(1);
  2102. List<SceneObjectPart> parts = GetLinkParts(linknumber);
  2103. if (parts.Count > 0)
  2104. {
  2105. try
  2106. {
  2107. foreach (SceneObjectPart part in parts)
  2108. SetTexture(part, texture, face);
  2109. }
  2110. finally { }
  2111. }
  2112. ScriptSleep(m_sleepMsOnSetLinkTexture);
  2113. }
  2114. protected void SetTexture(SceneObjectPart part, string texture, int face)
  2115. {
  2116. if (part == null || part.ParentGroup == null || part.ParentGroup.IsDeleted)
  2117. return;
  2118. UUID textureID = new UUID();
  2119. textureID = ScriptUtils.GetAssetIdFromItemName(m_host, texture, (int)AssetType.Texture);
  2120. if (textureID == UUID.Zero)
  2121. {
  2122. if (!UUID.TryParse(texture, out textureID))
  2123. return;
  2124. }
  2125. Primitive.TextureEntry tex = part.Shape.Textures;
  2126. int nsides = GetNumberOfSides(part);
  2127. if (face >= 0 && face < nsides)
  2128. {
  2129. Primitive.TextureEntryFace texface = tex.CreateFace((uint)face);
  2130. texface.TextureID = textureID;
  2131. tex.FaceTextures[face] = texface;
  2132. part.UpdateTextureEntry(tex);
  2133. return;
  2134. }
  2135. else if (face == ScriptBaseClass.ALL_SIDES)
  2136. {
  2137. for (uint i = 0; i < nsides; i++)
  2138. {
  2139. if (tex.FaceTextures[i] != null)
  2140. {
  2141. tex.FaceTextures[i].TextureID = textureID;
  2142. }
  2143. }
  2144. tex.DefaultTexture.TextureID = textureID;
  2145. part.UpdateTextureEntry(tex);
  2146. return;
  2147. }
  2148. }
  2149. public void llScaleTexture(double u, double v, int face)
  2150. {
  2151. m_host.AddScriptLPS(1);
  2152. ScaleTexture(m_host, u, v, face);
  2153. ScriptSleep(m_sleepMsOnScaleTexture);
  2154. }
  2155. protected void ScaleTexture(SceneObjectPart part, double u, double v, int face)
  2156. {
  2157. if (part == null || part.ParentGroup == null || part.ParentGroup.IsDeleted)
  2158. return;
  2159. Primitive.TextureEntry tex = part.Shape.Textures;
  2160. int nsides = GetNumberOfSides(part);
  2161. if (face >= 0 && face < nsides)
  2162. {
  2163. Primitive.TextureEntryFace texface = tex.CreateFace((uint)face);
  2164. texface.RepeatU = (float)u;
  2165. texface.RepeatV = (float)v;
  2166. tex.FaceTextures[face] = texface;
  2167. part.UpdateTextureEntry(tex);
  2168. return;
  2169. }
  2170. if (face == ScriptBaseClass.ALL_SIDES)
  2171. {
  2172. for (int i = 0; i < nsides; i++)
  2173. {
  2174. if (tex.FaceTextures[i] != null)
  2175. {
  2176. tex.FaceTextures[i].RepeatU = (float)u;
  2177. tex.FaceTextures[i].RepeatV = (float)v;
  2178. }
  2179. }
  2180. tex.DefaultTexture.RepeatU = (float)u;
  2181. tex.DefaultTexture.RepeatV = (float)v;
  2182. part.UpdateTextureEntry(tex);
  2183. return;
  2184. }
  2185. }
  2186. public void llOffsetTexture(double u, double v, int face)
  2187. {
  2188. m_host.AddScriptLPS(1);
  2189. OffsetTexture(m_host, u, v, face);
  2190. ScriptSleep(m_sleepMsOnOffsetTexture);
  2191. }
  2192. protected void OffsetTexture(SceneObjectPart part, double u, double v, int face)
  2193. {
  2194. if (part == null || part.ParentGroup == null || part.ParentGroup.IsDeleted)
  2195. return;
  2196. Primitive.TextureEntry tex = part.Shape.Textures;
  2197. int nsides = GetNumberOfSides(part);
  2198. if (face >= 0 && face < nsides)
  2199. {
  2200. Primitive.TextureEntryFace texface = tex.CreateFace((uint)face);
  2201. texface.OffsetU = (float)u;
  2202. texface.OffsetV = (float)v;
  2203. tex.FaceTextures[face] = texface;
  2204. part.UpdateTextureEntry(tex);
  2205. return;
  2206. }
  2207. if (face == ScriptBaseClass.ALL_SIDES)
  2208. {
  2209. for (int i = 0; i < nsides; i++)
  2210. {
  2211. if (tex.FaceTextures[i] != null)
  2212. {
  2213. tex.FaceTextures[i].OffsetU = (float)u;
  2214. tex.FaceTextures[i].OffsetV = (float)v;
  2215. }
  2216. }
  2217. tex.DefaultTexture.OffsetU = (float)u;
  2218. tex.DefaultTexture.OffsetV = (float)v;
  2219. part.UpdateTextureEntry(tex);
  2220. return;
  2221. }
  2222. }
  2223. public void llRotateTexture(double rotation, int face)
  2224. {
  2225. m_host.AddScriptLPS(1);
  2226. RotateTexture(m_host, rotation, face);
  2227. ScriptSleep(m_sleepMsOnRotateTexture);
  2228. }
  2229. protected void RotateTexture(SceneObjectPart part, double rotation, int face)
  2230. {
  2231. if (part == null || part.ParentGroup == null || part.ParentGroup.IsDeleted)
  2232. return;
  2233. Primitive.TextureEntry tex = part.Shape.Textures;
  2234. int nsides = GetNumberOfSides(part);
  2235. if (face >= 0 && face < nsides)
  2236. {
  2237. Primitive.TextureEntryFace texface = tex.CreateFace((uint)face);
  2238. texface.Rotation = (float)rotation;
  2239. tex.FaceTextures[face] = texface;
  2240. part.UpdateTextureEntry(tex);
  2241. return;
  2242. }
  2243. if (face == ScriptBaseClass.ALL_SIDES)
  2244. {
  2245. for (int i = 0; i < nsides; i++)
  2246. {
  2247. if (tex.FaceTextures[i] != null)
  2248. {
  2249. tex.FaceTextures[i].Rotation = (float)rotation;
  2250. }
  2251. }
  2252. tex.DefaultTexture.Rotation = (float)rotation;
  2253. part.UpdateTextureEntry(tex);
  2254. return;
  2255. }
  2256. }
  2257. public LSL_String llGetTexture(int face)
  2258. {
  2259. m_host.AddScriptLPS(1);
  2260. return GetTexture(m_host, face);
  2261. }
  2262. protected LSL_String GetTexture(SceneObjectPart part, int face)
  2263. {
  2264. Primitive.TextureEntry tex = part.Shape.Textures;
  2265. int nsides = GetNumberOfSides(part);
  2266. if (face == ScriptBaseClass.ALL_SIDES)
  2267. {
  2268. face = 0;
  2269. }
  2270. if (face >= 0 && face < nsides)
  2271. {
  2272. Primitive.TextureEntryFace texface;
  2273. texface = tex.GetFace((uint)face);
  2274. string texture = texface.TextureID.ToString();
  2275. lock (part.TaskInventory)
  2276. {
  2277. foreach (KeyValuePair<UUID, TaskInventoryItem> inv in part.TaskInventory)
  2278. {
  2279. if (inv.Value.AssetID == texface.TextureID)
  2280. {
  2281. texture = inv.Value.Name.ToString();
  2282. break;
  2283. }
  2284. }
  2285. }
  2286. return texture;
  2287. }
  2288. else
  2289. {
  2290. return UUID.Zero.ToString();
  2291. }
  2292. }
  2293. public void llSetPos(LSL_Vector pos)
  2294. {
  2295. m_host.AddScriptLPS(1);
  2296. SetPos(m_host, pos, true);
  2297. ScriptSleep(m_sleepMsOnSetPos);
  2298. }
  2299. /// <summary>
  2300. /// Tries to move the entire object so that the root prim is within 0.1m of position. http://wiki.secondlife.com/wiki/LlSetRegionPos
  2301. /// 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.
  2302. /// 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.
  2303. /// </summary>
  2304. /// <param name="pos"></param>
  2305. /// <returns>1 if successful, 0 otherwise.</returns>
  2306. public LSL_Integer llSetRegionPos(LSL_Vector pos)
  2307. {
  2308. m_host.AddScriptLPS(1);
  2309. // BEGIN WORKAROUND
  2310. // IF YOU GET REGION CROSSINGS WORKING WITH THIS FUNCTION, REPLACE THE WORKAROUND.
  2311. //
  2312. // This workaround is to prevent silent failure of this function.
  2313. // According to the specification on the SL Wiki, providing a position outside of the
  2314. if (pos.x < 0 || pos.x > World.RegionInfo.RegionSizeX || pos.y < 0 || pos.y > World.RegionInfo.RegionSizeY)
  2315. {
  2316. return 0;
  2317. }
  2318. // END WORK AROUND
  2319. else if ( // this is not part of the workaround if-block because it's not related to the workaround.
  2320. IsPhysical() ||
  2321. m_host.ParentGroup.IsAttachment || // return FALSE if attachment
  2322. (
  2323. pos.x < -10.0 || // return FALSE if more than 10 meters into a west-adjacent region.
  2324. pos.x > (World.RegionInfo.RegionSizeX + 10) || // return FALSE if more than 10 meters into a east-adjacent region.
  2325. pos.y < -10.0 || // return FALSE if more than 10 meters into a south-adjacent region.
  2326. pos.y > (World.RegionInfo.RegionSizeY + 10) || // return FALSE if more than 10 meters into a north-adjacent region.
  2327. pos.z > Constants.RegionHeight // return FALSE if altitude than 4096m
  2328. )
  2329. )
  2330. {
  2331. return 0;
  2332. }
  2333. // if we reach this point, then the object is not physical, it's not an attachment, and the destination is within the valid range.
  2334. // 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.
  2335. Vector3 objectPos = m_host.ParentGroup.RootPart.AbsolutePosition;
  2336. LandData here = World.GetLandData(objectPos);
  2337. LandData there = World.GetLandData(pos);
  2338. // 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.
  2339. bool sameParcel = here.GlobalID == there.GlobalID;
  2340. if (!sameParcel && !World.Permissions.CanRezObject(
  2341. m_host.ParentGroup.PrimCount, m_host.ParentGroup.OwnerID, pos))
  2342. {
  2343. return 0;
  2344. }
  2345. SetPos(m_host.ParentGroup.RootPart, pos, false);
  2346. return VecDist(pos, llGetRootPosition()) <= 0.1 ? 1 : 0;
  2347. }
  2348. // Capped movemment if distance > 10m (http://wiki.secondlife.com/wiki/LlSetPos)
  2349. // note linked setpos is capped "differently"
  2350. private LSL_Vector SetPosAdjust(LSL_Vector start, LSL_Vector end)
  2351. {
  2352. if (llVecDist(start, end) > 10.0f * m_ScriptDistanceFactor)
  2353. return start + m_ScriptDistanceFactor * 10.0f * llVecNorm(end - start);
  2354. else
  2355. return end;
  2356. }
  2357. protected LSL_Vector GetSetPosTarget(SceneObjectPart part, LSL_Vector targetPos, LSL_Vector fromPos, bool adjust)
  2358. {
  2359. if (part == null || part.ParentGroup == null || part.ParentGroup.IsDeleted)
  2360. return fromPos;
  2361. // Capped movemment if distance > 10m (http://wiki.secondlife.com/wiki/LlSetPos)
  2362. float ground = World.GetGroundHeight((float)targetPos.x, (float)targetPos.y);
  2363. bool disable_underground_movement = m_ScriptEngine.Config.GetBoolean("DisableUndergroundMovement", true);
  2364. if (part.ParentGroup.RootPart == part)
  2365. {
  2366. if ((targetPos.z < ground) && disable_underground_movement && m_host.ParentGroup.AttachmentPoint == 0)
  2367. targetPos.z = ground;
  2368. }
  2369. if (adjust)
  2370. return SetPosAdjust(fromPos, targetPos);
  2371. return targetPos;
  2372. }
  2373. /// <summary>
  2374. /// set object position, optionally capping the distance.
  2375. /// </summary>
  2376. /// <param name="part"></param>
  2377. /// <param name="targetPos"></param>
  2378. /// <param name="adjust">if TRUE, will cap the distance to 10m.</param>
  2379. protected void SetPos(SceneObjectPart part, LSL_Vector targetPos, bool adjust)
  2380. {
  2381. if (part == null || part.ParentGroup == null || part.ParentGroup.IsDeleted || part.ParentGroup.inTransit)
  2382. return;
  2383. LSL_Vector currentPos = GetPartLocalPos(part);
  2384. LSL_Vector toPos = GetSetPosTarget(part, targetPos, currentPos, adjust);
  2385. if (part.ParentGroup.RootPart == part)
  2386. {
  2387. SceneObjectGroup parent = part.ParentGroup;
  2388. if (!parent.IsAttachment && !World.Permissions.CanObjectEntry(parent, false, (Vector3)toPos))
  2389. return;
  2390. parent.UpdateGroupPosition((Vector3)toPos);
  2391. }
  2392. else
  2393. {
  2394. part.OffsetPosition = (Vector3)toPos;
  2395. // SceneObjectGroup parent = part.ParentGroup;
  2396. // parent.HasGroupChanged = true;
  2397. // parent.ScheduleGroupForTerseUpdate();
  2398. part.ScheduleTerseUpdate();
  2399. }
  2400. }
  2401. public LSL_Vector llGetPos()
  2402. {
  2403. m_host.AddScriptLPS(1);
  2404. return m_host.GetWorldPosition();
  2405. }
  2406. public LSL_Vector llGetLocalPos()
  2407. {
  2408. m_host.AddScriptLPS(1);
  2409. return GetPartLocalPos(m_host);
  2410. }
  2411. protected LSL_Vector GetPartLocalPos(SceneObjectPart part)
  2412. {
  2413. m_host.AddScriptLPS(1);
  2414. Vector3 pos;
  2415. if (!part.IsRoot)
  2416. {
  2417. pos = part.OffsetPosition;
  2418. }
  2419. else
  2420. {
  2421. if (part.ParentGroup.IsAttachment)
  2422. pos = part.AttachedPos;
  2423. else
  2424. pos = part.AbsolutePosition;
  2425. }
  2426. // m_log.DebugFormat("[LSL API]: Returning {0} in GetPartLocalPos()", pos);
  2427. return new LSL_Vector(pos);
  2428. }
  2429. public void llSetRot(LSL_Rotation rot)
  2430. {
  2431. m_host.AddScriptLPS(1);
  2432. // try to let this work as in SL...
  2433. if (m_host.ParentID == 0 || (m_host.ParentGroup != null && m_host == m_host.ParentGroup.RootPart))
  2434. {
  2435. // special case: If we are root, rotate complete SOG to new rotation
  2436. SetRot(m_host, rot);
  2437. }
  2438. else
  2439. {
  2440. // we are a child. The rotation values will be set to the one of root modified by rot, as in SL. Don't ask.
  2441. SceneObjectPart rootPart = m_host.ParentGroup.RootPart;
  2442. if (rootPart != null) // better safe than sorry
  2443. {
  2444. SetRot(m_host, rootPart.RotationOffset * (Quaternion)rot);
  2445. }
  2446. }
  2447. ScriptSleep(m_sleepMsOnSetRot);
  2448. }
  2449. public void llSetLocalRot(LSL_Rotation rot)
  2450. {
  2451. m_host.AddScriptLPS(1);
  2452. SetRot(m_host, rot);
  2453. ScriptSleep(m_sleepMsOnSetLocalRot);
  2454. }
  2455. protected void SetRot(SceneObjectPart part, Quaternion rot)
  2456. {
  2457. if (part == null || part.ParentGroup == null || part.ParentGroup.IsDeleted)
  2458. return;
  2459. bool isroot = (part == part.ParentGroup.RootPart);
  2460. bool isphys;
  2461. PhysicsActor pa = part.PhysActor;
  2462. // keep using physactor ideia of isphysical
  2463. // it should be SOP ideia of that
  2464. // not much of a issue with ubOde
  2465. if (pa != null && pa.IsPhysical)
  2466. isphys = true;
  2467. else
  2468. isphys = false;
  2469. // SL doesn't let scripts rotate root of physical linksets
  2470. if (isroot && isphys)
  2471. return;
  2472. part.UpdateRotation(rot);
  2473. // Update rotation does not move the object in the physics engine if it's a non physical linkset
  2474. // so do a nasty update of parts positions if is a root part rotation
  2475. if (isroot && pa != null) // with if above implies non physical root part
  2476. {
  2477. part.ParentGroup.ResetChildPrimPhysicsPositions();
  2478. }
  2479. else // fix sitting avatars. This is only needed bc of how we link avas to child parts, not root part
  2480. {
  2481. // List<ScenePresence> sittingavas = part.ParentGroup.GetLinkedAvatars();
  2482. List<ScenePresence> sittingavas = part.ParentGroup.GetSittingAvatars();
  2483. if (sittingavas.Count > 0)
  2484. {
  2485. foreach (ScenePresence av in sittingavas)
  2486. {
  2487. if (isroot || part.LocalId == av.ParentID)
  2488. av.SendTerseUpdateToAllClients();
  2489. }
  2490. }
  2491. }
  2492. }
  2493. /// <summary>
  2494. /// See http://lslwiki.net/lslwiki/wakka.php?wakka=ChildRotation
  2495. /// </summary>
  2496. public LSL_Rotation llGetRot()
  2497. {
  2498. // unlinked or root prim then use llRootRotation
  2499. // see llRootRotaion for references.
  2500. if (m_host.LinkNum == 0 || m_host.LinkNum == 1)
  2501. {
  2502. return llGetRootRotation();
  2503. }
  2504. m_host.AddScriptLPS(1);
  2505. Quaternion q = m_host.GetWorldRotation();
  2506. if (m_host.ParentGroup != null && m_host.ParentGroup.AttachmentPoint != 0)
  2507. {
  2508. ScenePresence avatar = World.GetScenePresence(m_host.ParentGroup.AttachedAvatar);
  2509. if (avatar != null)
  2510. {
  2511. if ((avatar.AgentControlFlags & (uint)AgentManager.ControlFlags.AGENT_CONTROL_MOUSELOOK) != 0)
  2512. q = avatar.CameraRotation * q; // Mouselook
  2513. else
  2514. q = avatar.Rotation * q; // Currently infrequently updated so may be inaccurate
  2515. }
  2516. }
  2517. return new LSL_Rotation(q.X, q.Y, q.Z, q.W);
  2518. }
  2519. private LSL_Rotation GetPartRot(SceneObjectPart part)
  2520. {
  2521. Quaternion q;
  2522. if (part.LinkNum == 0 || part.LinkNum == 1) // unlinked or root prim
  2523. {
  2524. if (part.ParentGroup.AttachmentPoint != 0)
  2525. {
  2526. ScenePresence avatar = World.GetScenePresence(part.ParentGroup.AttachedAvatar);
  2527. if (avatar != null)
  2528. {
  2529. if ((avatar.AgentControlFlags & (uint)AgentManager.ControlFlags.AGENT_CONTROL_MOUSELOOK) != 0)
  2530. q = avatar.CameraRotation; // Mouselook
  2531. else
  2532. q = avatar.GetWorldRotation(); // Currently infrequently updated so may be inaccurate
  2533. }
  2534. else
  2535. q = part.ParentGroup.GroupRotation; // Likely never get here but just in case
  2536. }
  2537. else
  2538. q = part.ParentGroup.GroupRotation; // just the group rotation
  2539. return new LSL_Rotation(q);
  2540. }
  2541. q = part.GetWorldRotation();
  2542. if (part.ParentGroup.AttachmentPoint != 0)
  2543. {
  2544. ScenePresence avatar = World.GetScenePresence(part.ParentGroup.AttachedAvatar);
  2545. if (avatar != null)
  2546. {
  2547. if ((avatar.AgentControlFlags & (uint)AgentManager.ControlFlags.AGENT_CONTROL_MOUSELOOK) != 0)
  2548. q = avatar.CameraRotation * q; // Mouselook
  2549. else
  2550. q = avatar.Rotation * q; // Currently infrequently updated so may be inaccurate
  2551. }
  2552. }
  2553. return new LSL_Rotation(q.X, q.Y, q.Z, q.W);
  2554. }
  2555. public LSL_Rotation llGetLocalRot()
  2556. {
  2557. return GetPartLocalRot(m_host);
  2558. }
  2559. private LSL_Rotation GetPartLocalRot(SceneObjectPart part)
  2560. {
  2561. m_host.AddScriptLPS(1);
  2562. Quaternion rot = part.RotationOffset;
  2563. return new LSL_Rotation(rot.X, rot.Y, rot.Z, rot.W);
  2564. }
  2565. public void llSetForce(LSL_Vector force, int local)
  2566. {
  2567. m_host.AddScriptLPS(1);
  2568. if (!m_host.ParentGroup.IsDeleted)
  2569. {
  2570. if (local != 0)
  2571. force *= llGetRot();
  2572. m_host.ParentGroup.RootPart.SetForce(force);
  2573. }
  2574. }
  2575. public LSL_Vector llGetForce()
  2576. {
  2577. LSL_Vector force = new LSL_Vector(0.0, 0.0, 0.0);
  2578. m_host.AddScriptLPS(1);
  2579. if (!m_host.ParentGroup.IsDeleted)
  2580. {
  2581. force = m_host.ParentGroup.RootPart.GetForce();
  2582. }
  2583. return force;
  2584. }
  2585. public void llSetVelocity(LSL_Vector vel, int local)
  2586. {
  2587. m_host.AddScriptLPS(1);
  2588. m_host.SetVelocity(new Vector3((float)vel.x, (float)vel.y, (float)vel.z), local != 0);
  2589. }
  2590. public void llSetAngularVelocity(LSL_Vector avel, int local)
  2591. {
  2592. m_host.AddScriptLPS(1);
  2593. m_host.SetAngularVelocity(new Vector3((float)avel.x, (float)avel.y, (float)avel.z), local != 0);
  2594. }
  2595. public LSL_Integer llTarget(LSL_Vector position, double range)
  2596. {
  2597. m_host.AddScriptLPS(1);
  2598. return m_host.ParentGroup.registerTargetWaypoint(position,
  2599. (float)range);
  2600. }
  2601. public void llTargetRemove(int number)
  2602. {
  2603. m_host.AddScriptLPS(1);
  2604. m_host.ParentGroup.unregisterTargetWaypoint(number);
  2605. }
  2606. public LSL_Integer llRotTarget(LSL_Rotation rot, double error)
  2607. {
  2608. m_host.AddScriptLPS(1);
  2609. return m_host.ParentGroup.registerRotTargetWaypoint(rot, (float)error);
  2610. }
  2611. public void llRotTargetRemove(int number)
  2612. {
  2613. m_host.AddScriptLPS(1);
  2614. m_host.ParentGroup.unregisterRotTargetWaypoint(number);
  2615. }
  2616. public void llMoveToTarget(LSL_Vector target, double tau)
  2617. {
  2618. m_host.AddScriptLPS(1);
  2619. m_host.ParentGroup.MoveToTarget(target, (float)tau);
  2620. }
  2621. public void llStopMoveToTarget()
  2622. {
  2623. m_host.AddScriptLPS(1);
  2624. m_host.ParentGroup.StopMoveToTarget();
  2625. }
  2626. public void llApplyImpulse(LSL_Vector force, int local)
  2627. {
  2628. m_host.AddScriptLPS(1);
  2629. //No energy force yet
  2630. Vector3 v = force;
  2631. if (v.Length() > 20000.0f)
  2632. {
  2633. v.Normalize();
  2634. v = v * 20000.0f;
  2635. }
  2636. m_host.ApplyImpulse(v, local != 0);
  2637. }
  2638. public void llApplyRotationalImpulse(LSL_Vector force, int local)
  2639. {
  2640. m_host.AddScriptLPS(1);
  2641. m_host.ParentGroup.RootPart.ApplyAngularImpulse(force, local != 0);
  2642. }
  2643. public void llSetTorque(LSL_Vector torque, int local)
  2644. {
  2645. m_host.AddScriptLPS(1);
  2646. m_host.ParentGroup.RootPart.SetAngularImpulse(torque, local != 0);
  2647. }
  2648. public LSL_Vector llGetTorque()
  2649. {
  2650. m_host.AddScriptLPS(1);
  2651. return new LSL_Vector(m_host.ParentGroup.GetTorque());
  2652. }
  2653. public void llSetForceAndTorque(LSL_Vector force, LSL_Vector torque, int local)
  2654. {
  2655. m_host.AddScriptLPS(1);
  2656. llSetForce(force, local);
  2657. llSetTorque(torque, local);
  2658. }
  2659. public LSL_Vector llGetVel()
  2660. {
  2661. m_host.AddScriptLPS(1);
  2662. Vector3 vel = Vector3.Zero;
  2663. if (m_host.ParentGroup.IsAttachment)
  2664. {
  2665. ScenePresence avatar = m_host.ParentGroup.Scene.GetScenePresence(m_host.ParentGroup.AttachedAvatar);
  2666. if (avatar != null)
  2667. vel = avatar.GetWorldVelocity();
  2668. }
  2669. else
  2670. {
  2671. vel = m_host.ParentGroup.RootPart.Velocity;
  2672. }
  2673. return new LSL_Vector(vel);
  2674. }
  2675. public LSL_Vector llGetAccel()
  2676. {
  2677. m_host.AddScriptLPS(1);
  2678. return new LSL_Vector(m_host.Acceleration);
  2679. }
  2680. public LSL_Vector llGetOmega()
  2681. {
  2682. m_host.AddScriptLPS(1);
  2683. Vector3 avel = m_host.AngularVelocity;
  2684. return new LSL_Vector(avel.X, avel.Y, avel.Z);
  2685. }
  2686. public LSL_Float llGetTimeOfDay()
  2687. {
  2688. m_host.AddScriptLPS(1);
  2689. return (double)((DateTime.Now.TimeOfDay.TotalMilliseconds / 1000) % (3600 * 4));
  2690. }
  2691. public LSL_Float llGetWallclock()
  2692. {
  2693. m_host.AddScriptLPS(1);
  2694. return DateTime.Now.TimeOfDay.TotalSeconds;
  2695. }
  2696. public LSL_Float llGetTime()
  2697. {
  2698. m_host.AddScriptLPS(1);
  2699. double ScriptTime = Util.GetTimeStampMS() - m_timer;
  2700. return (float)Math.Round((ScriptTime / 1000.0), 3);
  2701. }
  2702. public void llResetTime()
  2703. {
  2704. m_host.AddScriptLPS(1);
  2705. m_timer = Util.GetTimeStampMS();
  2706. }
  2707. public LSL_Float llGetAndResetTime()
  2708. {
  2709. m_host.AddScriptLPS(1);
  2710. double now = Util.GetTimeStampMS();
  2711. double ScriptTime = now - m_timer;
  2712. m_timer = now;
  2713. return (float)Math.Round((ScriptTime / 1000.0), 3);
  2714. }
  2715. public void llSound(string sound, double volume, int queue, int loop)
  2716. {
  2717. m_host.AddScriptLPS(1);
  2718. Deprecated("llSound", "Use llPlaySound instead");
  2719. }
  2720. // Xantor 20080528 PlaySound updated so it accepts an objectinventory name -or- a key to a sound
  2721. // 20080530 Updated to remove code duplication
  2722. public void llPlaySound(string sound, double volume)
  2723. {
  2724. m_host.AddScriptLPS(1);
  2725. if (m_SoundModule == null)
  2726. return;
  2727. UUID soundID = ScriptUtils.GetAssetIdFromKeyOrItemName(m_host, sound, AssetType.Sound);
  2728. if(soundID == UUID.Zero)
  2729. return;
  2730. // send the sound, once, to all clients in range
  2731. m_SoundModule.SendSound(m_host.UUID, soundID, volume, false, 0, false, false);
  2732. }
  2733. public void llLoopSound(string sound, double volume)
  2734. {
  2735. m_host.AddScriptLPS(1);
  2736. if (m_SoundModule == null)
  2737. return;
  2738. UUID soundID = ScriptUtils.GetAssetIdFromKeyOrItemName(m_host, sound, AssetType.Sound);
  2739. if(soundID == UUID.Zero)
  2740. return;
  2741. m_SoundModule.LoopSound(m_host.UUID, soundID, volume, false,false);
  2742. }
  2743. public void llLoopSoundMaster(string sound, double volume)
  2744. {
  2745. m_host.AddScriptLPS(1);
  2746. if (m_SoundModule == null)
  2747. return;
  2748. UUID soundID = ScriptUtils.GetAssetIdFromKeyOrItemName(m_host, sound, AssetType.Sound);
  2749. if(soundID == UUID.Zero)
  2750. return;
  2751. m_SoundModule.LoopSound(m_host.UUID, soundID, volume, true, false);
  2752. }
  2753. public void llLoopSoundSlave(string sound, double volume)
  2754. {
  2755. m_host.AddScriptLPS(1);
  2756. if (m_SoundModule == null)
  2757. return;
  2758. UUID soundID = ScriptUtils.GetAssetIdFromKeyOrItemName(m_host, sound, AssetType.Sound);
  2759. if(soundID == UUID.Zero)
  2760. return;
  2761. m_SoundModule.LoopSound(m_host.UUID, soundID, volume, false, true);
  2762. }
  2763. public void llPlaySoundSlave(string sound, double volume)
  2764. {
  2765. m_host.AddScriptLPS(1);
  2766. if (m_SoundModule == null)
  2767. return;
  2768. UUID soundID = ScriptUtils.GetAssetIdFromKeyOrItemName(m_host, sound, AssetType.Sound);
  2769. if(soundID == UUID.Zero)
  2770. return;
  2771. // send the sound, once, to all clients in range
  2772. m_SoundModule.SendSound(m_host.UUID, soundID, volume, false, 0, true, false);
  2773. }
  2774. public void llTriggerSound(string sound, double volume)
  2775. {
  2776. m_host.AddScriptLPS(1);
  2777. if (m_SoundModule == null)
  2778. return;
  2779. UUID soundID = ScriptUtils.GetAssetIdFromKeyOrItemName(m_host, sound, AssetType.Sound);
  2780. if(soundID == UUID.Zero)
  2781. return;
  2782. // send the sound, once, to all clients in rangeTrigger or play an attached sound in this part's inventory.
  2783. m_SoundModule.SendSound(m_host.UUID, soundID, volume, true, 0, false, false);
  2784. }
  2785. public void llStopSound()
  2786. {
  2787. m_host.AddScriptLPS(1);
  2788. if (m_SoundModule != null)
  2789. m_SoundModule.StopSound(m_host.UUID);
  2790. }
  2791. public void llPreloadSound(string sound)
  2792. {
  2793. m_host.AddScriptLPS(1);
  2794. if (m_SoundModule == null)
  2795. return;
  2796. UUID soundID = ScriptUtils.GetAssetIdFromKeyOrItemName(m_host, sound, AssetType.Sound);
  2797. if(soundID == UUID.Zero)
  2798. return;
  2799. m_SoundModule.PreloadSound(m_host.UUID, soundID);
  2800. ScriptSleep(m_sleepMsOnPreloadSound);
  2801. }
  2802. /// <summary>
  2803. /// Return a portion of the designated string bounded by
  2804. /// inclusive indices (start and end). As usual, the negative
  2805. /// indices, and the tolerance for out-of-bound values, makes
  2806. /// this more complicated than it might otherwise seem.
  2807. /// </summary>
  2808. public LSL_String llGetSubString(string src, int start, int end)
  2809. {
  2810. m_host.AddScriptLPS(1);
  2811. // Normalize indices (if negative).
  2812. // After normlaization they may still be
  2813. // negative, but that is now relative to
  2814. // the start, rather than the end, of the
  2815. // sequence.
  2816. if (start < 0)
  2817. {
  2818. start = src.Length+start;
  2819. }
  2820. if (end < 0)
  2821. {
  2822. end = src.Length+end;
  2823. }
  2824. // Conventional substring
  2825. if (start <= end)
  2826. {
  2827. // Implies both bounds are out-of-range.
  2828. if (end < 0 || start >= src.Length)
  2829. {
  2830. return String.Empty;
  2831. }
  2832. // If end is positive, then it directly
  2833. // corresponds to the lengt of the substring
  2834. // needed (plus one of course). BUT, it
  2835. // must be within bounds.
  2836. if (end >= src.Length)
  2837. {
  2838. end = src.Length-1;
  2839. }
  2840. if (start < 0)
  2841. {
  2842. return src.Substring(0,end+1);
  2843. }
  2844. // Both indices are positive
  2845. return src.Substring(start, (end+1) - start);
  2846. }
  2847. // Inverted substring (end < start)
  2848. else
  2849. {
  2850. // Implies both indices are below the
  2851. // lower bound. In the inverted case, that
  2852. // means the entire string will be returned
  2853. // unchanged.
  2854. if (start < 0)
  2855. {
  2856. return src;
  2857. }
  2858. // If both indices are greater than the upper
  2859. // bound the result may seem initially counter
  2860. // intuitive.
  2861. if (end >= src.Length)
  2862. {
  2863. return src;
  2864. }
  2865. if (end < 0)
  2866. {
  2867. if (start < src.Length)
  2868. {
  2869. return src.Substring(start);
  2870. }
  2871. else
  2872. {
  2873. return String.Empty;
  2874. }
  2875. }
  2876. else
  2877. {
  2878. if (start < src.Length)
  2879. {
  2880. return src.Substring(0,end+1) + src.Substring(start);
  2881. }
  2882. else
  2883. {
  2884. return src.Substring(0,end+1);
  2885. }
  2886. }
  2887. }
  2888. }
  2889. /// <summary>
  2890. /// Delete substring removes the specified substring bounded
  2891. /// by the inclusive indices start and end. Indices may be
  2892. /// negative (indicating end-relative) and may be inverted,
  2893. /// i.e. end < start.
  2894. /// </summary>
  2895. public LSL_String llDeleteSubString(string src, int start, int end)
  2896. {
  2897. m_host.AddScriptLPS(1);
  2898. // Normalize indices (if negative).
  2899. // After normlaization they may still be
  2900. // negative, but that is now relative to
  2901. // the start, rather than the end, of the
  2902. // sequence.
  2903. if (start < 0)
  2904. {
  2905. start = src.Length+start;
  2906. }
  2907. if (end < 0)
  2908. {
  2909. end = src.Length+end;
  2910. }
  2911. // Conventionally delimited substring
  2912. if (start <= end)
  2913. {
  2914. // If both bounds are outside of the existing
  2915. // string, then return unchanges.
  2916. if (end < 0 || start >= src.Length)
  2917. {
  2918. return src;
  2919. }
  2920. // At least one bound is in-range, so we
  2921. // need to clip the out-of-bound argument.
  2922. if (start < 0)
  2923. {
  2924. start = 0;
  2925. }
  2926. if (end >= src.Length)
  2927. {
  2928. end = src.Length-1;
  2929. }
  2930. return src.Remove(start,end-start+1);
  2931. }
  2932. // Inverted substring
  2933. else
  2934. {
  2935. // In this case, out of bounds means that
  2936. // the existing string is part of the cut.
  2937. if (start < 0 || end >= src.Length)
  2938. {
  2939. return String.Empty;
  2940. }
  2941. if (end > 0)
  2942. {
  2943. if (start < src.Length)
  2944. {
  2945. return src.Remove(start).Remove(0,end+1);
  2946. }
  2947. else
  2948. {
  2949. return src.Remove(0,end+1);
  2950. }
  2951. }
  2952. else
  2953. {
  2954. if (start < src.Length)
  2955. {
  2956. return src.Remove(start);
  2957. }
  2958. else
  2959. {
  2960. return src;
  2961. }
  2962. }
  2963. }
  2964. }
  2965. /// <summary>
  2966. /// Insert string inserts the specified string identified by src
  2967. /// at the index indicated by index. Index may be negative, in
  2968. /// which case it is end-relative. The index may exceed either
  2969. /// string bound, with the result being a concatenation.
  2970. /// </summary>
  2971. public LSL_String llInsertString(string dest, int index, string src)
  2972. {
  2973. m_host.AddScriptLPS(1);
  2974. // Normalize indices (if negative).
  2975. // After normlaization they may still be
  2976. // negative, but that is now relative to
  2977. // the start, rather than the end, of the
  2978. // sequence.
  2979. if (index < 0)
  2980. {
  2981. index = dest.Length+index;
  2982. // Negative now means it is less than the lower
  2983. // bound of the string.
  2984. if (index < 0)
  2985. {
  2986. return src+dest;
  2987. }
  2988. }
  2989. if (index >= dest.Length)
  2990. {
  2991. return dest+src;
  2992. }
  2993. // The index is in bounds.
  2994. // In this case the index refers to the index that will
  2995. // be assigned to the first character of the inserted string.
  2996. // So unlike the other string operations, we do not add one
  2997. // to get the correct string length.
  2998. return dest.Substring(0,index)+src+dest.Substring(index);
  2999. }
  3000. public LSL_String llToUpper(string src)
  3001. {
  3002. m_host.AddScriptLPS(1);
  3003. return src.ToUpper();
  3004. }
  3005. public LSL_String llToLower(string src)
  3006. {
  3007. m_host.AddScriptLPS(1);
  3008. return src.ToLower();
  3009. }
  3010. public LSL_Integer llGiveMoney(string destination, int amount)
  3011. {
  3012. Util.FireAndForget(x =>
  3013. {
  3014. m_host.AddScriptLPS(1);
  3015. if (m_item.PermsGranter == UUID.Zero)
  3016. return;
  3017. if ((m_item.PermsMask & ScriptBaseClass.PERMISSION_DEBIT) == 0)
  3018. {
  3019. Error("llGiveMoney", "No permissions to give money");
  3020. return;
  3021. }
  3022. UUID toID = new UUID();
  3023. if (!UUID.TryParse(destination, out toID))
  3024. {
  3025. Error("llGiveMoney", "Bad key in llGiveMoney");
  3026. return;
  3027. }
  3028. IMoneyModule money = World.RequestModuleInterface<IMoneyModule>();
  3029. if (money == null)
  3030. {
  3031. NotImplemented("llGiveMoney");
  3032. return;
  3033. }
  3034. string reason;
  3035. money.ObjectGiveMoney(
  3036. m_host.ParentGroup.RootPart.UUID, m_host.ParentGroup.RootPart.OwnerID, toID, amount,UUID.Zero, out reason);
  3037. }, null, "LSL_Api.llGiveMoney");
  3038. return 0;
  3039. }
  3040. public void llMakeExplosion(int particles, double scale, double vel, double lifetime, double arc, string texture, LSL_Vector offset)
  3041. {
  3042. m_host.AddScriptLPS(1);
  3043. Deprecated("llMakeExplosion", "Use llParticleSystem instead");
  3044. ScriptSleep(m_sleepMsOnMakeExplosion);
  3045. }
  3046. public void llMakeFountain(int particles, double scale, double vel, double lifetime, double arc, int bounce, string texture, LSL_Vector offset, double bounce_offset)
  3047. {
  3048. m_host.AddScriptLPS(1);
  3049. Deprecated("llMakeFountain", "Use llParticleSystem instead");
  3050. ScriptSleep(m_sleepMsOnMakeFountain);
  3051. }
  3052. public void llMakeSmoke(int particles, double scale, double vel, double lifetime, double arc, string texture, LSL_Vector offset)
  3053. {
  3054. m_host.AddScriptLPS(1);
  3055. Deprecated("llMakeSmoke", "Use llParticleSystem instead");
  3056. ScriptSleep(m_sleepMsOnMakeSmoke);
  3057. }
  3058. public void llMakeFire(int particles, double scale, double vel, double lifetime, double arc, string texture, LSL_Vector offset)
  3059. {
  3060. m_host.AddScriptLPS(1);
  3061. Deprecated("llMakeFire", "Use llParticleSystem instead");
  3062. ScriptSleep(m_sleepMsOnMakeFire);
  3063. }
  3064. public void llRezAtRoot(string inventory, LSL_Vector pos, LSL_Vector vel, LSL_Rotation rot, int param)
  3065. {
  3066. doObjectRez(inventory, pos, vel, rot, param, true);
  3067. }
  3068. public void doObjectRez(string inventory, LSL_Vector pos, LSL_Vector vel, LSL_Rotation rot, int param, bool atRoot)
  3069. {
  3070. m_host.AddScriptLPS(1);
  3071. if (Double.IsNaN(rot.x) || Double.IsNaN(rot.y) || Double.IsNaN(rot.z) || Double.IsNaN(rot.s))
  3072. return;
  3073. float dist = (float)llVecDist(llGetPos(), pos);
  3074. if (dist > m_ScriptDistanceFactor * 10.0f)
  3075. return;
  3076. TaskInventoryItem item = m_host.Inventory.GetInventoryItem(inventory);
  3077. if (item == null)
  3078. {
  3079. Error("llRez(AtRoot/Object)", "Can't find object '" + inventory + "'");
  3080. return;
  3081. }
  3082. if (item.InvType != (int)InventoryType.Object)
  3083. {
  3084. Error("llRez(AtRoot/Object)", "Can't create requested object; object is missing from database");
  3085. return;
  3086. }
  3087. Util.FireAndForget(x =>
  3088. {
  3089. Quaternion wrot = rot;
  3090. wrot.Normalize();
  3091. List<SceneObjectGroup> new_groups = World.RezObject(m_host, item, pos, wrot, vel, param, atRoot);
  3092. // If either of these are null, then there was an unknown error.
  3093. if (new_groups == null)
  3094. return;
  3095. bool notAttachment = !m_host.ParentGroup.IsAttachment;
  3096. foreach (SceneObjectGroup group in new_groups)
  3097. {
  3098. // objects rezzed with this method are die_at_edge by default.
  3099. group.RootPart.SetDieAtEdge(true);
  3100. group.ResumeScripts();
  3101. m_ScriptEngine.PostObjectEvent(m_host.LocalId, new EventParams(
  3102. "object_rez", new Object[] {
  3103. new LSL_String(
  3104. group.RootPart.UUID.ToString()) },
  3105. new DetectParams[0]));
  3106. if (notAttachment)
  3107. {
  3108. float groupmass = group.GetMass();
  3109. PhysicsActor pa = group.RootPart.PhysActor;
  3110. //Recoil.
  3111. if (pa != null && pa.IsPhysical && (Vector3)vel != Vector3.Zero)
  3112. {
  3113. Vector3 recoil = -vel * groupmass * m_recoilScaleFactor;
  3114. if (recoil != Vector3.Zero)
  3115. {
  3116. llApplyImpulse(recoil, 0);
  3117. }
  3118. }
  3119. }
  3120. }
  3121. }, null, "LSL_Api.doObjectRez");
  3122. //ScriptSleep((int)((groupmass * velmag) / 10));
  3123. ScriptSleep(m_sleepMsOnRezAtRoot);
  3124. }
  3125. public void llRezObject(string inventory, LSL_Vector pos, LSL_Vector vel, LSL_Rotation rot, int param)
  3126. {
  3127. doObjectRez(inventory, pos, vel, rot, param, false);
  3128. }
  3129. public void llLookAt(LSL_Vector target, double strength, double damping)
  3130. {
  3131. m_host.AddScriptLPS(1);
  3132. // Get the normalized vector to the target
  3133. LSL_Vector from = llGetPos();
  3134. // normalized direction to target
  3135. LSL_Vector dir = llVecNorm(target - from);
  3136. // use vertical to help compute left axis
  3137. // LSL_Vector up = new LSL_Vector(0.0, 0.0, 1.0);
  3138. // find normalized left axis parallel to horizon
  3139. // LSL_Vector left = llVecNorm(LSL_Vector.Cross(up, dir));
  3140. LSL_Vector left = new LSL_Vector(-dir.y, dir.x, 0.0f);
  3141. left = llVecNorm(left);
  3142. // make up orthogonal to left and dir
  3143. LSL_Vector up = LSL_Vector.Cross(dir, left);
  3144. // compute rotation based on orthogonal axes
  3145. // and rotate so Z points to target with X below horizont
  3146. LSL_Rotation rot = new LSL_Rotation(0.0, 0.707107, 0.0, 0.707107) * llAxes2Rot(dir, left, up);
  3147. SceneObjectGroup sog = m_host.ParentGroup;
  3148. if(sog == null || sog.IsDeleted)
  3149. return;
  3150. if (!sog.UsesPhysics || sog.IsAttachment)
  3151. {
  3152. // Do nothing if either value is 0 (this has been checked in SL)
  3153. if (strength <= 0.0 || damping <= 0.0)
  3154. return;
  3155. llSetLocalRot(rot);
  3156. }
  3157. else
  3158. {
  3159. if (strength == 0)
  3160. {
  3161. llSetLocalRot(rot);
  3162. return;
  3163. }
  3164. sog.StartLookAt(rot, (float)strength, (float)damping);
  3165. }
  3166. }
  3167. public void llStopLookAt()
  3168. {
  3169. m_host.AddScriptLPS(1);
  3170. m_host.StopLookAt();
  3171. }
  3172. public void llSetTimerEvent(double sec)
  3173. {
  3174. if (sec != 0.0 && sec < m_MinTimerInterval)
  3175. sec = m_MinTimerInterval;
  3176. m_host.AddScriptLPS(1);
  3177. // Setting timer repeat
  3178. AsyncCommands.TimerPlugin.SetTimerEvent(m_host.LocalId, m_item.ItemID, sec);
  3179. }
  3180. public virtual void llSleep(double sec)
  3181. {
  3182. // m_log.Info("llSleep snoozing " + sec + "s.");
  3183. m_host.AddScriptLPS(1);
  3184. Sleep((int)(sec * 1000));
  3185. }
  3186. public LSL_Float llGetMass()
  3187. {
  3188. m_host.AddScriptLPS(1);
  3189. if (m_host.ParentGroup.IsAttachment)
  3190. {
  3191. ScenePresence attachedAvatar = World.GetScenePresence(m_host.ParentGroup.AttachedAvatar);
  3192. if (attachedAvatar != null)
  3193. {
  3194. return attachedAvatar.GetMass();
  3195. }
  3196. else
  3197. {
  3198. return 0;
  3199. }
  3200. }
  3201. else
  3202. {
  3203. // new SL always returns object mass
  3204. // if (m_host.IsRoot)
  3205. // {
  3206. return m_host.ParentGroup.GetMass();
  3207. // }
  3208. // else
  3209. // {
  3210. // return m_host.GetMass();
  3211. // }
  3212. }
  3213. }
  3214. public LSL_Float llGetMassMKS()
  3215. {
  3216. return 100f * llGetMass();
  3217. }
  3218. public void llCollisionFilter(string name, string id, int accept)
  3219. {
  3220. m_host.AddScriptLPS(1);
  3221. m_host.CollisionFilter.Clear();
  3222. UUID objectID;
  3223. if (!UUID.TryParse(id, out objectID))
  3224. objectID = UUID.Zero;
  3225. if (objectID == UUID.Zero && name == "")
  3226. return;
  3227. m_host.CollisionFilter.Add(accept,objectID.ToString() + name);
  3228. }
  3229. public void llTakeControls(int controls, int accept, int pass_on)
  3230. {
  3231. if (m_item.PermsGranter != UUID.Zero)
  3232. {
  3233. ScenePresence presence = World.GetScenePresence(m_item.PermsGranter);
  3234. if (presence != null)
  3235. {
  3236. if ((m_item.PermsMask & ScriptBaseClass.PERMISSION_TAKE_CONTROLS) != 0)
  3237. {
  3238. presence.RegisterControlEventsToScript(controls, accept, pass_on, m_host.LocalId, m_item.ItemID);
  3239. }
  3240. }
  3241. }
  3242. m_host.AddScriptLPS(1);
  3243. }
  3244. public void llReleaseControls()
  3245. {
  3246. m_host.AddScriptLPS(1);
  3247. if (m_item.PermsGranter != UUID.Zero)
  3248. {
  3249. ScenePresence presence = World.GetScenePresence(m_item.PermsGranter);
  3250. if (presence != null)
  3251. {
  3252. if ((m_item.PermsMask & ScriptBaseClass.PERMISSION_TAKE_CONTROLS) != 0)
  3253. {
  3254. // Unregister controls from Presence
  3255. presence.UnRegisterControlEventsToScript(m_host.LocalId, m_item.ItemID);
  3256. // Remove Take Control permission.
  3257. m_item.PermsMask &= ~ScriptBaseClass.PERMISSION_TAKE_CONTROLS;
  3258. }
  3259. }
  3260. }
  3261. }
  3262. public void llReleaseURL(string url)
  3263. {
  3264. m_host.AddScriptLPS(1);
  3265. if (m_UrlModule != null)
  3266. m_UrlModule.ReleaseURL(url);
  3267. }
  3268. /// <summary>
  3269. /// Attach the object containing this script to the avatar that owns it.
  3270. /// </summary>
  3271. /// <param name='attachmentPoint'>
  3272. /// The attachment point (e.g. <see cref="OpenSim.Region.ScriptEngine.Shared.ScriptBase.ScriptBaseClass.ATTACH_CHEST">ATTACH_CHEST</see>)
  3273. /// </param>
  3274. /// <returns>true if the attach suceeded, false if it did not</returns>
  3275. public bool AttachToAvatar(int attachmentPoint)
  3276. {
  3277. SceneObjectGroup grp = m_host.ParentGroup;
  3278. ScenePresence presence = World.GetScenePresence(m_host.OwnerID);
  3279. IAttachmentsModule attachmentsModule = m_ScriptEngine.World.AttachmentsModule;
  3280. if (attachmentsModule != null)
  3281. return attachmentsModule.AttachObject(presence, grp, (uint)attachmentPoint, false, true, true);
  3282. else
  3283. return false;
  3284. }
  3285. /// <summary>
  3286. /// Detach the object containing this script from the avatar it is attached to.
  3287. /// </summary>
  3288. /// <remarks>
  3289. /// Nothing happens if the object is not attached.
  3290. /// </remarks>
  3291. public void DetachFromAvatar()
  3292. {
  3293. Util.FireAndForget(DetachWrapper, m_host, "LSL_Api.DetachFromAvatar");
  3294. }
  3295. private void DetachWrapper(object o)
  3296. {
  3297. if (World.AttachmentsModule != null)
  3298. {
  3299. SceneObjectPart host = (SceneObjectPart)o;
  3300. ScenePresence presence = World.GetScenePresence(host.OwnerID);
  3301. World.AttachmentsModule.DetachSingleAttachmentToInv(presence, host.ParentGroup);
  3302. }
  3303. }
  3304. public void llAttachToAvatar(LSL_Integer attachmentPoint)
  3305. {
  3306. m_host.AddScriptLPS(1);
  3307. if (m_item.PermsGranter != m_host.OwnerID)
  3308. return;
  3309. if ((m_item.PermsMask & ScriptBaseClass.PERMISSION_ATTACH) != 0)
  3310. AttachToAvatar(attachmentPoint);
  3311. }
  3312. public void llAttachToAvatarTemp(LSL_Integer attachmentPoint)
  3313. {
  3314. IAttachmentsModule attachmentsModule = World.RequestModuleInterface<IAttachmentsModule>();
  3315. if (attachmentsModule == null)
  3316. return;
  3317. if ((m_item.PermsMask & ScriptBaseClass.PERMISSION_ATTACH) == 0)
  3318. return;
  3319. SceneObjectGroup grp = m_host.ParentGroup;
  3320. if (grp == null || grp.IsDeleted || grp.IsAttachment)
  3321. return;
  3322. ScenePresence target;
  3323. if (!World.TryGetScenePresence(m_item.PermsGranter, out target))
  3324. return;
  3325. if (target.UUID != grp.OwnerID)
  3326. {
  3327. uint effectivePerms = grp.EffectiveOwnerPerms;
  3328. if ((effectivePerms & (uint)PermissionMask.Transfer) == 0)
  3329. return;
  3330. grp.SetOwner(target.UUID, target.ControllingClient.ActiveGroupId);
  3331. if (World.Permissions.PropagatePermissions())
  3332. {
  3333. foreach (SceneObjectPart child in grp.Parts)
  3334. {
  3335. child.Inventory.ChangeInventoryOwner(target.UUID);
  3336. child.TriggerScriptChangedEvent(Changed.OWNER);
  3337. child.ApplyNextOwnerPermissions();
  3338. }
  3339. grp.InvalidateEffectivePerms();
  3340. }
  3341. grp.RootPart.ObjectSaleType = 0;
  3342. grp.RootPart.SalePrice = 10;
  3343. grp.HasGroupChanged = true;
  3344. grp.RootPart.SendPropertiesToClient(target.ControllingClient);
  3345. grp.RootPart.ScheduleFullUpdate();
  3346. }
  3347. attachmentsModule.AttachObject(target, grp, (uint)attachmentPoint, false, false, true);
  3348. }
  3349. public void llDetachFromAvatar()
  3350. {
  3351. m_host.AddScriptLPS(1);
  3352. if (m_host.ParentGroup.AttachmentPoint == 0)
  3353. return;
  3354. if (m_item.PermsGranter != m_host.OwnerID)
  3355. return;
  3356. if ((m_item.PermsMask & ScriptBaseClass.PERMISSION_ATTACH) != 0)
  3357. DetachFromAvatar();
  3358. }
  3359. public void llTakeCamera(string avatar)
  3360. {
  3361. m_host.AddScriptLPS(1);
  3362. Deprecated("llTakeCamera", "Use llSetCameraParams instead");
  3363. }
  3364. public void llReleaseCamera(string avatar)
  3365. {
  3366. m_host.AddScriptLPS(1);
  3367. Deprecated("llReleaseCamera", "Use llClearCameraParams instead");
  3368. }
  3369. public LSL_Key llGetOwner()
  3370. {
  3371. m_host.AddScriptLPS(1);
  3372. return m_host.OwnerID.ToString();
  3373. }
  3374. public void llInstantMessage(string user, string message)
  3375. {
  3376. m_host.AddScriptLPS(1);
  3377. UUID result;
  3378. if (!UUID.TryParse(user, out result) || result == UUID.Zero)
  3379. {
  3380. Error("llInstantMessage","An invalid key was passed to llInstantMessage");
  3381. ScriptSleep(2000);
  3382. return;
  3383. }
  3384. // We may be able to use ClientView.SendInstantMessage here, but we need a client instance.
  3385. // InstantMessageModule.OnInstantMessage searches through a list of scenes for a client matching the toAgent,
  3386. // but I don't think we have a list of scenes available from here.
  3387. // (We also don't want to duplicate the code in OnInstantMessage if we can avoid it.)
  3388. // user is a UUID
  3389. // TODO: figure out values for client, fromSession, and imSessionID
  3390. // client.SendInstantMessage(m_host.UUID, fromSession, message, user, imSessionID, m_host.Name, AgentManager.InstantMessageDialog.MessageFromAgent, (uint)Util.UnixTimeSinceEpoch());
  3391. UUID friendTransactionID = UUID.Random();
  3392. //m_pendingFriendRequests.Add(friendTransactionID, fromAgentID);
  3393. GridInstantMessage msg = new GridInstantMessage();
  3394. msg.fromAgentID = new Guid(m_host.OwnerID.ToString()); // fromAgentID.Guid;
  3395. msg.toAgentID = new Guid(user); // toAgentID.Guid;
  3396. msg.imSessionID = new Guid(m_host.UUID.ToString()); // This is the item we're mucking with here
  3397. msg.timestamp = (uint)Util.UnixTimeSinceEpoch();
  3398. msg.fromAgentName = m_host.Name;//client.FirstName + " " + client.LastName;// fromAgentName;
  3399. if (message != null && message.Length > 1024)
  3400. msg.message = message.Substring(0, 1024);
  3401. else
  3402. msg.message = message;
  3403. msg.dialog = (byte)19; // MessageFromObject
  3404. msg.fromGroup = false;// fromGroup;
  3405. msg.offline = (byte)0; //offline;
  3406. msg.ParentEstateID = World.RegionInfo.EstateSettings.EstateID;
  3407. msg.Position = new Vector3(m_host.AbsolutePosition);
  3408. msg.RegionID = World.RegionInfo.RegionID.Guid;//RegionID.Guid;
  3409. Vector3 pos = m_host.AbsolutePosition;
  3410. msg.binaryBucket
  3411. = Util.StringToBytes256(
  3412. "{0}/{1}/{2}/{3}",
  3413. World.RegionInfo.RegionName,
  3414. (int)Math.Floor(pos.X),
  3415. (int)Math.Floor(pos.Y),
  3416. (int)Math.Floor(pos.Z));
  3417. if (m_TransferModule != null)
  3418. {
  3419. m_TransferModule.SendInstantMessage(msg, delegate(bool success) {});
  3420. }
  3421. ScriptSleep(m_sleepMsOnInstantMessage);
  3422. }
  3423. public void llEmail(string address, string subject, string message)
  3424. {
  3425. m_host.AddScriptLPS(1);
  3426. IEmailModule emailModule = m_ScriptEngine.World.RequestModuleInterface<IEmailModule>();
  3427. if (emailModule == null)
  3428. {
  3429. Error("llEmail", "Email module not configured");
  3430. return;
  3431. }
  3432. //Restrict email destination to the avatars registered email address?
  3433. //The restriction only applies if the destination address is not local.
  3434. if (m_restrictEmail == true && address.Contains(m_internalObjectHost) == false)
  3435. {
  3436. UserAccount account =
  3437. World.UserAccountService.GetUserAccount(
  3438. World.RegionInfo.ScopeID,
  3439. m_host.OwnerID);
  3440. if (account == null)
  3441. {
  3442. Error("llEmail", "Can't find user account for '" + m_host.OwnerID.ToString() + "'");
  3443. return;
  3444. }
  3445. if (String.IsNullOrEmpty(account.Email))
  3446. {
  3447. Error("llEmail", "User account has not registered an email address.");
  3448. return;
  3449. }
  3450. address = account.Email;
  3451. }
  3452. emailModule.SendEmail(m_host.UUID, address, subject, message);
  3453. ScriptSleep(m_sleepMsOnEmail);
  3454. }
  3455. public void llGetNextEmail(string address, string subject)
  3456. {
  3457. m_host.AddScriptLPS(1);
  3458. IEmailModule emailModule = m_ScriptEngine.World.RequestModuleInterface<IEmailModule>();
  3459. if (emailModule == null)
  3460. {
  3461. Error("llGetNextEmail", "Email module not configured");
  3462. return;
  3463. }
  3464. Email email;
  3465. email = emailModule.GetNextEmail(m_host.UUID, address, subject);
  3466. if (email == null)
  3467. return;
  3468. m_ScriptEngine.PostObjectEvent(m_host.LocalId,
  3469. new EventParams("email",
  3470. new Object[] {
  3471. new LSL_String(email.time),
  3472. new LSL_String(email.sender),
  3473. new LSL_String(email.subject),
  3474. new LSL_String(email.message),
  3475. new LSL_Integer(email.numLeft)},
  3476. new DetectParams[0]));
  3477. }
  3478. public LSL_Key llGetKey()
  3479. {
  3480. m_host.AddScriptLPS(1);
  3481. return m_host.UUID.ToString();
  3482. }
  3483. public LSL_Key llGenerateKey()
  3484. {
  3485. m_host.AddScriptLPS(1);
  3486. return UUID.Random().ToString();
  3487. }
  3488. public void llSetBuoyancy(double buoyancy)
  3489. {
  3490. m_host.AddScriptLPS(1);
  3491. if (!m_host.ParentGroup.IsDeleted)
  3492. {
  3493. m_host.ParentGroup.RootPart.SetBuoyancy((float)buoyancy);
  3494. }
  3495. }
  3496. /// <summary>
  3497. /// Attempt to clamp the object on the Z axis at the given height over tau seconds.
  3498. /// </summary>
  3499. /// <param name="height">Height to hover. Height of zero disables hover.</param>
  3500. /// <param name="water">False if height is calculated just from ground, otherwise uses ground or water depending on whichever is higher</param>
  3501. /// <param name="tau">Number of seconds over which to reach target</param>
  3502. public void llSetHoverHeight(double height, int water, double tau)
  3503. {
  3504. m_host.AddScriptLPS(1);
  3505. PIDHoverType hoverType = PIDHoverType.Ground;
  3506. if (water != 0)
  3507. {
  3508. hoverType = PIDHoverType.GroundAndWater;
  3509. }
  3510. m_host.SetHoverHeight((float)height, hoverType, (float)tau);
  3511. }
  3512. public void llStopHover()
  3513. {
  3514. m_host.AddScriptLPS(1);
  3515. m_host.SetHoverHeight(0f, PIDHoverType.Ground, 0f);
  3516. }
  3517. public void llMinEventDelay(double delay)
  3518. {
  3519. m_host.AddScriptLPS(1);
  3520. try
  3521. {
  3522. m_ScriptEngine.SetMinEventDelay(m_item.ItemID, delay);
  3523. }
  3524. catch (NotImplementedException)
  3525. {
  3526. // Currently not implemented in DotNetEngine only XEngine
  3527. NotImplemented("llMinEventDelay", "In DotNetEngine");
  3528. }
  3529. }
  3530. public void llSoundPreload(string sound)
  3531. {
  3532. m_host.AddScriptLPS(1);
  3533. Deprecated("llSoundPreload", "Use llPreloadSound instead");
  3534. }
  3535. public void llRotLookAt(LSL_Rotation target, double strength, double damping)
  3536. {
  3537. m_host.AddScriptLPS(1);
  3538. // Per discussion with Melanie, for non-physical objects llLookAt appears to simply
  3539. // set the rotation of the object, copy that behavior
  3540. SceneObjectGroup sog = m_host.ParentGroup;
  3541. if(sog == null || sog.IsDeleted)
  3542. return;
  3543. if (strength == 0 || !sog.UsesPhysics || sog.IsAttachment)
  3544. {
  3545. llSetLocalRot(target);
  3546. }
  3547. else
  3548. {
  3549. sog.RotLookAt(target, (float)strength, (float)damping);
  3550. }
  3551. }
  3552. public LSL_Integer llStringLength(string str)
  3553. {
  3554. m_host.AddScriptLPS(1);
  3555. if (str.Length > 0)
  3556. {
  3557. return str.Length;
  3558. }
  3559. else
  3560. {
  3561. return 0;
  3562. }
  3563. }
  3564. public void llStartAnimation(string anim)
  3565. {
  3566. m_host.AddScriptLPS(1);
  3567. if (m_item.PermsGranter == UUID.Zero)
  3568. return;
  3569. if ((m_item.PermsMask & ScriptBaseClass.PERMISSION_TRIGGER_ANIMATION) != 0)
  3570. {
  3571. ScenePresence presence = World.GetScenePresence(m_item.PermsGranter);
  3572. if (presence != null)
  3573. {
  3574. // Do NOT try to parse UUID, animations cannot be triggered by ID
  3575. UUID animID = ScriptUtils.GetAssetIdFromItemName(m_host, anim, (int)AssetType.Animation);
  3576. if (animID == UUID.Zero)
  3577. presence.Animator.AddAnimation(anim, m_host.UUID);
  3578. else
  3579. presence.Animator.AddAnimation(animID, m_host.UUID);
  3580. }
  3581. }
  3582. }
  3583. public void llStopAnimation(string anim)
  3584. {
  3585. m_host.AddScriptLPS(1);
  3586. if (m_item.PermsGranter == UUID.Zero)
  3587. return;
  3588. if ((m_item.PermsMask & ScriptBaseClass.PERMISSION_TRIGGER_ANIMATION) != 0)
  3589. {
  3590. ScenePresence presence = World.GetScenePresence(m_item.PermsGranter);
  3591. if (presence != null)
  3592. {
  3593. UUID animID = ScriptUtils.GetAssetIdFromKeyOrItemName(m_host, anim);
  3594. if (animID == UUID.Zero)
  3595. presence.Animator.RemoveAnimation(anim);
  3596. else
  3597. presence.Animator.RemoveAnimation(animID, true);
  3598. }
  3599. }
  3600. }
  3601. public void llStartObjectAnimation(string anim)
  3602. {
  3603. m_host.AddScriptLPS(1);
  3604. // Do NOT try to parse UUID, animations cannot be triggered by ID
  3605. UUID animID = ScriptUtils.GetAssetIdFromItemName(m_host, anim, (int)AssetType.Animation);
  3606. if (animID == UUID.Zero)
  3607. return;
  3608. m_host.AddAnimation(animID, anim);
  3609. }
  3610. public void llStopObjectAnimation(string anim)
  3611. {
  3612. m_host.AddScriptLPS(1);
  3613. UUID animID = ScriptUtils.GetAssetIdFromKeyOrItemName(m_host, anim, AssetType.Animation);
  3614. if (animID != UUID.Zero)
  3615. m_host.RemoveAnimation(animID);
  3616. }
  3617. public LSL_List llGetObjectAnimationNames()
  3618. {
  3619. m_host.AddScriptLPS(1);
  3620. LSL_List ret = new LSL_List();
  3621. if(m_host.AnimationsNames == null || m_host.AnimationsNames.Count == 0)
  3622. return ret;
  3623. foreach (string name in m_host.AnimationsNames.Values)
  3624. ret.Add(new LSL_String(name));
  3625. return ret;
  3626. }
  3627. public void llPointAt(LSL_Vector pos)
  3628. {
  3629. m_host.AddScriptLPS(1);
  3630. }
  3631. public void llStopPointAt()
  3632. {
  3633. m_host.AddScriptLPS(1);
  3634. }
  3635. public void llTargetOmega(LSL_Vector axis, double spinrate, double gain)
  3636. {
  3637. m_host.AddScriptLPS(1);
  3638. TargetOmega(m_host, axis, spinrate, gain);
  3639. }
  3640. protected void TargetOmega(SceneObjectPart part, LSL_Vector axis, double spinrate, double gain)
  3641. {
  3642. PhysicsActor pa = part.PhysActor;
  3643. if ( ( pa == null || !pa.IsPhysical ) && gain == 0.0d )
  3644. spinrate = 0.0d;
  3645. part.UpdateAngularVelocity(axis * spinrate);
  3646. }
  3647. public LSL_Integer llGetStartParameter()
  3648. {
  3649. m_host.AddScriptLPS(1);
  3650. return m_ScriptEngine.GetStartParameter(m_item.ItemID);
  3651. }
  3652. public void llRequestPermissions(string agent, int perm)
  3653. {
  3654. UUID agentID;
  3655. if (!UUID.TryParse(agent, out agentID))
  3656. return;
  3657. if (agentID == UUID.Zero || perm == 0) // Releasing permissions
  3658. {
  3659. llReleaseControls();
  3660. m_item.PermsGranter = UUID.Zero;
  3661. m_item.PermsMask = 0;
  3662. m_ScriptEngine.PostScriptEvent(m_item.ItemID, new EventParams(
  3663. "run_time_permissions", new Object[] {
  3664. new LSL_Integer(0) },
  3665. new DetectParams[0]));
  3666. return;
  3667. }
  3668. if (m_item.PermsGranter != agentID || (perm & ScriptBaseClass.PERMISSION_TAKE_CONTROLS) == 0)
  3669. llReleaseControls();
  3670. m_host.AddScriptLPS(1);
  3671. int implicitPerms = 0;
  3672. if (m_host.ParentGroup.IsAttachment && (UUID)agent == m_host.ParentGroup.AttachedAvatar)
  3673. {
  3674. // When attached, certain permissions are implicit if requested from owner
  3675. implicitPerms = ScriptBaseClass.PERMISSION_TAKE_CONTROLS |
  3676. ScriptBaseClass.PERMISSION_TRIGGER_ANIMATION |
  3677. ScriptBaseClass.PERMISSION_CONTROL_CAMERA |
  3678. ScriptBaseClass.PERMISSION_TRACK_CAMERA |
  3679. ScriptBaseClass.PERMISSION_ATTACH |
  3680. ScriptBaseClass.PERMISSION_OVERRIDE_ANIMATIONS;
  3681. }
  3682. else
  3683. {
  3684. if (m_host.ParentGroup.GetSittingAvatars().SingleOrDefault(sp => sp.UUID == agentID) != null)
  3685. {
  3686. // When agent is sitting, certain permissions are implicit if requested from sitting agent
  3687. implicitPerms = ScriptBaseClass.PERMISSION_TRIGGER_ANIMATION |
  3688. ScriptBaseClass.PERMISSION_CONTROL_CAMERA |
  3689. ScriptBaseClass.PERMISSION_TRACK_CAMERA |
  3690. ScriptBaseClass.PERMISSION_TAKE_CONTROLS;
  3691. }
  3692. else
  3693. {
  3694. if (World.GetExtraSetting("auto_grant_attach_perms") == "true")
  3695. implicitPerms = ScriptBaseClass.PERMISSION_ATTACH;
  3696. }
  3697. if (World.GetExtraSetting("auto_grant_all_perms") == "true")
  3698. {
  3699. implicitPerms = perm;
  3700. }
  3701. }
  3702. if ((perm & (~implicitPerms)) == 0) // Requested only implicit perms
  3703. {
  3704. m_host.TaskInventory.LockItemsForWrite(true);
  3705. m_host.TaskInventory[m_item.ItemID].PermsGranter = agentID;
  3706. m_host.TaskInventory[m_item.ItemID].PermsMask = perm;
  3707. m_host.TaskInventory.LockItemsForWrite(false);
  3708. m_ScriptEngine.PostScriptEvent(m_item.ItemID, new EventParams(
  3709. "run_time_permissions", new Object[] {
  3710. new LSL_Integer(perm) },
  3711. new DetectParams[0]));
  3712. return;
  3713. }
  3714. ScenePresence presence = World.GetScenePresence(agentID);
  3715. if (presence != null)
  3716. {
  3717. // If permissions are being requested from an NPC and were not implicitly granted above then
  3718. // auto grant all requested permissions if the script is owned by the NPC or the NPCs owner
  3719. INPCModule npcModule = World.RequestModuleInterface<INPCModule>();
  3720. if (npcModule != null && npcModule.IsNPC(agentID, World))
  3721. {
  3722. if (npcModule.CheckPermissions(agentID, m_host.OwnerID))
  3723. {
  3724. lock (m_host.TaskInventory)
  3725. {
  3726. m_host.TaskInventory[m_item.ItemID].PermsGranter = agentID;
  3727. m_host.TaskInventory[m_item.ItemID].PermsMask = perm;
  3728. }
  3729. m_ScriptEngine.PostScriptEvent(
  3730. m_item.ItemID,
  3731. new EventParams(
  3732. "run_time_permissions", new Object[] { new LSL_Integer(perm) }, new DetectParams[0]));
  3733. }
  3734. // it is an NPC, exit even if the permissions werent granted above, they are not going to answer
  3735. // the question!
  3736. return;
  3737. }
  3738. string ownerName = resolveName(m_host.ParentGroup.RootPart.OwnerID);
  3739. if (ownerName == String.Empty)
  3740. ownerName = "(hippos)";
  3741. if (!m_waitingForScriptAnswer)
  3742. {
  3743. m_host.TaskInventory.LockItemsForWrite(true);
  3744. m_host.TaskInventory[m_item.ItemID].PermsGranter = agentID;
  3745. m_host.TaskInventory[m_item.ItemID].PermsMask = 0;
  3746. m_host.TaskInventory.LockItemsForWrite(false);
  3747. presence.ControllingClient.OnScriptAnswer += handleScriptAnswer;
  3748. m_waitingForScriptAnswer=true;
  3749. }
  3750. presence.ControllingClient.SendScriptQuestion(
  3751. m_host.UUID, m_host.ParentGroup.RootPart.Name, ownerName, m_item.ItemID, perm);
  3752. return;
  3753. }
  3754. // Requested agent is not in range, refuse perms
  3755. m_ScriptEngine.PostScriptEvent(
  3756. m_item.ItemID,
  3757. new EventParams("run_time_permissions", new Object[] { new LSL_Integer(0) }, new DetectParams[0]));
  3758. }
  3759. void handleScriptAnswer(IClientAPI client, UUID taskID, UUID itemID, int answer)
  3760. {
  3761. if (taskID != m_host.UUID)
  3762. return;
  3763. client.OnScriptAnswer -= handleScriptAnswer;
  3764. m_waitingForScriptAnswer = false;
  3765. if ((answer & ScriptBaseClass.PERMISSION_TAKE_CONTROLS) == 0)
  3766. llReleaseControls();
  3767. m_host.TaskInventory.LockItemsForWrite(true);
  3768. m_host.TaskInventory[m_item.ItemID].PermsMask = answer;
  3769. m_host.TaskInventory.LockItemsForWrite(false);
  3770. m_ScriptEngine.PostScriptEvent(m_item.ItemID, new EventParams(
  3771. "run_time_permissions", new Object[] {
  3772. new LSL_Integer(answer) },
  3773. new DetectParams[0]));
  3774. }
  3775. public LSL_Key llGetPermissionsKey()
  3776. {
  3777. m_host.AddScriptLPS(1);
  3778. return m_item.PermsGranter.ToString();
  3779. }
  3780. public LSL_Integer llGetPermissions()
  3781. {
  3782. m_host.AddScriptLPS(1);
  3783. int perms = m_item.PermsMask;
  3784. if (m_automaticLinkPermission)
  3785. perms |= ScriptBaseClass.PERMISSION_CHANGE_LINKS;
  3786. return perms;
  3787. }
  3788. public LSL_Integer llGetLinkNumber()
  3789. {
  3790. m_host.AddScriptLPS(1);
  3791. if (m_host.ParentGroup.PrimCount > 1)
  3792. {
  3793. return m_host.LinkNum;
  3794. }
  3795. else
  3796. {
  3797. return 0;
  3798. }
  3799. }
  3800. public void llSetLinkColor(int linknumber, LSL_Vector color, int face)
  3801. {
  3802. List<SceneObjectPart> parts = GetLinkParts(linknumber);
  3803. if (parts.Count > 0)
  3804. {
  3805. try
  3806. {
  3807. foreach (SceneObjectPart part in parts)
  3808. part.SetFaceColorAlpha(face, color, null);
  3809. }
  3810. finally { }
  3811. }
  3812. }
  3813. public void llCreateLink(LSL_String target, LSL_Integer parent)
  3814. {
  3815. m_host.AddScriptLPS(1);
  3816. UUID targetID;
  3817. if (!UUID.TryParse(target, out targetID))
  3818. return;
  3819. if ((m_item.PermsMask & ScriptBaseClass.PERMISSION_CHANGE_LINKS) == 0
  3820. && !m_automaticLinkPermission)
  3821. {
  3822. Error("llCreateLink", "PERMISSION_CHANGE_LINKS permission not set");
  3823. return;
  3824. }
  3825. CreateLink(target, parent);
  3826. }
  3827. public void CreateLink(string target, int parent)
  3828. {
  3829. UUID targetID;
  3830. if (!UUID.TryParse(target, out targetID))
  3831. return;
  3832. SceneObjectPart targetPart = World.GetSceneObjectPart((UUID)targetID);
  3833. if (targetPart == null)
  3834. return;
  3835. if (targetPart.ParentGroup.AttachmentPoint != 0)
  3836. return; // Fail silently if attached
  3837. if (targetPart.ParentGroup.RootPart.OwnerID != m_host.ParentGroup.RootPart.OwnerID)
  3838. return;
  3839. SceneObjectGroup parentPrim = null, childPrim = null;
  3840. if (parent != 0)
  3841. {
  3842. parentPrim = m_host.ParentGroup;
  3843. childPrim = targetPart.ParentGroup;
  3844. }
  3845. else
  3846. {
  3847. parentPrim = targetPart.ParentGroup;
  3848. childPrim = m_host.ParentGroup;
  3849. }
  3850. // Required for linking
  3851. childPrim.RootPart.ClearUpdateSchedule();
  3852. parentPrim.LinkToGroup(childPrim, true);
  3853. parentPrim.TriggerScriptChangedEvent(Changed.LINK);
  3854. parentPrim.RootPart.CreateSelected = true;
  3855. parentPrim.HasGroupChanged = true;
  3856. parentPrim.ScheduleGroupForFullUpdate();
  3857. IClientAPI client = null;
  3858. ScenePresence sp = World.GetScenePresence(m_host.OwnerID);
  3859. if (sp != null)
  3860. client = sp.ControllingClient;
  3861. if (client != null)
  3862. parentPrim.SendPropertiesToClient(client);
  3863. ScriptSleep(m_sleepMsOnCreateLink);
  3864. }
  3865. public void llBreakLink(int linknum)
  3866. {
  3867. m_host.AddScriptLPS(1);
  3868. if ((m_item.PermsMask & ScriptBaseClass.PERMISSION_CHANGE_LINKS) == 0
  3869. && !m_automaticLinkPermission)
  3870. {
  3871. Error("llBreakLink", "PERMISSION_CHANGE_LINKS permission not set");
  3872. return;
  3873. }
  3874. BreakLink(linknum);
  3875. }
  3876. public void BreakLink(int linknum)
  3877. {
  3878. if (linknum < ScriptBaseClass.LINK_THIS)
  3879. return;
  3880. SceneObjectGroup parentPrim = m_host.ParentGroup;
  3881. if (parentPrim.AttachmentPoint != 0)
  3882. return; // Fail silently if attached
  3883. SceneObjectPart childPrim = null;
  3884. switch (linknum)
  3885. {
  3886. case ScriptBaseClass.LINK_ROOT:
  3887. break;
  3888. case ScriptBaseClass.LINK_SET:
  3889. case ScriptBaseClass.LINK_ALL_OTHERS:
  3890. case ScriptBaseClass.LINK_ALL_CHILDREN:
  3891. case ScriptBaseClass.LINK_THIS:
  3892. foreach (SceneObjectPart part in parentPrim.Parts)
  3893. {
  3894. if (part.UUID != m_host.UUID)
  3895. {
  3896. childPrim = part;
  3897. break;
  3898. }
  3899. }
  3900. break;
  3901. default:
  3902. childPrim = parentPrim.GetLinkNumPart(linknum);
  3903. if (childPrim.UUID == m_host.UUID)
  3904. childPrim = null;
  3905. break;
  3906. }
  3907. if (linknum == ScriptBaseClass.LINK_ROOT)
  3908. {
  3909. // Restructuring Multiple Prims.
  3910. List<SceneObjectPart> parts = new List<SceneObjectPart>(parentPrim.Parts);
  3911. parts.Remove(parentPrim.RootPart);
  3912. if (parts.Count > 0)
  3913. {
  3914. try
  3915. {
  3916. foreach (SceneObjectPart part in parts)
  3917. {
  3918. parentPrim.DelinkFromGroup(part.LocalId, true);
  3919. }
  3920. }
  3921. finally { }
  3922. }
  3923. parentPrim.HasGroupChanged = true;
  3924. parentPrim.ScheduleGroupForFullUpdate();
  3925. parentPrim.TriggerScriptChangedEvent(Changed.LINK);
  3926. if (parts.Count > 0)
  3927. {
  3928. SceneObjectPart newRoot = parts[0];
  3929. parts.Remove(newRoot);
  3930. try
  3931. {
  3932. foreach (SceneObjectPart part in parts)
  3933. {
  3934. part.ClearUpdateSchedule();
  3935. newRoot.ParentGroup.LinkToGroup(part.ParentGroup);
  3936. }
  3937. }
  3938. finally { }
  3939. newRoot.ParentGroup.HasGroupChanged = true;
  3940. newRoot.ParentGroup.ScheduleGroupForFullUpdate();
  3941. }
  3942. }
  3943. else
  3944. {
  3945. if (childPrim == null)
  3946. return;
  3947. parentPrim.DelinkFromGroup(childPrim.LocalId, true);
  3948. parentPrim.HasGroupChanged = true;
  3949. parentPrim.ScheduleGroupForFullUpdate();
  3950. parentPrim.TriggerScriptChangedEvent(Changed.LINK);
  3951. }
  3952. }
  3953. public void llBreakAllLinks()
  3954. {
  3955. m_host.AddScriptLPS(1);
  3956. TaskInventoryItem item = m_item;
  3957. if ((item.PermsMask & ScriptBaseClass.PERMISSION_CHANGE_LINKS) == 0
  3958. && !m_automaticLinkPermission)
  3959. {
  3960. Error("llBreakAllLinks","Script trying to link but PERMISSION_CHANGE_LINKS permission not set!");
  3961. return;
  3962. }
  3963. BreakAllLinks();
  3964. }
  3965. public void BreakAllLinks()
  3966. {
  3967. SceneObjectGroup parentPrim = m_host.ParentGroup;
  3968. if (parentPrim.AttachmentPoint != 0)
  3969. return; // Fail silently if attached
  3970. List<SceneObjectPart> parts = new List<SceneObjectPart>(parentPrim.Parts);
  3971. parts.Remove(parentPrim.RootPart);
  3972. foreach (SceneObjectPart part in parts)
  3973. {
  3974. parentPrim.DelinkFromGroup(part.LocalId, true);
  3975. parentPrim.TriggerScriptChangedEvent(Changed.LINK);
  3976. }
  3977. parentPrim.HasGroupChanged = true;
  3978. parentPrim.ScheduleGroupForFullUpdate();
  3979. }
  3980. public LSL_Key llGetLinkKey(int linknum)
  3981. {
  3982. m_host.AddScriptLPS(1);
  3983. SceneObjectPart part = m_host.ParentGroup.GetLinkNumPart(linknum);
  3984. if (part != null)
  3985. {
  3986. return part.UUID.ToString();
  3987. }
  3988. else
  3989. {
  3990. if (linknum > m_host.ParentGroup.PrimCount || (linknum == 1 && m_host.ParentGroup.PrimCount == 1))
  3991. {
  3992. linknum -= (m_host.ParentGroup.PrimCount) + 1;
  3993. if (linknum < 0)
  3994. return UUID.Zero.ToString();
  3995. List<ScenePresence> avatars = GetLinkAvatars(ScriptBaseClass.LINK_SET);
  3996. if (avatars.Count > linknum)
  3997. {
  3998. return avatars[linknum].UUID.ToString();
  3999. }
  4000. }
  4001. return UUID.Zero.ToString();
  4002. }
  4003. }
  4004. /// <summary>
  4005. /// Returns the name of the child prim or seated avatar matching the
  4006. /// specified link number.
  4007. /// </summary>
  4008. /// <param name="linknum">
  4009. /// The number of a link in the linkset or a link-related constant.
  4010. /// </param>
  4011. /// <returns>
  4012. /// The name determined to match the specified link number.
  4013. /// </returns>
  4014. /// <remarks>
  4015. /// The rules governing the returned name are not simple. The only
  4016. /// time a blank name is returned is if the target prim has a blank
  4017. /// name. If no prim with the given link number can be found then
  4018. /// usually NULL_KEY is returned but there are exceptions.
  4019. ///
  4020. /// In a single unlinked prim, A call with 0 returns the name, all
  4021. /// other values for link number return NULL_KEY
  4022. ///
  4023. /// In link sets it is more complicated.
  4024. ///
  4025. /// If the script is in the root prim:-
  4026. /// A zero link number returns NULL_KEY.
  4027. /// Positive link numbers return the name of the prim, or NULL_KEY
  4028. /// if a prim does not exist at that position.
  4029. /// Negative link numbers return the name of the first child prim.
  4030. ///
  4031. /// If the script is in a child prim:-
  4032. /// Link numbers 0 or 1 return the name of the root prim.
  4033. /// Positive link numbers return the name of the prim or NULL_KEY
  4034. /// if a prim does not exist at that position.
  4035. /// Negative numbers return the name of the root prim.
  4036. ///
  4037. /// References
  4038. /// http://lslwiki.net/lslwiki/wakka.php?wakka=llGetLinkName
  4039. /// Mentions NULL_KEY being returned
  4040. /// http://wiki.secondlife.com/wiki/LlGetLinkName
  4041. /// Mentions using the LINK_* constants, some of which are negative
  4042. /// </remarks>
  4043. public LSL_String llGetLinkName(int linknum)
  4044. {
  4045. m_host.AddScriptLPS(1);
  4046. ISceneEntity entity = GetLinkEntity(m_host, linknum);
  4047. if (entity != null)
  4048. return entity.Name;
  4049. else
  4050. return ScriptBaseClass.NULL_KEY;
  4051. }
  4052. public LSL_Integer llGetInventoryNumber(int type)
  4053. {
  4054. m_host.AddScriptLPS(1);
  4055. int count = 0;
  4056. m_host.TaskInventory.LockItemsForRead(true);
  4057. foreach (KeyValuePair<UUID, TaskInventoryItem> inv in m_host.TaskInventory)
  4058. {
  4059. if (inv.Value.Type == type || type == -1)
  4060. {
  4061. count = count + 1;
  4062. }
  4063. }
  4064. m_host.TaskInventory.LockItemsForRead(false);
  4065. return count;
  4066. }
  4067. public LSL_String llGetInventoryName(int type, int number)
  4068. {
  4069. m_host.AddScriptLPS(1);
  4070. ArrayList keys = new ArrayList();
  4071. m_host.TaskInventory.LockItemsForRead(true);
  4072. foreach (KeyValuePair<UUID, TaskInventoryItem> inv in m_host.TaskInventory)
  4073. {
  4074. if (inv.Value.Type == type || type == -1)
  4075. {
  4076. keys.Add(inv.Value.Name);
  4077. }
  4078. }
  4079. m_host.TaskInventory.LockItemsForRead(false);
  4080. if (keys.Count == 0)
  4081. {
  4082. return String.Empty;
  4083. }
  4084. keys.Sort();
  4085. if (keys.Count > number)
  4086. {
  4087. return (string)keys[number];
  4088. }
  4089. return String.Empty;
  4090. }
  4091. public LSL_Float llGetEnergy()
  4092. {
  4093. m_host.AddScriptLPS(1);
  4094. // TODO: figure out real energy value
  4095. return 1.0f;
  4096. }
  4097. public void llGiveInventory(string destination, string inventory)
  4098. {
  4099. m_host.AddScriptLPS(1);
  4100. UUID destId = UUID.Zero;
  4101. if (!UUID.TryParse(destination, out destId))
  4102. {
  4103. Error("llGiveInventory", "Can't parse destination key '" + destination + "'");
  4104. return;
  4105. }
  4106. TaskInventoryItem item = m_host.Inventory.GetInventoryItem(inventory);
  4107. if (item == null)
  4108. {
  4109. Error("llGiveInventory", "Can't find inventory object '" + inventory + "'");
  4110. return;
  4111. }
  4112. UUID objId = item.ItemID;
  4113. // check if destination is an object
  4114. if (World.GetSceneObjectPart(destId) != null)
  4115. {
  4116. // destination is an object
  4117. World.MoveTaskInventoryItem(destId, m_host, objId);
  4118. }
  4119. else
  4120. {
  4121. ScenePresence presence = World.GetScenePresence(destId);
  4122. if (presence == null)
  4123. {
  4124. UserAccount account =
  4125. World.UserAccountService.GetUserAccount(
  4126. World.RegionInfo.ScopeID,
  4127. destId);
  4128. if (account == null)
  4129. {
  4130. GridUserInfo info = World.GridUserService.GetGridUserInfo(destId.ToString());
  4131. if(info == null || info.Online == false)
  4132. {
  4133. Error("llGiveInventory", "Can't find destination '" + destId.ToString() + "'");
  4134. return;
  4135. }
  4136. }
  4137. }
  4138. // destination is an avatar
  4139. string message;
  4140. InventoryItemBase agentItem = World.MoveTaskInventoryItem(destId, UUID.Zero, m_host, objId, out message);
  4141. if (agentItem == null)
  4142. {
  4143. llSay(0, message);
  4144. return;
  4145. }
  4146. byte[] bucket = new byte[1];
  4147. bucket[0] = (byte)item.Type;
  4148. //byte[] objBytes = agentItem.ID.GetBytes();
  4149. //Array.Copy(objBytes, 0, bucket, 1, 16);
  4150. GridInstantMessage msg = new GridInstantMessage(World,
  4151. m_host.OwnerID, m_host.Name, destId,
  4152. (byte)InstantMessageDialog.TaskInventoryOffered,
  4153. false, item.Name+". "+m_host.Name+" is located at "+
  4154. World.RegionInfo.RegionName+" "+
  4155. m_host.AbsolutePosition.ToString(),
  4156. agentItem.ID, true, m_host.AbsolutePosition,
  4157. bucket, true);
  4158. ScenePresence sp;
  4159. if (World.TryGetScenePresence(destId, out sp))
  4160. {
  4161. sp.ControllingClient.SendInstantMessage(msg);
  4162. }
  4163. else
  4164. {
  4165. if (m_TransferModule != null)
  4166. m_TransferModule.SendInstantMessage(msg, delegate(bool success) {});
  4167. }
  4168. //This delay should only occur when giving inventory to avatars.
  4169. ScriptSleep(m_sleepMsOnGiveInventory);
  4170. }
  4171. }
  4172. [DebuggerNonUserCode]
  4173. public void llRemoveInventory(string name)
  4174. {
  4175. m_host.AddScriptLPS(1);
  4176. TaskInventoryItem item = m_host.Inventory.GetInventoryItem(name);
  4177. if (item == null)
  4178. return;
  4179. if (item.ItemID == m_item.ItemID)
  4180. throw new ScriptDeleteException();
  4181. else
  4182. m_host.Inventory.RemoveInventoryItem(item.ItemID);
  4183. }
  4184. public void llSetText(string text, LSL_Vector color, double alpha)
  4185. {
  4186. m_host.AddScriptLPS(1);
  4187. Vector3 av3 = Util.Clip(color, 0.0f, 1.0f);
  4188. byte[] data;
  4189. data = Util.StringToBytes256(text);
  4190. text = Util.UTF8.GetString(data);
  4191. m_host.SetText(text, av3, Util.Clip((float)alpha, 0.0f, 1.0f));
  4192. }
  4193. public LSL_Float llWater(LSL_Vector offset)
  4194. {
  4195. m_host.AddScriptLPS(1);
  4196. return World.RegionInfo.RegionSettings.WaterHeight;
  4197. }
  4198. public void llPassTouches(int pass)
  4199. {
  4200. m_host.AddScriptLPS(1);
  4201. if (pass != 0)
  4202. m_host.PassTouches = true;
  4203. else
  4204. m_host.PassTouches = false;
  4205. }
  4206. public LSL_Key llRequestAgentData(string id, int data)
  4207. {
  4208. m_host.AddScriptLPS(1);
  4209. UUID uuid;
  4210. if (UUID.TryParse(id, out uuid))
  4211. {
  4212. PresenceInfo pinfo = null;
  4213. UserAccount account;
  4214. UserInfoCacheEntry ce;
  4215. if (!m_userInfoCache.TryGetValue(uuid, out ce))
  4216. {
  4217. account = World.UserAccountService.GetUserAccount(World.RegionInfo.ScopeID, uuid);
  4218. if (account == null)
  4219. {
  4220. m_userInfoCache[uuid] = null; // Cache negative
  4221. return UUID.Zero.ToString();
  4222. }
  4223. PresenceInfo[] pinfos = World.PresenceService.GetAgents(new string[] { uuid.ToString() });
  4224. if (pinfos != null && pinfos.Length > 0)
  4225. {
  4226. foreach (PresenceInfo p in pinfos)
  4227. {
  4228. if (p.RegionID != UUID.Zero)
  4229. {
  4230. pinfo = p;
  4231. }
  4232. }
  4233. }
  4234. ce = new UserInfoCacheEntry();
  4235. ce.time = Util.EnvironmentTickCount();
  4236. ce.account = account;
  4237. ce.pinfo = pinfo;
  4238. m_userInfoCache[uuid] = ce;
  4239. }
  4240. else
  4241. {
  4242. if (ce == null)
  4243. return UUID.Zero.ToString();
  4244. account = ce.account;
  4245. pinfo = ce.pinfo;
  4246. }
  4247. if (Util.EnvironmentTickCount() < ce.time ||
  4248. (Util.EnvironmentTickCount() - ce.time) >= LlRequestAgentDataCacheTimeoutMs)
  4249. {
  4250. PresenceInfo[] pinfos = World.PresenceService.GetAgents(new string[] { uuid.ToString() });
  4251. if (pinfos != null && pinfos.Length > 0)
  4252. {
  4253. foreach (PresenceInfo p in pinfos)
  4254. {
  4255. if (p.RegionID != UUID.Zero)
  4256. {
  4257. pinfo = p;
  4258. }
  4259. }
  4260. }
  4261. else
  4262. pinfo = null;
  4263. ce.time = Util.EnvironmentTickCount();
  4264. ce.pinfo = pinfo;
  4265. }
  4266. string reply = String.Empty;
  4267. switch (data)
  4268. {
  4269. case ScriptBaseClass.DATA_ONLINE: // DATA_ONLINE (0|1)
  4270. if (pinfo != null && pinfo.RegionID != UUID.Zero)
  4271. reply = "1";
  4272. else
  4273. reply = "0";
  4274. break;
  4275. case ScriptBaseClass.DATA_NAME: // DATA_NAME (First Last)
  4276. reply = account.FirstName + " " + account.LastName;
  4277. break;
  4278. case ScriptBaseClass.DATA_BORN: // DATA_BORN (YYYY-MM-DD)
  4279. DateTime born = new DateTime(1970, 1, 1, 0, 0, 0, 0);
  4280. born = born.AddSeconds(account.Created);
  4281. reply = born.ToString("yyyy-MM-dd");
  4282. break;
  4283. case ScriptBaseClass.DATA_RATING: // DATA_RATING (0,0,0,0,0,0)
  4284. reply = "0,0,0,0,0,0";
  4285. break;
  4286. case 7: // DATA_USERLEVEL (integer). This is not available in LL and so has no constant.
  4287. reply = account.UserLevel.ToString();
  4288. break;
  4289. case ScriptBaseClass.DATA_PAYINFO: // DATA_PAYINFO (0|1|2|3)
  4290. reply = "0";
  4291. break;
  4292. default:
  4293. return UUID.Zero.ToString(); // Raise no event
  4294. }
  4295. UUID rq = UUID.Random();
  4296. UUID tid = AsyncCommands.
  4297. DataserverPlugin.RegisterRequest(m_host.LocalId,
  4298. m_item.ItemID, rq.ToString());
  4299. AsyncCommands.
  4300. DataserverPlugin.DataserverReply(rq.ToString(), reply);
  4301. ScriptSleep(m_sleepMsOnRequestAgentData);
  4302. return tid.ToString();
  4303. }
  4304. else
  4305. {
  4306. Error("llRequestAgentData","Invalid UUID passed to llRequestAgentData.");
  4307. }
  4308. return "";
  4309. }
  4310. public LSL_Key llRequestInventoryData(string name)
  4311. {
  4312. m_host.AddScriptLPS(1);
  4313. foreach (TaskInventoryItem item in m_host.Inventory.GetInventoryItems())
  4314. {
  4315. if (item.Type == 3 && item.Name == name)
  4316. {
  4317. UUID tid = AsyncCommands.
  4318. DataserverPlugin.RegisterRequest(m_host.LocalId,
  4319. m_item.ItemID, item.AssetID.ToString());
  4320. Vector3 region = new Vector3(World.RegionInfo.WorldLocX, World.RegionInfo.WorldLocY, 0);
  4321. World.AssetService.Get(item.AssetID.ToString(), this,
  4322. delegate(string i, object sender, AssetBase a)
  4323. {
  4324. AssetLandmark lm = new AssetLandmark(a);
  4325. float rx = (uint)(lm.RegionHandle >> 32);
  4326. float ry = (uint)lm.RegionHandle;
  4327. region = lm.Position + new Vector3(rx, ry, 0) - region;
  4328. string reply = region.ToString();
  4329. AsyncCommands.
  4330. DataserverPlugin.DataserverReply(i.ToString(),
  4331. reply);
  4332. });
  4333. ScriptSleep(m_sleepMsOnRequestInventoryData);
  4334. return tid.ToString();
  4335. }
  4336. }
  4337. ScriptSleep(m_sleepMsOnRequestInventoryData);
  4338. return String.Empty;
  4339. }
  4340. public void llSetDamage(double damage)
  4341. {
  4342. m_host.AddScriptLPS(1);
  4343. m_host.ParentGroup.Damage = (float)damage;
  4344. }
  4345. public void llTeleportAgentHome(string agent)
  4346. {
  4347. m_host.AddScriptLPS(1);
  4348. UUID agentId = new UUID();
  4349. if (UUID.TryParse(agent, out agentId))
  4350. {
  4351. ScenePresence presence = World.GetScenePresence(agentId);
  4352. if (presence != null && presence.PresenceType != PresenceType.Npc)
  4353. {
  4354. // agent must not be a god
  4355. if (presence.GodController.UserLevel >= 200) return;
  4356. // agent must be over the owners land
  4357. if (m_host.OwnerID == World.LandChannel.GetLandObject(presence.AbsolutePosition).LandData.OwnerID)
  4358. {
  4359. if (!World.TeleportClientHome(agentId, presence.ControllingClient))
  4360. {
  4361. // They can't be teleported home for some reason
  4362. GridRegion regionInfo = World.GridService.GetRegionByUUID(UUID.Zero, new UUID("2b02daac-e298-42fa-9a75-f488d37896e6"));
  4363. if (regionInfo != null)
  4364. {
  4365. World.RequestTeleportLocation(
  4366. presence.ControllingClient, regionInfo.RegionHandle, new Vector3(128, 128, 23), Vector3.Zero,
  4367. (uint)(Constants.TeleportFlags.SetLastToTarget | Constants.TeleportFlags.ViaHome));
  4368. }
  4369. }
  4370. }
  4371. }
  4372. }
  4373. ScriptSleep(m_sleepMsOnSetDamage);
  4374. }
  4375. public void llTeleportAgent(string agent, string destination, LSL_Vector targetPos, LSL_Vector targetLookAt)
  4376. {
  4377. m_host.AddScriptLPS(1);
  4378. UUID agentId = new UUID();
  4379. if (UUID.TryParse(agent, out agentId))
  4380. {
  4381. ScenePresence presence = World.GetScenePresence(agentId);
  4382. if (presence != null && presence.PresenceType != PresenceType.Npc)
  4383. {
  4384. if (destination == String.Empty)
  4385. destination = World.RegionInfo.RegionName;
  4386. if (m_item.PermsGranter == agentId)
  4387. {
  4388. if ((m_item.PermsMask & ScriptBaseClass.PERMISSION_TELEPORT) != 0)
  4389. {
  4390. DoLLTeleport(presence, destination, targetPos, targetLookAt);
  4391. }
  4392. }
  4393. // agent must be wearing the object
  4394. if (m_host.ParentGroup.AttachmentPoint != 0 && m_host.OwnerID == presence.UUID)
  4395. {
  4396. DoLLTeleport(presence, destination, targetPos, targetLookAt);
  4397. }
  4398. else
  4399. {
  4400. // agent must not be a god
  4401. if (presence.IsViewerUIGod) return;
  4402. // agent must be over the owners land
  4403. ILandObject agentLand = World.LandChannel.GetLandObject(presence.AbsolutePosition);
  4404. ILandObject objectLand = World.LandChannel.GetLandObject(m_host.AbsolutePosition);
  4405. if (m_host.OwnerID == objectLand.LandData.OwnerID && m_host.OwnerID == agentLand.LandData.OwnerID)
  4406. {
  4407. DoLLTeleport(presence, destination, targetPos, targetLookAt);
  4408. }
  4409. }
  4410. }
  4411. }
  4412. }
  4413. public void llTeleportAgentGlobalCoords(string agent, LSL_Vector global_coords, LSL_Vector targetPos, LSL_Vector targetLookAt)
  4414. {
  4415. m_host.AddScriptLPS(1);
  4416. UUID agentId = new UUID();
  4417. ulong regionHandle = Util.RegionWorldLocToHandle((uint)global_coords.x, (uint)global_coords.y);
  4418. if (UUID.TryParse(agent, out agentId))
  4419. {
  4420. // This function is owner only!
  4421. if (m_host.OwnerID != agentId)
  4422. return;
  4423. ScenePresence presence = World.GetScenePresence(agentId);
  4424. if (presence == null || presence.PresenceType == PresenceType.Npc)
  4425. return;
  4426. // Can't TP sitting avatars
  4427. if (presence.ParentID != 0) // Sitting
  4428. return;
  4429. if (m_item.PermsGranter == agentId)
  4430. {
  4431. // If attached using llAttachToAvatarTemp, cowardly refuse
  4432. if (m_host.ParentGroup.AttachmentPoint != 0 && m_host.ParentGroup.FromItemID == UUID.Zero)
  4433. return;
  4434. if ((m_item.PermsMask & ScriptBaseClass.PERMISSION_TELEPORT) != 0)
  4435. {
  4436. World.RequestTeleportLocation(presence.ControllingClient, regionHandle, targetPos, targetLookAt, (uint)TeleportFlags.ViaLocation);
  4437. }
  4438. }
  4439. }
  4440. }
  4441. private void DoLLTeleport(ScenePresence sp, string destination, Vector3 targetPos, Vector3 targetLookAt)
  4442. {
  4443. UUID assetID = ScriptUtils.GetAssetIdFromKeyOrItemName(m_host, destination);
  4444. // The destinaion is not an asset ID and also doesn't name a landmark.
  4445. // Use it as a sim name
  4446. if (assetID == UUID.Zero)
  4447. {
  4448. World.RequestTeleportLocation(sp.ControllingClient, destination, targetPos, targetLookAt, (uint)TeleportFlags.ViaLocation);
  4449. return;
  4450. }
  4451. AssetBase lma = World.AssetService.Get(assetID.ToString());
  4452. if (lma == null)
  4453. return;
  4454. if (lma.Type != (sbyte)AssetType.Landmark)
  4455. return;
  4456. AssetLandmark lm = new AssetLandmark(lma);
  4457. World.RequestTeleportLocation(sp.ControllingClient, lm.RegionHandle, targetPos, targetLookAt, (uint)TeleportFlags.ViaLocation);
  4458. }
  4459. public void llTextBox(string agent, string message, int chatChannel)
  4460. {
  4461. IDialogModule dm = World.RequestModuleInterface<IDialogModule>();
  4462. if (dm == null)
  4463. return;
  4464. m_host.AddScriptLPS(1);
  4465. UUID av = new UUID();
  4466. if (!UUID.TryParse(agent,out av))
  4467. {
  4468. Error("llTextBox", "First parameter must be a key");
  4469. return;
  4470. }
  4471. if (message == string.Empty)
  4472. {
  4473. Error("llTextBox", "Empty message");
  4474. }
  4475. else if (Encoding.UTF8.GetByteCount(message) > 512)
  4476. {
  4477. Error("llTextBox", "Message longer than 512 bytes");
  4478. }
  4479. else
  4480. {
  4481. dm.SendTextBoxToUser(av, message, chatChannel, m_host.Name, m_host.UUID, m_host.OwnerID);
  4482. ScriptSleep(m_sleepMsOnTextBox);
  4483. }
  4484. }
  4485. public void llModifyLand(int action, int brush)
  4486. {
  4487. m_host.AddScriptLPS(1);
  4488. ITerrainModule tm = m_ScriptEngine.World.RequestModuleInterface<ITerrainModule>();
  4489. if (tm != null)
  4490. {
  4491. tm.ModifyTerrain(m_host.OwnerID, m_host.AbsolutePosition, (byte) brush, (byte) action, m_host.OwnerID);
  4492. }
  4493. }
  4494. public void llCollisionSound(string impact_sound, double impact_volume)
  4495. {
  4496. m_host.AddScriptLPS(1);
  4497. if(impact_sound == "")
  4498. {
  4499. m_host.CollisionSoundVolume = (float)impact_volume;
  4500. m_host.CollisionSound = m_host.invalidCollisionSoundUUID;
  4501. m_host.CollisionSoundType = -1; // disable all sounds
  4502. m_host.aggregateScriptEvents();
  4503. return;
  4504. }
  4505. // TODO: Parameter check logic required.
  4506. UUID soundId = ScriptUtils.GetAssetIdFromKeyOrItemName(m_host, impact_sound, AssetType.Sound);
  4507. if(soundId != UUID.Zero)
  4508. {
  4509. m_host.CollisionSound = soundId;
  4510. m_host.CollisionSoundVolume = (float)impact_volume;
  4511. m_host.CollisionSoundType = 1;
  4512. }
  4513. else
  4514. m_host.CollisionSoundType = -1;
  4515. m_host.aggregateScriptEvents();
  4516. }
  4517. public LSL_String llGetAnimation(string id)
  4518. {
  4519. // This should only return a value if the avatar is in the same region
  4520. m_host.AddScriptLPS(1);
  4521. UUID avatar = (UUID)id;
  4522. ScenePresence presence = World.GetScenePresence(avatar);
  4523. if (presence == null)
  4524. return "";
  4525. if (m_host.RegionHandle == presence.RegionHandle)
  4526. {
  4527. if (presence != null)
  4528. {
  4529. // if (presence.SitGround)
  4530. // return "Sitting on Ground";
  4531. // if (presence.ParentID != 0 || presence.ParentUUID != UUID.Zero)
  4532. // return "Sitting";
  4533. string movementAnimation = presence.Animator.CurrentMovementAnimation;
  4534. string lslMovementAnimation;
  4535. if (MovementAnimationsForLSL.TryGetValue(movementAnimation, out lslMovementAnimation))
  4536. return lslMovementAnimation;
  4537. }
  4538. }
  4539. return String.Empty;
  4540. }
  4541. public void llMessageLinked(int linknumber, int num, string msg, string id)
  4542. {
  4543. m_host.AddScriptLPS(1);
  4544. List<SceneObjectPart> parts = GetLinkParts(linknumber);
  4545. UUID partItemID;
  4546. foreach (SceneObjectPart part in parts)
  4547. {
  4548. foreach (TaskInventoryItem item in part.Inventory.GetInventoryItems())
  4549. {
  4550. if (item.Type == ScriptBaseClass.INVENTORY_SCRIPT)
  4551. {
  4552. partItemID = item.ItemID;
  4553. int linkNumber = m_host.LinkNum;
  4554. if (m_host.ParentGroup.PrimCount == 1)
  4555. linkNumber = 0;
  4556. object[] resobj = new object[]
  4557. {
  4558. new LSL_Integer(linkNumber), new LSL_Integer(num), new LSL_String(msg), new LSL_String(id)
  4559. };
  4560. m_ScriptEngine.PostScriptEvent(partItemID,
  4561. new EventParams("link_message",
  4562. resobj, new DetectParams[0]));
  4563. }
  4564. }
  4565. }
  4566. }
  4567. public void llPushObject(string target, LSL_Vector impulse, LSL_Vector ang_impulse, int local)
  4568. {
  4569. m_host.AddScriptLPS(1);
  4570. bool pushrestricted = World.RegionInfo.RegionSettings.RestrictPushing;
  4571. bool pushAllowed = false;
  4572. bool pusheeIsAvatar = false;
  4573. UUID targetID = UUID.Zero;
  4574. if (!UUID.TryParse(target,out targetID))
  4575. return;
  4576. ScenePresence pusheeav = null;
  4577. Vector3 PusheePos = Vector3.Zero;
  4578. SceneObjectPart pusheeob = null;
  4579. ScenePresence avatar = World.GetScenePresence(targetID);
  4580. if (avatar != null)
  4581. {
  4582. pusheeIsAvatar = true;
  4583. // Pushee doesn't have a physics actor
  4584. if (avatar.PhysicsActor == null)
  4585. return;
  4586. // Pushee is in GodMode this pushing object isn't owned by them
  4587. if (avatar.IsViewerUIGod && m_host.OwnerID != targetID)
  4588. return;
  4589. pusheeav = avatar;
  4590. // Find pushee position
  4591. // Pushee Linked?
  4592. SceneObjectPart sitPart = pusheeav.ParentPart;
  4593. if (sitPart != null)
  4594. PusheePos = sitPart.AbsolutePosition;
  4595. else
  4596. PusheePos = pusheeav.AbsolutePosition;
  4597. }
  4598. if (!pusheeIsAvatar)
  4599. {
  4600. // not an avatar so push is not affected by parcel flags
  4601. pusheeob = World.GetSceneObjectPart((UUID)target);
  4602. // We can't find object
  4603. if (pusheeob == null)
  4604. return;
  4605. // Object not pushable. Not an attachment and has no physics component
  4606. if (!pusheeob.ParentGroup.IsAttachment && pusheeob.PhysActor == null)
  4607. return;
  4608. PusheePos = pusheeob.AbsolutePosition;
  4609. pushAllowed = true;
  4610. }
  4611. else
  4612. {
  4613. if (pushrestricted)
  4614. {
  4615. ILandObject targetlandObj = World.LandChannel.GetLandObject(PusheePos);
  4616. // We didn't find the parcel but region is push restricted so assume it is NOT ok
  4617. if (targetlandObj == null)
  4618. return;
  4619. // Need provisions for Group Owned here
  4620. if (m_host.OwnerID == targetlandObj.LandData.OwnerID ||
  4621. targetlandObj.LandData.IsGroupOwned || m_host.OwnerID == targetID)
  4622. {
  4623. pushAllowed = true;
  4624. }
  4625. }
  4626. else
  4627. {
  4628. ILandObject targetlandObj = World.LandChannel.GetLandObject(PusheePos);
  4629. if (targetlandObj == null)
  4630. {
  4631. // We didn't find the parcel but region isn't push restricted so assume it's ok
  4632. pushAllowed = true;
  4633. }
  4634. else
  4635. {
  4636. // Parcel push restriction
  4637. if ((targetlandObj.LandData.Flags & (uint)ParcelFlags.RestrictPushObject) == (uint)ParcelFlags.RestrictPushObject)
  4638. {
  4639. // Need provisions for Group Owned here
  4640. if (m_host.OwnerID == targetlandObj.LandData.OwnerID ||
  4641. targetlandObj.LandData.IsGroupOwned ||
  4642. m_host.OwnerID == targetID)
  4643. {
  4644. pushAllowed = true;
  4645. }
  4646. //ParcelFlags.RestrictPushObject
  4647. //pushAllowed = true;
  4648. }
  4649. else
  4650. {
  4651. // Parcel isn't push restricted
  4652. pushAllowed = true;
  4653. }
  4654. }
  4655. }
  4656. }
  4657. if (pushAllowed)
  4658. {
  4659. float distance = (PusheePos - m_host.AbsolutePosition).Length();
  4660. float distance_term = distance * distance * distance; // Script Energy
  4661. // use total object mass and not part
  4662. float pusher_mass = m_host.ParentGroup.GetMass();
  4663. float PUSH_ATTENUATION_DISTANCE = 17f;
  4664. float PUSH_ATTENUATION_SCALE = 5f;
  4665. float distance_attenuation = 1f;
  4666. if (distance > PUSH_ATTENUATION_DISTANCE)
  4667. {
  4668. float normalized_units = 1f + (distance - PUSH_ATTENUATION_DISTANCE) / PUSH_ATTENUATION_SCALE;
  4669. distance_attenuation = 1f / normalized_units;
  4670. }
  4671. Vector3 applied_linear_impulse = impulse;
  4672. {
  4673. float impulse_length = applied_linear_impulse.Length();
  4674. float desired_energy = impulse_length * pusher_mass;
  4675. if (desired_energy > 0f)
  4676. desired_energy += distance_term;
  4677. float scaling_factor = 1f;
  4678. scaling_factor *= distance_attenuation;
  4679. applied_linear_impulse *= scaling_factor;
  4680. }
  4681. if (pusheeIsAvatar)
  4682. {
  4683. if (pusheeav != null)
  4684. {
  4685. PhysicsActor pa = pusheeav.PhysicsActor;
  4686. if (pa != null)
  4687. {
  4688. if (local != 0)
  4689. {
  4690. // applied_linear_impulse *= m_host.GetWorldRotation();
  4691. applied_linear_impulse *= pusheeav.GetWorldRotation();
  4692. }
  4693. pa.AddForce(applied_linear_impulse, true);
  4694. }
  4695. }
  4696. }
  4697. else
  4698. {
  4699. if (pusheeob != null)
  4700. {
  4701. if (pusheeob.PhysActor != null)
  4702. {
  4703. pusheeob.ApplyImpulse(applied_linear_impulse, local != 0);
  4704. }
  4705. }
  4706. }
  4707. }
  4708. }
  4709. public void llPassCollisions(int pass)
  4710. {
  4711. m_host.AddScriptLPS(1);
  4712. if (pass == 0)
  4713. {
  4714. m_host.PassCollisions = false;
  4715. }
  4716. else
  4717. {
  4718. m_host.PassCollisions = true;
  4719. }
  4720. }
  4721. public LSL_String llGetScriptName()
  4722. {
  4723. m_host.AddScriptLPS(1);
  4724. return m_item.Name != null ? m_item.Name : String.Empty;
  4725. }
  4726. public LSL_Integer llGetLinkNumberOfSides(int link)
  4727. {
  4728. m_host.AddScriptLPS(1);
  4729. SceneObjectPart linkedPart;
  4730. if (link == ScriptBaseClass.LINK_ROOT)
  4731. linkedPart = m_host.ParentGroup.RootPart;
  4732. else if (link == ScriptBaseClass.LINK_THIS)
  4733. linkedPart = m_host;
  4734. else
  4735. linkedPart = m_host.ParentGroup.GetLinkNumPart(link);
  4736. return GetNumberOfSides(linkedPart);
  4737. }
  4738. public LSL_Integer llGetNumberOfSides()
  4739. {
  4740. m_host.AddScriptLPS(1);
  4741. return m_host.GetNumberOfSides();
  4742. }
  4743. protected int GetNumberOfSides(SceneObjectPart part)
  4744. {
  4745. return part.GetNumberOfSides();
  4746. }
  4747. /* The new / changed functions were tested with the following LSL script:
  4748. default
  4749. {
  4750. state_entry()
  4751. {
  4752. rotation rot = llEuler2Rot(<0,70,0> * DEG_TO_RAD);
  4753. llOwnerSay("to get here, we rotate over: "+ (string) llRot2Axis(rot));
  4754. llOwnerSay("and we rotate for: "+ (llRot2Angle(rot) * RAD_TO_DEG));
  4755. // convert back and forth between quaternion <-> vector and angle
  4756. rotation newrot = llAxisAngle2Rot(llRot2Axis(rot),llRot2Angle(rot));
  4757. llOwnerSay("Old rotation was: "+(string) rot);
  4758. llOwnerSay("re-converted rotation is: "+(string) newrot);
  4759. llSetRot(rot); // to check the parameters in the prim
  4760. }
  4761. }
  4762. */
  4763. // Xantor 29/apr/2008
  4764. // Returns rotation described by rotating angle radians about axis.
  4765. // q = cos(a/2) + i (x * sin(a/2)) + j (y * sin(a/2)) + k (z * sin(a/2))
  4766. public LSL_Rotation llAxisAngle2Rot(LSL_Vector axis, double angle)
  4767. {
  4768. m_host.AddScriptLPS(1);
  4769. double x, y, z, s, t;
  4770. s = Math.Cos(angle * 0.5);
  4771. t = Math.Sin(angle * 0.5); // temp value to avoid 2 more sin() calcs
  4772. axis = LSL_Vector.Norm(axis);
  4773. x = axis.x * t;
  4774. y = axis.y * t;
  4775. z = axis.z * t;
  4776. return new LSL_Rotation(x,y,z,s);
  4777. }
  4778. /// <summary>
  4779. /// Returns the axis of rotation for a quaternion
  4780. /// </summary>
  4781. /// <returns></returns>
  4782. /// <param name='rot'></param>
  4783. public LSL_Vector llRot2Axis(LSL_Rotation rot)
  4784. {
  4785. m_host.AddScriptLPS(1);
  4786. rot.Normalize();
  4787. double s = Math.Sqrt(1 - rot.s * rot.s);
  4788. if (s < 1e-8)
  4789. return new LSL_Vector(0, 0, 0);
  4790. double invS = 1.0 / s;
  4791. if (rot.s < 0)
  4792. invS = -invS;
  4793. return new LSL_Vector(rot.x * invS, rot.y * invS, rot.z * invS);
  4794. }
  4795. // Returns the angle of a quaternion (see llRot2Axis for the axis)
  4796. public LSL_Float llRot2Angle(LSL_Rotation rot)
  4797. {
  4798. m_host.AddScriptLPS(1);
  4799. rot.Normalize();
  4800. double angle = 2 * Math.Acos(rot.s);
  4801. if (angle > Math.PI)
  4802. angle = 2 * Math.PI - angle;
  4803. return angle;
  4804. }
  4805. public LSL_Float llAcos(double val)
  4806. {
  4807. m_host.AddScriptLPS(1);
  4808. return (double)Math.Acos(val);
  4809. }
  4810. public LSL_Float llAsin(double val)
  4811. {
  4812. m_host.AddScriptLPS(1);
  4813. return (double)Math.Asin(val);
  4814. }
  4815. // jcochran 5/jan/2012
  4816. public LSL_Float llAngleBetween(LSL_Rotation a, LSL_Rotation b)
  4817. {
  4818. m_host.AddScriptLPS(1);
  4819. double aa = (a.x * a.x + a.y * a.y + a.z * a.z + a.s * a.s);
  4820. double bb = (b.x * b.x + b.y * b.y + b.z * b.z + b.s * b.s);
  4821. double aa_bb = aa * bb;
  4822. if (aa_bb == 0) return 0.0;
  4823. double ab = (a.x * b.x + a.y * b.y + a.z * b.z + a.s * b.s);
  4824. double quotient = (ab * ab) / aa_bb;
  4825. if (quotient >= 1.0) return 0.0;
  4826. return Math.Acos(2 * quotient - 1);
  4827. }
  4828. public LSL_Key llGetInventoryKey(string name)
  4829. {
  4830. m_host.AddScriptLPS(1);
  4831. TaskInventoryItem item = m_host.Inventory.GetInventoryItem(name);
  4832. if (item == null)
  4833. return UUID.Zero.ToString();
  4834. if ((item.CurrentPermissions
  4835. & (uint)(PermissionMask.Copy | PermissionMask.Transfer | PermissionMask.Modify))
  4836. == (uint)(PermissionMask.Copy | PermissionMask.Transfer | PermissionMask.Modify))
  4837. {
  4838. return item.AssetID.ToString();
  4839. }
  4840. return UUID.Zero.ToString();
  4841. }
  4842. public void llAllowInventoryDrop(int add)
  4843. {
  4844. m_host.AddScriptLPS(1);
  4845. if (add != 0)
  4846. m_host.ParentGroup.RootPart.AllowedDrop = true;
  4847. else
  4848. m_host.ParentGroup.RootPart.AllowedDrop = false;
  4849. // Update the object flags
  4850. m_host.ParentGroup.RootPart.aggregateScriptEvents();
  4851. }
  4852. public LSL_Vector llGetSunDirection()
  4853. {
  4854. m_host.AddScriptLPS(1);
  4855. LSL_Vector SunDoubleVector3;
  4856. Vector3 SunFloatVector3;
  4857. // sunPosition estate setting is set in OpenSim.Region.CoreModules.SunModule
  4858. // have to convert from Vector3 (float) to LSL_Vector (double)
  4859. SunFloatVector3 = World.RegionInfo.RegionSettings.SunVector;
  4860. SunDoubleVector3.x = (double)SunFloatVector3.X;
  4861. SunDoubleVector3.y = (double)SunFloatVector3.Y;
  4862. SunDoubleVector3.z = (double)SunFloatVector3.Z;
  4863. return SunDoubleVector3;
  4864. }
  4865. public LSL_Vector llGetTextureOffset(int face)
  4866. {
  4867. m_host.AddScriptLPS(1);
  4868. return GetTextureOffset(m_host, face);
  4869. }
  4870. protected LSL_Vector GetTextureOffset(SceneObjectPart part, int face)
  4871. {
  4872. Primitive.TextureEntry tex = part.Shape.Textures;
  4873. LSL_Vector offset = new LSL_Vector();
  4874. if (face == ScriptBaseClass.ALL_SIDES)
  4875. {
  4876. face = 0;
  4877. }
  4878. if (face >= 0 && face < GetNumberOfSides(part))
  4879. {
  4880. offset.x = tex.GetFace((uint)face).OffsetU;
  4881. offset.y = tex.GetFace((uint)face).OffsetV;
  4882. offset.z = 0.0;
  4883. return offset;
  4884. }
  4885. else
  4886. {
  4887. return offset;
  4888. }
  4889. }
  4890. public LSL_Vector llGetTextureScale(int side)
  4891. {
  4892. m_host.AddScriptLPS(1);
  4893. Primitive.TextureEntry tex = m_host.Shape.Textures;
  4894. LSL_Vector scale;
  4895. if (side == -1)
  4896. {
  4897. side = 0;
  4898. }
  4899. scale.x = tex.GetFace((uint)side).RepeatU;
  4900. scale.y = tex.GetFace((uint)side).RepeatV;
  4901. scale.z = 0.0;
  4902. return scale;
  4903. }
  4904. public LSL_Float llGetTextureRot(int face)
  4905. {
  4906. m_host.AddScriptLPS(1);
  4907. return GetTextureRot(m_host, face);
  4908. }
  4909. protected LSL_Float GetTextureRot(SceneObjectPart part, int face)
  4910. {
  4911. Primitive.TextureEntry tex = part.Shape.Textures;
  4912. if (face == -1)
  4913. {
  4914. face = 0;
  4915. }
  4916. if (face >= 0 && face < GetNumberOfSides(part))
  4917. {
  4918. return tex.GetFace((uint)face).Rotation;
  4919. }
  4920. else
  4921. {
  4922. return 0.0;
  4923. }
  4924. }
  4925. public LSL_Integer llSubStringIndex(string source, string pattern)
  4926. {
  4927. m_host.AddScriptLPS(1);
  4928. return source.IndexOf(pattern);
  4929. }
  4930. public LSL_Key llGetOwnerKey(string id)
  4931. {
  4932. m_host.AddScriptLPS(1);
  4933. UUID key = new UUID();
  4934. if (UUID.TryParse(id, out key))
  4935. {
  4936. try
  4937. {
  4938. SceneObjectPart obj = World.GetSceneObjectPart(key);
  4939. if (obj == null)
  4940. return id; // the key is for an agent so just return the key
  4941. else
  4942. return obj.OwnerID.ToString();
  4943. }
  4944. catch (KeyNotFoundException)
  4945. {
  4946. return id; // The Object/Agent not in the region so just return the key
  4947. }
  4948. }
  4949. else
  4950. {
  4951. return UUID.Zero.ToString();
  4952. }
  4953. }
  4954. public LSL_Vector llGetCenterOfMass()
  4955. {
  4956. m_host.AddScriptLPS(1);
  4957. return new LSL_Vector(m_host.GetCenterOfMass());
  4958. }
  4959. public LSL_List llListSort(LSL_List src, int stride, int ascending)
  4960. {
  4961. m_host.AddScriptLPS(1);
  4962. if (stride <= 0)
  4963. {
  4964. stride = 1;
  4965. }
  4966. return src.Sort(stride, ascending);
  4967. }
  4968. public LSL_Integer llGetListLength(LSL_List src)
  4969. {
  4970. m_host.AddScriptLPS(1);
  4971. return src.Length;
  4972. }
  4973. public LSL_Integer llList2Integer(LSL_List src, int index)
  4974. {
  4975. m_host.AddScriptLPS(1);
  4976. if (index < 0)
  4977. index = src.Length + index;
  4978. if (index >= src.Length || index < 0)
  4979. return 0;
  4980. object item = src.Data[index];
  4981. // Vectors & Rotations always return zero in SL, but
  4982. // keys don't always return zero, it seems to be a bit complex.
  4983. if (item is LSL_Vector || item is LSL_Rotation)
  4984. return 0;
  4985. try
  4986. {
  4987. if (item is LSL_Integer)
  4988. return (LSL_Integer)item;
  4989. else if (item is LSL_Float)
  4990. return Convert.ToInt32(((LSL_Float)item).value);;
  4991. return new LSL_Integer(item.ToString());
  4992. }
  4993. catch (FormatException)
  4994. {
  4995. return 0;
  4996. }
  4997. }
  4998. public LSL_Float llList2Float(LSL_List src, int index)
  4999. {
  5000. m_host.AddScriptLPS(1);
  5001. if (index < 0)
  5002. index = src.Length + index;
  5003. if (index >= src.Length || index < 0)
  5004. return 0;
  5005. object item = src.Data[index];
  5006. // Vectors & Rotations always return zero in SL
  5007. if(item is LSL_Vector || item is LSL_Rotation)
  5008. return 0;
  5009. // valid keys seem to get parsed as integers then converted to floats
  5010. if (item is LSL_Key)
  5011. {
  5012. UUID uuidt;
  5013. string s = item.ToString();
  5014. if(UUID.TryParse(s, out uuidt))
  5015. return Convert.ToDouble(new LSL_Integer(s).value);
  5016. // we can't do this because a string is also a LSL_Key for now :(
  5017. // else
  5018. // return 0;
  5019. }
  5020. try
  5021. {
  5022. if (item is LSL_Integer)
  5023. return Convert.ToDouble(((LSL_Integer)item).value);
  5024. else if (item is LSL_Float)
  5025. return Convert.ToDouble(((LSL_Float)item).value);
  5026. else if (item is LSL_String)
  5027. {
  5028. string str = ((LSL_String)item).m_string;
  5029. Match m = Regex.Match(str, "^\\s*(-?\\+?[,0-9]+\\.?[0-9]*)");
  5030. if (m != Match.Empty)
  5031. {
  5032. str = m.Value;
  5033. double d = 0.0;
  5034. if (!Double.TryParse(str, out d))
  5035. return 0.0;
  5036. return d;
  5037. }
  5038. return 0.0;
  5039. }
  5040. return Convert.ToDouble(item);
  5041. }
  5042. catch (FormatException)
  5043. {
  5044. return 0.0;
  5045. }
  5046. }
  5047. public LSL_String llList2String(LSL_List src, int index)
  5048. {
  5049. m_host.AddScriptLPS(1);
  5050. if (index < 0)
  5051. index = src.Length + index;
  5052. if (index >= src.Length || index < 0)
  5053. return String.Empty;
  5054. return src.Data[index].ToString();
  5055. }
  5056. public LSL_Key llList2Key(LSL_List src, int index)
  5057. {
  5058. m_host.AddScriptLPS(1);
  5059. if (index < 0)
  5060. index = src.Length + index;
  5061. if (index >= src.Length || index < 0)
  5062. return String.Empty;
  5063. object item = src.Data[index];
  5064. // SL spits out an empty string for types other than key & string
  5065. // At the time of patching, LSL_Key is currently LSL_String,
  5066. // so the OR check may be a little redundant, but it's being done
  5067. // for completion and should LSL_Key ever be implemented
  5068. // as it's own struct
  5069. // NOTE: 3rd case is needed because a NULL_KEY comes through as
  5070. // type 'obj' and wrongly returns ""
  5071. if (!(item is LSL_String ||
  5072. item is LSL_Key ||
  5073. item.ToString() == "00000000-0000-0000-0000-000000000000"))
  5074. {
  5075. return String.Empty;
  5076. }
  5077. return item.ToString();
  5078. }
  5079. public LSL_Vector llList2Vector(LSL_List src, int index)
  5080. {
  5081. m_host.AddScriptLPS(1);
  5082. if (index < 0)
  5083. index = src.Length + index;
  5084. if (index >= src.Length || index < 0)
  5085. return new LSL_Vector(0, 0, 0);
  5086. object item = src.Data[index];
  5087. if (item.GetType() == typeof(LSL_Vector))
  5088. return (LSL_Vector)item;
  5089. // SL spits always out ZERO_VECTOR for anything other than
  5090. // strings or vectors. Although keys always return ZERO_VECTOR,
  5091. // it is currently difficult to make the distinction between
  5092. // a string, a key as string and a string that by coincidence
  5093. // is a string, so we're going to leave that up to the
  5094. // LSL_Vector constructor.
  5095. if(item is LSL_Vector)
  5096. return (LSL_Vector) item;
  5097. if (item is LSL_String)
  5098. return new LSL_Vector(item.ToString());
  5099. return new LSL_Vector(0, 0, 0);
  5100. }
  5101. public LSL_Rotation llList2Rot(LSL_List src, int index)
  5102. {
  5103. m_host.AddScriptLPS(1);
  5104. if (index < 0)
  5105. index = src.Length + index;
  5106. if (index >= src.Length || index < 0)
  5107. return new LSL_Rotation(0, 0, 0, 1);
  5108. object item = src.Data[index];
  5109. // SL spits always out ZERO_ROTATION for anything other than
  5110. // strings or vectors. Although keys always return ZERO_ROTATION,
  5111. // it is currently difficult to make the distinction between
  5112. // a string, a key as string and a string that by coincidence
  5113. // is a string, so we're going to leave that up to the
  5114. // LSL_Rotation constructor.
  5115. if (item.GetType() == typeof(LSL_Rotation))
  5116. return (LSL_Rotation)item;
  5117. if (item is LSL_String)
  5118. return new LSL_Rotation(src.Data[index].ToString());
  5119. return new LSL_Rotation(0, 0, 0, 1);
  5120. }
  5121. public LSL_List llList2List(LSL_List src, int start, int end)
  5122. {
  5123. m_host.AddScriptLPS(1);
  5124. return src.GetSublist(start, end);
  5125. }
  5126. public LSL_List llDeleteSubList(LSL_List src, int start, int end)
  5127. {
  5128. return src.DeleteSublist(start, end);
  5129. }
  5130. public LSL_Integer llGetListEntryType(LSL_List src, int index)
  5131. {
  5132. m_host.AddScriptLPS(1);
  5133. if (index < 0)
  5134. {
  5135. index = src.Length + index;
  5136. }
  5137. if (index >= src.Length)
  5138. {
  5139. return 0;
  5140. }
  5141. if (src.Data[index] is LSL_Integer || src.Data[index] is Int32)
  5142. return 1;
  5143. if (src.Data[index] is LSL_Float || src.Data[index] is Single || src.Data[index] is Double)
  5144. return 2;
  5145. if (src.Data[index] is LSL_String || src.Data[index] is String)
  5146. {
  5147. UUID tuuid;
  5148. if (UUID.TryParse(src.Data[index].ToString(), out tuuid))
  5149. {
  5150. return 4;
  5151. }
  5152. else
  5153. {
  5154. return 3;
  5155. }
  5156. }
  5157. if (src.Data[index] is LSL_Vector)
  5158. return 5;
  5159. if (src.Data[index] is LSL_Rotation)
  5160. return 6;
  5161. if (src.Data[index] is LSL_List)
  5162. return 7;
  5163. return 0;
  5164. }
  5165. /// <summary>
  5166. /// Process the supplied list and return the
  5167. /// content of the list formatted as a comma
  5168. /// separated list. There is a space after
  5169. /// each comma.
  5170. /// </summary>
  5171. public LSL_String llList2CSV(LSL_List src)
  5172. {
  5173. m_host.AddScriptLPS(1);
  5174. return string.Join(", ",
  5175. (new List<object>(src.Data)).ConvertAll<string>(o =>
  5176. {
  5177. return o.ToString();
  5178. }).ToArray());
  5179. }
  5180. /// <summary>
  5181. /// The supplied string is scanned for commas
  5182. /// and converted into a list. Commas are only
  5183. /// effective if they are encountered outside
  5184. /// of '<' '>' delimiters. Any whitespace
  5185. /// before or after an element is trimmed.
  5186. /// </summary>
  5187. public LSL_List llCSV2List(string src)
  5188. {
  5189. LSL_List result = new LSL_List();
  5190. int parens = 0;
  5191. int start = 0;
  5192. int length = 0;
  5193. m_host.AddScriptLPS(1);
  5194. for (int i = 0; i < src.Length; i++)
  5195. {
  5196. switch (src[i])
  5197. {
  5198. case '<':
  5199. parens++;
  5200. length++;
  5201. break;
  5202. case '>':
  5203. if (parens > 0)
  5204. parens--;
  5205. length++;
  5206. break;
  5207. case ',':
  5208. if (parens == 0)
  5209. {
  5210. result.Add(new LSL_String(src.Substring(start,length).Trim()));
  5211. start += length+1;
  5212. length = 0;
  5213. }
  5214. else
  5215. {
  5216. length++;
  5217. }
  5218. break;
  5219. default:
  5220. length++;
  5221. break;
  5222. }
  5223. }
  5224. result.Add(new LSL_String(src.Substring(start,length).Trim()));
  5225. return result;
  5226. }
  5227. /// <summary>
  5228. /// Randomizes the list, be arbitrarily reordering
  5229. /// sublists of stride elements. As the stride approaches
  5230. /// the size of the list, the options become very
  5231. /// limited.
  5232. /// </summary>
  5233. /// <remarks>
  5234. /// This could take a while for very large list
  5235. /// sizes.
  5236. /// </remarks>
  5237. public LSL_List llListRandomize(LSL_List src, int stride)
  5238. {
  5239. LSL_List result;
  5240. BetterRandom rand = new BetterRandom();
  5241. int chunkk;
  5242. int[] chunks;
  5243. m_host.AddScriptLPS(1);
  5244. if (stride <= 0)
  5245. {
  5246. stride = 1;
  5247. }
  5248. // Stride MUST be a factor of the list length
  5249. // If not, then return the src list. This also
  5250. // traps those cases where stride > length.
  5251. if (src.Length != stride && src.Length % stride == 0)
  5252. {
  5253. chunkk = src.Length/stride;
  5254. chunks = new int[chunkk];
  5255. for (int i = 0; i < chunkk; i++)
  5256. {
  5257. chunks[i] = i;
  5258. }
  5259. // Knuth shuffle the chunkk index
  5260. for (int i = chunkk - 1; i > 0; i--)
  5261. {
  5262. // Elect an unrandomized chunk to swap
  5263. int index = rand.Next(i + 1);
  5264. // and swap position with first unrandomized chunk
  5265. int tmp = chunks[i];
  5266. chunks[i] = chunks[index];
  5267. chunks[index] = tmp;
  5268. }
  5269. // Construct the randomized list
  5270. result = new LSL_List();
  5271. for (int i = 0; i < chunkk; i++)
  5272. {
  5273. for (int j = 0; j < stride; j++)
  5274. {
  5275. result.Add(src.Data[chunks[i] * stride + j]);
  5276. }
  5277. }
  5278. }
  5279. else
  5280. {
  5281. object[] array = new object[src.Length];
  5282. Array.Copy(src.Data, 0, array, 0, src.Length);
  5283. result = new LSL_List(array);
  5284. }
  5285. return result;
  5286. }
  5287. /// <summary>
  5288. /// Elements in the source list starting with 0 and then
  5289. /// every i+stride. If the stride is negative then the scan
  5290. /// is backwards producing an inverted result.
  5291. /// Only those elements that are also in the specified
  5292. /// range are included in the result.
  5293. /// </summary>
  5294. public LSL_List llList2ListStrided(LSL_List src, int start, int end, int stride)
  5295. {
  5296. LSL_List result = new LSL_List();
  5297. int[] si = new int[2];
  5298. int[] ei = new int[2];
  5299. bool twopass = false;
  5300. m_host.AddScriptLPS(1);
  5301. // First step is always to deal with negative indices
  5302. if (start < 0)
  5303. start = src.Length+start;
  5304. if (end < 0)
  5305. end = src.Length+end;
  5306. // Out of bounds indices are OK, just trim them
  5307. // accordingly
  5308. if (start > src.Length)
  5309. start = src.Length;
  5310. if (end > src.Length)
  5311. end = src.Length;
  5312. if (stride == 0)
  5313. stride = 1;
  5314. // There may be one or two ranges to be considered
  5315. if (start != end)
  5316. {
  5317. if (start <= end)
  5318. {
  5319. si[0] = start;
  5320. ei[0] = end;
  5321. }
  5322. else
  5323. {
  5324. si[1] = start;
  5325. ei[1] = src.Length;
  5326. si[0] = 0;
  5327. ei[0] = end;
  5328. twopass = true;
  5329. }
  5330. // The scan always starts from the beginning of the
  5331. // source list, but members are only selected if they
  5332. // fall within the specified sub-range. The specified
  5333. // range values are inclusive.
  5334. // A negative stride reverses the direction of the
  5335. // scan producing an inverted list as a result.
  5336. if (stride > 0)
  5337. {
  5338. for (int i = 0; i < src.Length; i += stride)
  5339. {
  5340. if (i<=ei[0] && i>=si[0])
  5341. result.Add(src.Data[i]);
  5342. if (twopass && i>=si[1] && i<=ei[1])
  5343. result.Add(src.Data[i]);
  5344. }
  5345. }
  5346. else if (stride < 0)
  5347. {
  5348. for (int i = src.Length - 1; i >= 0; i += stride)
  5349. {
  5350. if (i <= ei[0] && i >= si[0])
  5351. result.Add(src.Data[i]);
  5352. if (twopass && i >= si[1] && i <= ei[1])
  5353. result.Add(src.Data[i]);
  5354. }
  5355. }
  5356. }
  5357. else
  5358. {
  5359. if (start%stride == 0)
  5360. {
  5361. result.Add(src.Data[start]);
  5362. }
  5363. }
  5364. return result;
  5365. }
  5366. public LSL_Integer llGetRegionAgentCount()
  5367. {
  5368. m_host.AddScriptLPS(1);
  5369. int count = 0;
  5370. World.ForEachRootScenePresence(delegate(ScenePresence sp) {
  5371. count++;
  5372. });
  5373. return new LSL_Integer(count);
  5374. }
  5375. public LSL_Vector llGetRegionCorner()
  5376. {
  5377. m_host.AddScriptLPS(1);
  5378. return new LSL_Vector(World.RegionInfo.WorldLocX, World.RegionInfo.WorldLocY, 0);
  5379. }
  5380. public LSL_String llGetEnv(LSL_String name)
  5381. {
  5382. m_host.AddScriptLPS(1);
  5383. if (name == "agent_limit")
  5384. {
  5385. return World.RegionInfo.RegionSettings.AgentLimit.ToString();
  5386. }
  5387. else if (name == "dynamic_pathfinding")
  5388. {
  5389. return "0";
  5390. }
  5391. else if (name == "estate_id")
  5392. {
  5393. return World.RegionInfo.EstateSettings.EstateID.ToString();
  5394. }
  5395. else if (name == "estate_name")
  5396. {
  5397. return World.RegionInfo.EstateSettings.EstateName;
  5398. }
  5399. else if (name == "frame_number")
  5400. {
  5401. return World.Frame.ToString();
  5402. }
  5403. else if (name == "region_cpu_ratio")
  5404. {
  5405. return "1";
  5406. }
  5407. else if (name == "region_idle")
  5408. {
  5409. return "0";
  5410. }
  5411. else if (name == "region_product_name")
  5412. {
  5413. if (World.RegionInfo.RegionType != String.Empty)
  5414. return World.RegionInfo.RegionType;
  5415. else
  5416. return "";
  5417. }
  5418. else if (name == "region_product_sku")
  5419. {
  5420. return "OpenSim";
  5421. }
  5422. else if (name == "region_start_time")
  5423. {
  5424. return World.UnixStartTime.ToString();
  5425. }
  5426. else if (name == "sim_channel")
  5427. {
  5428. return "OpenSim";
  5429. }
  5430. else if (name == "sim_version")
  5431. {
  5432. return World.GetSimulatorVersion();
  5433. }
  5434. else if (name == "simulator_hostname")
  5435. {
  5436. IUrlModule UrlModule = World.RequestModuleInterface<IUrlModule>();
  5437. return UrlModule.ExternalHostNameForLSL;
  5438. }
  5439. else if (name == "region_max_prims")
  5440. {
  5441. return World.RegionInfo.ObjectCapacity.ToString();
  5442. }
  5443. else if (name == "region_object_bonus")
  5444. {
  5445. return World.RegionInfo.RegionSettings.ObjectBonus.ToString();
  5446. }
  5447. else
  5448. {
  5449. return "";
  5450. }
  5451. }
  5452. /// <summary>
  5453. /// Insert the list identified by <paramref name="src"/> into the
  5454. /// list designated by <paramref name="dest"/> such that the first
  5455. /// new element has the index specified by <paramref name="index"/>
  5456. /// </summary>
  5457. public LSL_List llListInsertList(LSL_List dest, LSL_List src, int index)
  5458. {
  5459. LSL_List pref;
  5460. LSL_List suff;
  5461. m_host.AddScriptLPS(1);
  5462. if (index < 0)
  5463. {
  5464. index = index+dest.Length;
  5465. if (index < 0)
  5466. {
  5467. index = 0;
  5468. }
  5469. }
  5470. if (index != 0)
  5471. {
  5472. pref = dest.GetSublist(0,index-1);
  5473. if (index < dest.Length)
  5474. {
  5475. suff = dest.GetSublist(index,-1);
  5476. return pref + src + suff;
  5477. }
  5478. else
  5479. {
  5480. return pref + src;
  5481. }
  5482. }
  5483. else
  5484. {
  5485. if (index < dest.Length)
  5486. {
  5487. suff = dest.GetSublist(index,-1);
  5488. return src + suff;
  5489. }
  5490. else
  5491. {
  5492. return src;
  5493. }
  5494. }
  5495. }
  5496. /// <summary>
  5497. /// Returns the index of the first occurrence of test
  5498. /// in src.
  5499. /// </summary>
  5500. /// <param name="src">Source list</param>
  5501. /// <param name="test">List to search for</param>
  5502. /// <returns>
  5503. /// The index number of the point in src where test was found if it was found.
  5504. /// Otherwise returns -1
  5505. /// </returns>
  5506. public LSL_Integer llListFindList(LSL_List src, LSL_List test)
  5507. {
  5508. int index = -1;
  5509. int length = src.Length - test.Length + 1;
  5510. m_host.AddScriptLPS(1);
  5511. // If either list is empty, do not match
  5512. if (src.Length != 0 && test.Length != 0)
  5513. {
  5514. for (int i = 0; i < length; i++)
  5515. {
  5516. int needle = llGetListEntryType(test, 0).value;
  5517. int haystack = llGetListEntryType(src, i).value;
  5518. // Why this piece of insanity? This is because most script constants are C# value types (e.g. int)
  5519. // rather than wrapped LSL types. Such a script constant does not have int.Equal(LSL_Integer) code
  5520. // and so the comparison fails even if the LSL_Integer conceptually has the same value.
  5521. // Therefore, here we test Equals on both the source and destination objects.
  5522. // However, a future better approach may be use LSL struct script constants (e.g. LSL_Integer(1)).
  5523. if ((needle == haystack) && (src.Data[i].Equals(test.Data[0]) || test.Data[0].Equals(src.Data[i])))
  5524. {
  5525. int j;
  5526. for (j = 1; j < test.Length; j++)
  5527. {
  5528. needle = llGetListEntryType(test, j).value;
  5529. haystack = llGetListEntryType(src, i+j).value;
  5530. if ((needle != haystack) || (!(src.Data[i+j].Equals(test.Data[j]) || test.Data[j].Equals(src.Data[i+j]))))
  5531. break;
  5532. }
  5533. if (j == test.Length)
  5534. {
  5535. index = i;
  5536. break;
  5537. }
  5538. }
  5539. }
  5540. }
  5541. return index;
  5542. }
  5543. public LSL_String llGetObjectName()
  5544. {
  5545. m_host.AddScriptLPS(1);
  5546. return m_host.Name !=null ? m_host.Name : String.Empty;
  5547. }
  5548. public void llSetObjectName(string name)
  5549. {
  5550. m_host.AddScriptLPS(1);
  5551. m_host.Name = name != null ? name : String.Empty;
  5552. }
  5553. public LSL_String llGetDate()
  5554. {
  5555. m_host.AddScriptLPS(1);
  5556. DateTime date = DateTime.Now.ToUniversalTime();
  5557. string result = date.ToString("yyyy-MM-dd");
  5558. return result;
  5559. }
  5560. public LSL_Integer llEdgeOfWorld(LSL_Vector pos, LSL_Vector dir)
  5561. {
  5562. m_host.AddScriptLPS(1);
  5563. if(dir.x == 0 && dir.y == 0)
  5564. return 1; // SL wiki
  5565. float rsx = World.RegionInfo.RegionSizeX;
  5566. float rsy = World.RegionInfo.RegionSizeY;
  5567. // can understand what sl does if position is not in region, so do something :)
  5568. float px = (float)Util.Clamp(pos.x, 0.5, rsx - 0.5);
  5569. float py = (float)Util.Clamp(pos.y, 0.5, rsy - 0.5);
  5570. float ex, ey;
  5571. if (dir.x == 0)
  5572. {
  5573. ex = px;
  5574. ey = dir.y > 0 ? rsy + 1.0f : -1.0f;
  5575. }
  5576. else if(dir.y == 0)
  5577. {
  5578. ex = dir.x > 0 ? rsx + 1.0f : -1.0f;
  5579. ey = py;
  5580. }
  5581. else
  5582. {
  5583. float dx = (float) dir.x;
  5584. float dy = (float) dir.y;
  5585. float t1 = dx * dx + dy * dy;
  5586. t1 = (float)Math.Sqrt(t1);
  5587. dx /= t1;
  5588. dy /= t1;
  5589. if(dx > 0)
  5590. t1 = (rsx + 1f - px)/dx;
  5591. else
  5592. t1 = -(px + 1f)/dx;
  5593. float t2;
  5594. if(dy > 0)
  5595. t2 = (rsy + 1f - py)/dy;
  5596. else
  5597. t2 = -(py + 1f)/dy;
  5598. if(t1 > t2)
  5599. t1 = t2;
  5600. ex = px + t1 * dx;
  5601. ey = py + t1 * dy;
  5602. }
  5603. ex += World.RegionInfo.WorldLocX;
  5604. ey += World.RegionInfo.WorldLocY;
  5605. if(World.GridService.GetRegionByPosition(World.RegionInfo.ScopeID, (int)ex, (int)ey) != null)
  5606. return 0;
  5607. return 1;
  5608. }
  5609. /// <summary>
  5610. /// Not fully implemented yet. Still to do:-
  5611. /// AGENT_BUSY
  5612. /// Remove as they are done
  5613. /// </summary>
  5614. public LSL_Integer llGetAgentInfo(string id)
  5615. {
  5616. m_host.AddScriptLPS(1);
  5617. UUID key = new UUID();
  5618. if (!UUID.TryParse(id, out key))
  5619. {
  5620. return 0;
  5621. }
  5622. int flags = 0;
  5623. ScenePresence agent = World.GetScenePresence(key);
  5624. if (agent == null)
  5625. {
  5626. return 0;
  5627. }
  5628. if (agent.IsChildAgent)
  5629. return 0; // Fail if they are not in the same region
  5630. // note: in OpenSim, sitting seems to cancel AGENT_ALWAYS_RUN, unlike SL
  5631. if (agent.SetAlwaysRun)
  5632. {
  5633. flags |= ScriptBaseClass.AGENT_ALWAYS_RUN;
  5634. }
  5635. if (agent.HasAttachments())
  5636. {
  5637. flags |= ScriptBaseClass.AGENT_ATTACHMENTS;
  5638. if (agent.HasScriptedAttachments())
  5639. flags |= ScriptBaseClass.AGENT_SCRIPTED;
  5640. }
  5641. if ((agent.AgentControlFlags & (uint)AgentManager.ControlFlags.AGENT_CONTROL_FLY) != 0)
  5642. {
  5643. flags |= ScriptBaseClass.AGENT_FLYING;
  5644. flags |= ScriptBaseClass.AGENT_IN_AIR; // flying always implies in-air, even if colliding with e.g. a wall
  5645. }
  5646. if ((agent.AgentControlFlags & (uint)AgentManager.ControlFlags.AGENT_CONTROL_AWAY) != 0)
  5647. {
  5648. flags |= ScriptBaseClass.AGENT_AWAY;
  5649. }
  5650. UUID busy = new UUID("efcf670c-2d18-8128-973a-034ebc806b67");
  5651. UUID[] anims = agent.Animator.GetAnimationArray();
  5652. if (Array.Exists<UUID>(anims, a => { return a == busy; }))
  5653. {
  5654. flags |= ScriptBaseClass.AGENT_BUSY;
  5655. }
  5656. // seems to get unset, even if in mouselook, when avatar is sitting on a prim???
  5657. if ((agent.AgentControlFlags & (uint)AgentManager.ControlFlags.AGENT_CONTROL_MOUSELOOK) != 0)
  5658. {
  5659. flags |= ScriptBaseClass.AGENT_MOUSELOOK;
  5660. }
  5661. if ((agent.State & (byte)AgentState.Typing) != (byte)0)
  5662. {
  5663. flags |= ScriptBaseClass.AGENT_TYPING;
  5664. }
  5665. string agentMovementAnimation = agent.Animator.CurrentMovementAnimation;
  5666. if (agentMovementAnimation == "CROUCH")
  5667. {
  5668. flags |= ScriptBaseClass.AGENT_CROUCHING;
  5669. }
  5670. if (agentMovementAnimation == "WALK" || agentMovementAnimation == "CROUCHWALK")
  5671. {
  5672. flags |= ScriptBaseClass.AGENT_WALKING;
  5673. }
  5674. // not colliding implies in air. Note: flying also implies in-air, even if colliding (see above)
  5675. // note: AGENT_IN_AIR and AGENT_WALKING seem to be mutually exclusive states in SL.
  5676. // note: this may need some tweaking when walking downhill. you "fall down" for a brief instant
  5677. // and don't collide when walking downhill, which instantly registers as in-air, briefly. should
  5678. // there be some minimum non-collision threshold time before claiming the avatar is in-air?
  5679. if ((flags & ScriptBaseClass.AGENT_WALKING) == 0 && !agent.IsColliding )
  5680. {
  5681. flags |= ScriptBaseClass.AGENT_IN_AIR;
  5682. }
  5683. if (agent.ParentPart != null)
  5684. {
  5685. flags |= ScriptBaseClass.AGENT_ON_OBJECT;
  5686. flags |= ScriptBaseClass.AGENT_SITTING;
  5687. }
  5688. if (agent.Animator.Animations.ImplicitDefaultAnimation.AnimID
  5689. == DefaultAvatarAnimations.AnimsUUID["SIT_GROUND_CONSTRAINED"])
  5690. {
  5691. flags |= ScriptBaseClass.AGENT_SITTING;
  5692. }
  5693. if (agent.Appearance.VisualParams[(int)AvatarAppearance.VPElement.SHAPE_MALE] > 0)
  5694. {
  5695. flags |= ScriptBaseClass.AGENT_MALE;
  5696. }
  5697. return flags;
  5698. }
  5699. public LSL_String llGetAgentLanguage(string id)
  5700. {
  5701. // This should only return a value if the avatar is in the same region, but eh. idc.
  5702. m_host.AddScriptLPS(1);
  5703. if (World.AgentPreferencesService == null)
  5704. {
  5705. Error("llGetAgentLanguage", "No AgentPreferencesService present");
  5706. }
  5707. else
  5708. {
  5709. UUID key = new UUID();
  5710. if (UUID.TryParse(id, out key))
  5711. {
  5712. return new LSL_String(World.AgentPreferencesService.GetLang(key));
  5713. }
  5714. }
  5715. return new LSL_String("en-us");
  5716. }
  5717. /// <summary>
  5718. /// http://wiki.secondlife.com/wiki/LlGetAgentList
  5719. /// The list of options is currently not used in SL
  5720. /// scope is one of:-
  5721. /// AGENT_LIST_REGION - all in the region
  5722. /// AGENT_LIST_PARCEL - all in the same parcel as the scripted object
  5723. /// AGENT_LIST_PARCEL_OWNER - all in any parcel owned by the owner of the
  5724. /// current parcel.
  5725. /// AGENT_LIST_EXCLUDENPC ignore NPCs (bit mask)
  5726. /// </summary>
  5727. public LSL_List llGetAgentList(LSL_Integer scope, LSL_List options)
  5728. {
  5729. m_host.AddScriptLPS(1);
  5730. // do our bit masks part
  5731. bool noNPC = (scope & ScriptBaseClass.AGENT_LIST_EXCLUDENPC) !=0;
  5732. // remove bit masks part
  5733. scope &= ~ ScriptBaseClass.AGENT_LIST_EXCLUDENPC;
  5734. // the constants are 1, 2 and 4 so bits are being set, but you
  5735. // get an error "INVALID_SCOPE" if it is anything but 1, 2 and 4
  5736. bool regionWide = scope == ScriptBaseClass.AGENT_LIST_REGION;
  5737. bool parcelOwned = scope == ScriptBaseClass.AGENT_LIST_PARCEL_OWNER;
  5738. bool parcel = scope == ScriptBaseClass.AGENT_LIST_PARCEL;
  5739. LSL_List result = new LSL_List();
  5740. if (!regionWide && !parcelOwned && !parcel)
  5741. {
  5742. result.Add("INVALID_SCOPE");
  5743. return result;
  5744. }
  5745. ILandObject land;
  5746. UUID id = UUID.Zero;
  5747. if (parcel || parcelOwned)
  5748. {
  5749. land = World.LandChannel.GetLandObject(m_host.ParentGroup.RootPart.GetWorldPosition());
  5750. if (land == null)
  5751. {
  5752. id = UUID.Zero;
  5753. }
  5754. else
  5755. {
  5756. if (parcelOwned)
  5757. {
  5758. id = land.LandData.OwnerID;
  5759. }
  5760. else
  5761. {
  5762. id = land.LandData.GlobalID;
  5763. }
  5764. }
  5765. }
  5766. World.ForEachRootScenePresence(
  5767. delegate (ScenePresence ssp)
  5768. {
  5769. if(noNPC && ssp.IsNPC)
  5770. return;
  5771. // Gods are not listed in SL
  5772. if (!ssp.IsDeleted && !ssp.IsViewerUIGod && !ssp.IsChildAgent)
  5773. {
  5774. if (!regionWide)
  5775. {
  5776. land = World.LandChannel.GetLandObject(ssp.AbsolutePosition);
  5777. if (land != null)
  5778. {
  5779. if (parcelOwned && land.LandData.OwnerID == id ||
  5780. parcel && land.LandData.GlobalID == id)
  5781. {
  5782. result.Add(new LSL_Key(ssp.UUID.ToString()));
  5783. }
  5784. }
  5785. }
  5786. else
  5787. {
  5788. result.Add(new LSL_Key(ssp.UUID.ToString()));
  5789. }
  5790. }
  5791. // Maximum of 100 results
  5792. if (result.Length > 99)
  5793. {
  5794. return;
  5795. }
  5796. }
  5797. );
  5798. return result;
  5799. }
  5800. public void llAdjustSoundVolume(double volume)
  5801. {
  5802. m_host.AddScriptLPS(1);
  5803. m_host.AdjustSoundGain(volume);
  5804. ScriptSleep(m_sleepMsOnAdjustSoundVolume);
  5805. }
  5806. public void llSetSoundRadius(double radius)
  5807. {
  5808. m_host.AddScriptLPS(1);
  5809. m_host.SoundRadius = radius;
  5810. }
  5811. public LSL_String llKey2Name(string id)
  5812. {
  5813. m_host.AddScriptLPS(1);
  5814. UUID key = new UUID();
  5815. if (UUID.TryParse(id,out key))
  5816. {
  5817. ScenePresence presence = World.GetScenePresence(key);
  5818. if (presence != null)
  5819. {
  5820. return presence.ControllingClient.Name;
  5821. //return presence.Name;
  5822. }
  5823. if (World.GetSceneObjectPart(key) != null)
  5824. {
  5825. return World.GetSceneObjectPart(key).Name;
  5826. }
  5827. }
  5828. return String.Empty;
  5829. }
  5830. public LSL_Key llName2Key(LSL_String name)
  5831. {
  5832. m_host.AddScriptLPS(1);
  5833. foreach (ScenePresence sp in World.GetScenePresences())
  5834. {
  5835. if (sp.IsDeleted || sp.IsChildAgent)
  5836. continue;
  5837. string test = sp.ControllingClient.Name;
  5838. if (!name.Contains(" "))
  5839. test = test.Replace(" ", ".");
  5840. if (String.Compare(name, test, true) == 0)
  5841. return sp.UUID.ToString();
  5842. }
  5843. return UUID.Zero.ToString();
  5844. }
  5845. public void llSetTextureAnim(int mode, int face, int sizex, int sizey, double start, double length, double rate)
  5846. {
  5847. m_host.AddScriptLPS(1);
  5848. SetTextureAnim(m_host, mode, face, sizex, sizey, start, length, rate);
  5849. }
  5850. public void llSetLinkTextureAnim(int linknumber, int mode, int face, int sizex, int sizey, double start, double length, double rate)
  5851. {
  5852. m_host.AddScriptLPS(1);
  5853. List<SceneObjectPart> parts = GetLinkParts(linknumber);
  5854. try
  5855. {
  5856. foreach (SceneObjectPart part in parts)
  5857. {
  5858. SetTextureAnim(part, mode, face, sizex, sizey, start, length, rate);
  5859. }
  5860. }
  5861. finally
  5862. {
  5863. }
  5864. }
  5865. private void SetTextureAnim(SceneObjectPart part, int mode, int face, int sizex, int sizey, double start, double length, double rate)
  5866. {
  5867. Primitive.TextureAnimation pTexAnim = new Primitive.TextureAnimation();
  5868. pTexAnim.Flags = (Primitive.TextureAnimMode)mode;
  5869. //ALL_SIDES
  5870. if (face == ScriptBaseClass.ALL_SIDES)
  5871. face = 255;
  5872. pTexAnim.Face = (uint)face;
  5873. pTexAnim.Length = (float)length;
  5874. pTexAnim.Rate = (float)rate;
  5875. pTexAnim.SizeX = (uint)sizex;
  5876. pTexAnim.SizeY = (uint)sizey;
  5877. pTexAnim.Start = (float)start;
  5878. part.AddTextureAnimation(pTexAnim);
  5879. part.SendFullUpdateToAllClients();
  5880. part.ParentGroup.HasGroupChanged = true;
  5881. }
  5882. public void llTriggerSoundLimited(string sound, double volume, LSL_Vector top_north_east,
  5883. LSL_Vector bottom_south_west)
  5884. {
  5885. m_host.AddScriptLPS(1);
  5886. if (m_SoundModule != null)
  5887. {
  5888. m_SoundModule.TriggerSoundLimited(m_host.UUID,
  5889. ScriptUtils.GetAssetIdFromKeyOrItemName(m_host, sound, AssetType.Sound), volume,
  5890. bottom_south_west, top_north_east);
  5891. }
  5892. }
  5893. public void llEjectFromLand(LSL_Key pest)
  5894. {
  5895. m_host.AddScriptLPS(1);
  5896. UUID agentID = new UUID();
  5897. if (UUID.TryParse(pest, out agentID))
  5898. {
  5899. ScenePresence presence = World.GetScenePresence(agentID);
  5900. if (presence != null)
  5901. {
  5902. // agent must be over the owners land
  5903. ILandObject land = World.LandChannel.GetLandObject(presence.AbsolutePosition);
  5904. if (land == null)
  5905. return;
  5906. if (m_host.OwnerID == land.LandData.OwnerID)
  5907. {
  5908. Vector3 p = World.GetNearestAllowedPosition(presence, land);
  5909. presence.TeleportOnEject(p);
  5910. presence.ControllingClient.SendAlertMessage("You have been ejected from this land");
  5911. }
  5912. }
  5913. }
  5914. ScriptSleep(m_sleepMsOnEjectFromLand);
  5915. }
  5916. public LSL_List llParseString2List(string str, LSL_List separators, LSL_List in_spacers)
  5917. {
  5918. return ParseString2List(str, separators, in_spacers, false);
  5919. }
  5920. public LSL_Integer llOverMyLand(string id)
  5921. {
  5922. m_host.AddScriptLPS(1);
  5923. UUID key = new UUID();
  5924. if (UUID.TryParse(id, out key))
  5925. {
  5926. try
  5927. {
  5928. ScenePresence presence = World.GetScenePresence(key);
  5929. if (presence != null) // object is an avatar
  5930. {
  5931. if (m_host.OwnerID == World.LandChannel.GetLandObject(presence.AbsolutePosition).LandData.OwnerID)
  5932. return 1;
  5933. }
  5934. else // object is not an avatar
  5935. {
  5936. SceneObjectPart obj = World.GetSceneObjectPart(key);
  5937. if (obj != null &&
  5938. m_host.OwnerID == World.LandChannel.GetLandObject(obj.AbsolutePosition).LandData.OwnerID)
  5939. return 1;
  5940. }
  5941. }
  5942. catch { }
  5943. }
  5944. return 0;
  5945. }
  5946. public LSL_Key llGetLandOwnerAt(LSL_Vector pos)
  5947. {
  5948. m_host.AddScriptLPS(1);
  5949. ILandObject land = World.LandChannel.GetLandObject((float)pos.x, (float)pos.y);
  5950. if (land == null)
  5951. return UUID.Zero.ToString();
  5952. return land.LandData.OwnerID.ToString();
  5953. }
  5954. /// <summary>
  5955. /// According to http://lslwiki.net/lslwiki/wakka.php?wakka=llGetAgentSize
  5956. /// only the height of avatars vary and that says:
  5957. /// Width (x) and depth (y) are constant. (0.45m and 0.6m respectively).
  5958. /// </summary>
  5959. public LSL_Vector llGetAgentSize(string id)
  5960. {
  5961. m_host.AddScriptLPS(1);
  5962. ScenePresence avatar = World.GetScenePresence((UUID)id);
  5963. LSL_Vector agentSize;
  5964. if (avatar == null || avatar.IsChildAgent) // Fail if not in the same region
  5965. {
  5966. agentSize = ScriptBaseClass.ZERO_VECTOR;
  5967. }
  5968. else
  5969. {
  5970. // agentSize = new LSL_Vector(0.45f, 0.6f, avatar.Appearance.AvatarHeight);
  5971. Vector3 s = avatar.Appearance.AvatarSize;
  5972. agentSize = new LSL_Vector(s.X, s.Y, s.Z);
  5973. }
  5974. return agentSize;
  5975. }
  5976. public LSL_Integer llSameGroup(string id)
  5977. {
  5978. m_host.AddScriptLPS(1);
  5979. UUID uuid = new UUID();
  5980. if (!UUID.TryParse(id, out uuid))
  5981. return new LSL_Integer(0);
  5982. // Check if it's a group key
  5983. if (uuid == m_host.ParentGroup.RootPart.GroupID)
  5984. return new LSL_Integer(1);
  5985. // Handle object case
  5986. SceneObjectPart part = World.GetSceneObjectPart(uuid);
  5987. if (part != null)
  5988. {
  5989. if(part.ParentGroup.IsAttachment)
  5990. {
  5991. uuid = part.ParentGroup.AttachedAvatar;
  5992. }
  5993. else
  5994. {
  5995. // This will handle both deed and non-deed and also the no
  5996. // group case
  5997. if (part.ParentGroup.RootPart.GroupID == m_host.ParentGroup.RootPart.GroupID)
  5998. return new LSL_Integer(1);
  5999. return new LSL_Integer(0);
  6000. }
  6001. }
  6002. // Handle the case where id names an avatar
  6003. ScenePresence presence = World.GetScenePresence(uuid);
  6004. if (presence != null)
  6005. {
  6006. if (presence.IsChildAgent)
  6007. return new LSL_Integer(0);
  6008. IClientAPI client = presence.ControllingClient;
  6009. if (m_host.ParentGroup.RootPart.GroupID == client.ActiveGroupId)
  6010. return new LSL_Integer(1);
  6011. return new LSL_Integer(0);
  6012. }
  6013. return new LSL_Integer(0);
  6014. }
  6015. public void llUnSit(string id)
  6016. {
  6017. m_host.AddScriptLPS(1);
  6018. UUID key = new UUID();
  6019. if (UUID.TryParse(id, out key))
  6020. {
  6021. ScenePresence av = World.GetScenePresence(key);
  6022. List<ScenePresence> sittingAvatars = m_host.ParentGroup.GetSittingAvatars();
  6023. if (av != null)
  6024. {
  6025. if (sittingAvatars.Contains(av))
  6026. {
  6027. // if the avatar is sitting on this object, then
  6028. // we can unsit them. We don't want random scripts unsitting random people
  6029. // Lets avoid the popcorn avatar scenario.
  6030. av.StandUp();
  6031. }
  6032. else
  6033. {
  6034. // If the object owner also owns the parcel
  6035. // or
  6036. // if the land is group owned and the object is group owned by the same group
  6037. // or
  6038. // if the object is owned by a person with estate access.
  6039. ILandObject parcel = World.LandChannel.GetLandObject(av.AbsolutePosition);
  6040. if (parcel != null)
  6041. {
  6042. if (m_host.OwnerID == parcel.LandData.OwnerID ||
  6043. (m_host.OwnerID == m_host.GroupID && m_host.GroupID == parcel.LandData.GroupID
  6044. && parcel.LandData.IsGroupOwned) || World.Permissions.IsGod(m_host.OwnerID))
  6045. {
  6046. av.StandUp();
  6047. }
  6048. }
  6049. }
  6050. }
  6051. }
  6052. }
  6053. public LSL_Vector llGroundSlope(LSL_Vector offset)
  6054. {
  6055. m_host.AddScriptLPS(1);
  6056. //Get the slope normal. This gives us the equation of the plane tangent to the slope.
  6057. LSL_Vector vsn = llGroundNormal(offset);
  6058. //Plug the x,y coordinates of the slope normal into the equation of the plane to get
  6059. //the height of that point on the plane. The resulting vector gives the slope.
  6060. Vector3 vsl = vsn;
  6061. vsl.Z = (float)(((vsn.x * vsn.x) + (vsn.y * vsn.y)) / (-1 * vsn.z));
  6062. vsl.Normalize();
  6063. //Normalization might be overkill here
  6064. vsn.x = vsl.X;
  6065. vsn.y = vsl.Y;
  6066. vsn.z = vsl.Z;
  6067. return vsn;
  6068. }
  6069. public LSL_Vector llGroundNormal(LSL_Vector offset)
  6070. {
  6071. m_host.AddScriptLPS(1);
  6072. Vector3 pos = m_host.GetWorldPosition() + (Vector3)offset;
  6073. // Clamp to valid position
  6074. if (pos.X < 0)
  6075. pos.X = 0;
  6076. else if (pos.X >= World.Heightmap.Width)
  6077. pos.X = World.Heightmap.Width - 1;
  6078. if (pos.Y < 0)
  6079. pos.Y = 0;
  6080. else if (pos.Y >= World.Heightmap.Height)
  6081. pos.Y = World.Heightmap.Height - 1;
  6082. //Find two points in addition to the position to define a plane
  6083. Vector3 p0 = new Vector3(pos.X, pos.Y,
  6084. (float)World.Heightmap[(int)pos.X, (int)pos.Y]);
  6085. Vector3 p1 = new Vector3();
  6086. Vector3 p2 = new Vector3();
  6087. if ((pos.X + 1.0f) >= World.Heightmap.Width)
  6088. p1 = new Vector3(pos.X + 1.0f, pos.Y,
  6089. (float)World.Heightmap[(int)pos.X, (int)pos.Y]);
  6090. else
  6091. p1 = new Vector3(pos.X + 1.0f, pos.Y,
  6092. (float)World.Heightmap[(int)(pos.X + 1.0f), (int)pos.Y]);
  6093. if ((pos.Y + 1.0f) >= World.Heightmap.Height)
  6094. p2 = new Vector3(pos.X, pos.Y + 1.0f,
  6095. (float)World.Heightmap[(int)pos.X, (int)pos.Y]);
  6096. else
  6097. p2 = new Vector3(pos.X, pos.Y + 1.0f,
  6098. (float)World.Heightmap[(int)pos.X, (int)(pos.Y + 1.0f)]);
  6099. //Find normalized vectors from p0 to p1 and p0 to p2
  6100. Vector3 v0 = new Vector3(p1.X - p0.X, p1.Y - p0.Y, p1.Z - p0.Z);
  6101. Vector3 v1 = new Vector3(p2.X - p0.X, p2.Y - p0.Y, p2.Z - p0.Z);
  6102. v0.Normalize();
  6103. v1.Normalize();
  6104. //Find the cross product of the vectors (the slope normal).
  6105. Vector3 vsn = new Vector3();
  6106. vsn.X = (v0.Y * v1.Z) - (v0.Z * v1.Y);
  6107. vsn.Y = (v0.Z * v1.X) - (v0.X * v1.Z);
  6108. vsn.Z = (v0.X * v1.Y) - (v0.Y * v1.X);
  6109. vsn.Normalize();
  6110. //I believe the crossproduct of two normalized vectors is a normalized vector so
  6111. //this normalization may be overkill
  6112. return new LSL_Vector(vsn);
  6113. }
  6114. public LSL_Vector llGroundContour(LSL_Vector offset)
  6115. {
  6116. m_host.AddScriptLPS(1);
  6117. LSL_Vector x = llGroundSlope(offset);
  6118. return new LSL_Vector(-x.y, x.x, 0.0);
  6119. }
  6120. public LSL_Integer llGetAttached()
  6121. {
  6122. m_host.AddScriptLPS(1);
  6123. return m_host.ParentGroup.AttachmentPoint;
  6124. }
  6125. public LSL_List llGetAttachedList(string id)
  6126. {
  6127. m_host.AddScriptLPS(1);
  6128. ScenePresence av = World.GetScenePresence((UUID)id);
  6129. if (av == null || av.IsDeleted)
  6130. return new LSL_List("NOT_FOUND");
  6131. if (av.IsChildAgent || av.IsInTransit)
  6132. return new LSL_List("NOT_ON_REGION");
  6133. LSL_List AttachmentsList = new LSL_List();
  6134. List<SceneObjectGroup> Attachments;
  6135. Attachments = av.GetAttachments();
  6136. foreach (SceneObjectGroup Attachment in Attachments)
  6137. {
  6138. if(Attachment.HasPrivateAttachmentPoint)
  6139. continue;
  6140. AttachmentsList.Add(new LSL_Key(Attachment.UUID.ToString()));
  6141. }
  6142. return AttachmentsList;
  6143. }
  6144. public virtual LSL_Integer llGetFreeMemory()
  6145. {
  6146. m_host.AddScriptLPS(1);
  6147. // Make scripts designed for Mono happy
  6148. return 65536;
  6149. }
  6150. public LSL_Integer llGetFreeURLs()
  6151. {
  6152. m_host.AddScriptLPS(1);
  6153. if (m_UrlModule != null)
  6154. return new LSL_Integer(m_UrlModule.GetFreeUrls());
  6155. return new LSL_Integer(0);
  6156. }
  6157. public LSL_String llGetRegionName()
  6158. {
  6159. m_host.AddScriptLPS(1);
  6160. return World.RegionInfo.RegionName;
  6161. }
  6162. public LSL_Float llGetRegionTimeDilation()
  6163. {
  6164. m_host.AddScriptLPS(1);
  6165. return (double)World.TimeDilation;
  6166. }
  6167. /// <summary>
  6168. /// Returns the value reported in the client Statistics window
  6169. /// </summary>
  6170. public LSL_Float llGetRegionFPS()
  6171. {
  6172. m_host.AddScriptLPS(1);
  6173. return World.StatsReporter.LastReportedSimFPS;
  6174. }
  6175. /* particle system rules should be coming into this routine as doubles, that is
  6176. rule[0] should be an integer from this list and rule[1] should be the arg
  6177. for the same integer. wiki.secondlife.com has most of this mapping, but some
  6178. came from http://www.caligari-designs.com/p4u2
  6179. We iterate through the list for 'Count' elements, incrementing by two for each
  6180. iteration and set the members of Primitive.ParticleSystem, one at a time.
  6181. */
  6182. public enum PrimitiveRule : int
  6183. {
  6184. PSYS_PART_FLAGS = 0,
  6185. PSYS_PART_START_COLOR = 1,
  6186. PSYS_PART_START_ALPHA = 2,
  6187. PSYS_PART_END_COLOR = 3,
  6188. PSYS_PART_END_ALPHA = 4,
  6189. PSYS_PART_START_SCALE = 5,
  6190. PSYS_PART_END_SCALE = 6,
  6191. PSYS_PART_MAX_AGE = 7,
  6192. PSYS_SRC_ACCEL = 8,
  6193. PSYS_SRC_PATTERN = 9,
  6194. PSYS_SRC_INNERANGLE = 10,
  6195. PSYS_SRC_OUTERANGLE = 11,
  6196. PSYS_SRC_TEXTURE = 12,
  6197. PSYS_SRC_BURST_RATE = 13,
  6198. PSYS_SRC_BURST_PART_COUNT = 15,
  6199. PSYS_SRC_BURST_RADIUS = 16,
  6200. PSYS_SRC_BURST_SPEED_MIN = 17,
  6201. PSYS_SRC_BURST_SPEED_MAX = 18,
  6202. PSYS_SRC_MAX_AGE = 19,
  6203. PSYS_SRC_TARGET_KEY = 20,
  6204. PSYS_SRC_OMEGA = 21,
  6205. PSYS_SRC_ANGLE_BEGIN = 22,
  6206. PSYS_SRC_ANGLE_END = 23,
  6207. PSYS_PART_BLEND_FUNC_SOURCE = 24,
  6208. PSYS_PART_BLEND_FUNC_DEST = 25,
  6209. PSYS_PART_START_GLOW = 26,
  6210. PSYS_PART_END_GLOW = 27
  6211. }
  6212. internal Primitive.ParticleSystem.ParticleDataFlags ConvertUINTtoFlags(uint flags)
  6213. {
  6214. Primitive.ParticleSystem.ParticleDataFlags returnval = Primitive.ParticleSystem.ParticleDataFlags.None;
  6215. return returnval;
  6216. }
  6217. protected Primitive.ParticleSystem getNewParticleSystemWithSLDefaultValues()
  6218. {
  6219. Primitive.ParticleSystem ps = new Primitive.ParticleSystem();
  6220. // TODO find out about the other defaults and add them here
  6221. ps.PartStartColor = new Color4(1.0f, 1.0f, 1.0f, 1.0f);
  6222. ps.PartEndColor = new Color4(1.0f, 1.0f, 1.0f, 1.0f);
  6223. ps.PartStartScaleX = 1.0f;
  6224. ps.PartStartScaleY = 1.0f;
  6225. ps.PartEndScaleX = 1.0f;
  6226. ps.PartEndScaleY = 1.0f;
  6227. ps.BurstSpeedMin = 1.0f;
  6228. ps.BurstSpeedMax = 1.0f;
  6229. ps.BurstRate = 0.1f;
  6230. ps.PartMaxAge = 10.0f;
  6231. ps.BurstPartCount = 1;
  6232. ps.BlendFuncSource = ScriptBaseClass.PSYS_PART_BF_SOURCE_ALPHA;
  6233. ps.BlendFuncDest = ScriptBaseClass.PSYS_PART_BF_ONE_MINUS_SOURCE_ALPHA;
  6234. ps.PartStartGlow = 0.0f;
  6235. ps.PartEndGlow = 0.0f;
  6236. return ps;
  6237. }
  6238. public void llLinkParticleSystem(int linknumber, LSL_List rules)
  6239. {
  6240. m_host.AddScriptLPS(1);
  6241. List<SceneObjectPart> parts = GetLinkParts(linknumber);
  6242. foreach (SceneObjectPart part in parts)
  6243. {
  6244. SetParticleSystem(part, rules, "llLinkParticleSystem");
  6245. }
  6246. }
  6247. public void llParticleSystem(LSL_List rules)
  6248. {
  6249. m_host.AddScriptLPS(1);
  6250. SetParticleSystem(m_host, rules, "llParticleSystem");
  6251. }
  6252. private void SetParticleSystem(SceneObjectPart part, LSL_List rules, string originFunc)
  6253. {
  6254. if (rules.Length == 0)
  6255. {
  6256. part.RemoveParticleSystem();
  6257. part.ParentGroup.HasGroupChanged = true;
  6258. }
  6259. else
  6260. {
  6261. Primitive.ParticleSystem prules = getNewParticleSystemWithSLDefaultValues();
  6262. LSL_Vector tempv = new LSL_Vector();
  6263. float tempf = 0;
  6264. int tmpi = 0;
  6265. for (int i = 0; i < rules.Length; i += 2)
  6266. {
  6267. int psystype;
  6268. try
  6269. {
  6270. psystype = rules.GetLSLIntegerItem(i);
  6271. }
  6272. catch (InvalidCastException)
  6273. {
  6274. Error(originFunc, string.Format("Error running particle system params index #{0}: particle system parameter type must be integer", i));
  6275. return;
  6276. }
  6277. switch (psystype)
  6278. {
  6279. case (int)ScriptBaseClass.PSYS_PART_FLAGS:
  6280. try
  6281. {
  6282. prules.PartDataFlags = (Primitive.ParticleSystem.ParticleDataFlags)(uint)rules.GetLSLIntegerItem(i + 1);
  6283. }
  6284. catch(InvalidCastException)
  6285. {
  6286. Error(originFunc, string.Format("Error running rule PSYS_PART_FLAGS: arg #{0} - parameter 1 must be integer", i + 1));
  6287. return;
  6288. }
  6289. break;
  6290. case (int)ScriptBaseClass.PSYS_PART_START_COLOR:
  6291. try
  6292. {
  6293. tempv = rules.GetVector3Item(i + 1);
  6294. }
  6295. catch(InvalidCastException)
  6296. {
  6297. Error(originFunc, string.Format("Error running rule PSYS_PART_START_COLOR: arg #{0} - parameter 1 must be vector", i + 1));
  6298. return;
  6299. }
  6300. prules.PartStartColor.R = (float)tempv.x;
  6301. prules.PartStartColor.G = (float)tempv.y;
  6302. prules.PartStartColor.B = (float)tempv.z;
  6303. break;
  6304. case (int)ScriptBaseClass.PSYS_PART_START_ALPHA:
  6305. try
  6306. {
  6307. tempf = (float)rules.GetLSLFloatItem(i + 1);
  6308. }
  6309. catch(InvalidCastException)
  6310. {
  6311. Error(originFunc, string.Format("Error running rule PSYS_PART_START_ALPHA: arg #{0} - parameter 1 must be float", i + 1));
  6312. return;
  6313. }
  6314. prules.PartStartColor.A = tempf;
  6315. break;
  6316. case (int)ScriptBaseClass.PSYS_PART_END_COLOR:
  6317. try
  6318. {
  6319. tempv = rules.GetVector3Item(i + 1);
  6320. }
  6321. catch(InvalidCastException)
  6322. {
  6323. Error(originFunc, string.Format("Error running rule PSYS_PART_END_COLOR: arg #{0} - parameter 1 must be vector", i + 1));
  6324. return;
  6325. }
  6326. prules.PartEndColor.R = (float)tempv.x;
  6327. prules.PartEndColor.G = (float)tempv.y;
  6328. prules.PartEndColor.B = (float)tempv.z;
  6329. break;
  6330. case (int)ScriptBaseClass.PSYS_PART_END_ALPHA:
  6331. try
  6332. {
  6333. tempf = (float)rules.GetLSLFloatItem(i + 1);
  6334. }
  6335. catch(InvalidCastException)
  6336. {
  6337. Error(originFunc, string.Format("Error running rule PSYS_PART_END_ALPHA: arg #{0} - parameter 1 must be float", i + 1));
  6338. return;
  6339. }
  6340. prules.PartEndColor.A = tempf;
  6341. break;
  6342. case (int)ScriptBaseClass.PSYS_PART_START_SCALE:
  6343. try
  6344. {
  6345. tempv = rules.GetVector3Item(i + 1);
  6346. }
  6347. catch(InvalidCastException)
  6348. {
  6349. Error(originFunc, string.Format("Error running rule PSYS_PART_START_SCALE: arg #{0} - parameter 1 must be vector", i + 1));
  6350. return;
  6351. }
  6352. prules.PartStartScaleX = validParticleScale((float)tempv.x);
  6353. prules.PartStartScaleY = validParticleScale((float)tempv.y);
  6354. break;
  6355. case (int)ScriptBaseClass.PSYS_PART_END_SCALE:
  6356. try
  6357. {
  6358. tempv = rules.GetVector3Item(i + 1);
  6359. }
  6360. catch(InvalidCastException)
  6361. {
  6362. Error(originFunc, string.Format("Error running rule PSYS_PART_END_SCALE: arg #{0} - parameter 1 must be vector", i + 1));
  6363. return;
  6364. }
  6365. prules.PartEndScaleX = validParticleScale((float)tempv.x);
  6366. prules.PartEndScaleY = validParticleScale((float)tempv.y);
  6367. break;
  6368. case (int)ScriptBaseClass.PSYS_PART_MAX_AGE:
  6369. try
  6370. {
  6371. tempf = (float)rules.GetLSLFloatItem(i + 1);
  6372. }
  6373. catch(InvalidCastException)
  6374. {
  6375. Error(originFunc, string.Format("Error running rule PSYS_PART_MAX_AGE: arg #{0} - parameter 1 must be float", i + 1));
  6376. return;
  6377. }
  6378. prules.PartMaxAge = tempf;
  6379. break;
  6380. case (int)ScriptBaseClass.PSYS_SRC_ACCEL:
  6381. try
  6382. {
  6383. tempv = rules.GetVector3Item(i + 1);
  6384. }
  6385. catch(InvalidCastException)
  6386. {
  6387. Error(originFunc, string.Format("Error running rule PSYS_SRC_ACCEL: arg #{0} - parameter 1 must be vector", i + 1));
  6388. return;
  6389. }
  6390. prules.PartAcceleration.X = (float)tempv.x;
  6391. prules.PartAcceleration.Y = (float)tempv.y;
  6392. prules.PartAcceleration.Z = (float)tempv.z;
  6393. break;
  6394. case (int)ScriptBaseClass.PSYS_SRC_PATTERN:
  6395. try
  6396. {
  6397. tmpi = (int)rules.GetLSLIntegerItem(i + 1);
  6398. }
  6399. catch(InvalidCastException)
  6400. {
  6401. Error(originFunc, string.Format("Error running rule PSYS_SRC_PATTERN: arg #{0} - parameter 1 must be integer", i + 1));
  6402. return;
  6403. }
  6404. prules.Pattern = (Primitive.ParticleSystem.SourcePattern)tmpi;
  6405. break;
  6406. // PSYS_SRC_INNERANGLE and PSYS_SRC_ANGLE_BEGIN use the same variables. The
  6407. // PSYS_SRC_OUTERANGLE and PSYS_SRC_ANGLE_END also use the same variable. The
  6408. // client tells the difference between the two by looking at the 0x02 bit in
  6409. // the PartFlags variable.
  6410. case (int)ScriptBaseClass.PSYS_SRC_INNERANGLE:
  6411. try
  6412. {
  6413. tempf = (float)rules.GetLSLFloatItem(i + 1);
  6414. }
  6415. catch(InvalidCastException)
  6416. {
  6417. Error(originFunc, string.Format("Error running rule PSYS_SRC_INNERANGLE: arg #{0} - parameter 1 must be float", i + 1));
  6418. return;
  6419. }
  6420. prules.InnerAngle = (float)tempf;
  6421. prules.PartFlags &= 0xFFFFFFFD; // Make sure new angle format is off.
  6422. break;
  6423. case (int)ScriptBaseClass.PSYS_SRC_OUTERANGLE:
  6424. try
  6425. {
  6426. tempf = (float)rules.GetLSLFloatItem(i + 1);
  6427. }
  6428. catch(InvalidCastException)
  6429. {
  6430. Error(originFunc, string.Format("Error running rule PSYS_SRC_OUTERANGLE: arg #{0} - parameter 1 must be float", i + 1));
  6431. return;
  6432. }
  6433. prules.OuterAngle = (float)tempf;
  6434. prules.PartFlags &= 0xFFFFFFFD; // Make sure new angle format is off.
  6435. break;
  6436. case (int)ScriptBaseClass.PSYS_PART_BLEND_FUNC_SOURCE:
  6437. try
  6438. {
  6439. tmpi = (int)rules.GetLSLIntegerItem(i + 1);
  6440. }
  6441. catch(InvalidCastException)
  6442. {
  6443. Error(originFunc, string.Format("Error running rule PSYS_PART_BLEND_FUNC_SOURCE: arg #{0} - parameter 1 must be integer", i + 1));
  6444. return;
  6445. }
  6446. prules.BlendFuncSource = (byte)tmpi;
  6447. break;
  6448. case (int)ScriptBaseClass.PSYS_PART_BLEND_FUNC_DEST:
  6449. try
  6450. {
  6451. tmpi = (int)rules.GetLSLIntegerItem(i + 1);
  6452. }
  6453. catch(InvalidCastException)
  6454. {
  6455. Error(originFunc, string.Format("Error running rule PSYS_PART_BLEND_FUNC_DEST: arg #{0} - parameter 1 must be integer", i + 1));
  6456. return;
  6457. }
  6458. prules.BlendFuncDest = (byte)tmpi;
  6459. break;
  6460. case (int)ScriptBaseClass.PSYS_PART_START_GLOW:
  6461. try
  6462. {
  6463. tempf = (float)rules.GetLSLFloatItem(i + 1);
  6464. }
  6465. catch(InvalidCastException)
  6466. {
  6467. Error(originFunc, string.Format("Error running rule PSYS_PART_START_GLOW: arg #{0} - parameter 1 must be float", i + 1));
  6468. return;
  6469. }
  6470. prules.PartStartGlow = (float)tempf;
  6471. break;
  6472. case (int)ScriptBaseClass.PSYS_PART_END_GLOW:
  6473. try
  6474. {
  6475. tempf = (float)rules.GetLSLFloatItem(i + 1);
  6476. }
  6477. catch(InvalidCastException)
  6478. {
  6479. Error(originFunc, string.Format("Error running rule PSYS_PART_END_GLOW: arg #{0} - parameter 1 must be float", i + 1));
  6480. return;
  6481. }
  6482. prules.PartEndGlow = (float)tempf;
  6483. break;
  6484. case (int)ScriptBaseClass.PSYS_SRC_TEXTURE:
  6485. try
  6486. {
  6487. prules.Texture = ScriptUtils.GetAssetIdFromKeyOrItemName(m_host, rules.GetLSLStringItem(i + 1));
  6488. }
  6489. catch(InvalidCastException)
  6490. {
  6491. Error(originFunc, string.Format("Error running rule PSYS_SRC_TEXTURE: arg #{0} - parameter 1 must be string or key", i + 1));
  6492. return;
  6493. }
  6494. break;
  6495. case (int)ScriptBaseClass.PSYS_SRC_BURST_RATE:
  6496. try
  6497. {
  6498. tempf = (float)rules.GetLSLFloatItem(i + 1);
  6499. }
  6500. catch(InvalidCastException)
  6501. {
  6502. Error(originFunc, string.Format("Error running rule PSYS_SRC_BURST_RATE: arg #{0} - parameter 1 must be float", i + 1));
  6503. return;
  6504. }
  6505. prules.BurstRate = (float)tempf;
  6506. break;
  6507. case (int)ScriptBaseClass.PSYS_SRC_BURST_PART_COUNT:
  6508. try
  6509. {
  6510. prules.BurstPartCount = (byte)(int)rules.GetLSLIntegerItem(i + 1);
  6511. }
  6512. catch(InvalidCastException)
  6513. {
  6514. Error(originFunc, string.Format("Error running rule PSYS_SRC_BURST_PART_COUNT: arg #{0} - parameter 1 must be integer", i + 1));
  6515. return;
  6516. }
  6517. break;
  6518. case (int)ScriptBaseClass.PSYS_SRC_BURST_RADIUS:
  6519. try
  6520. {
  6521. tempf = (float)rules.GetLSLFloatItem(i + 1);
  6522. }
  6523. catch(InvalidCastException)
  6524. {
  6525. Error(originFunc, string.Format("Error running rule PSYS_SRC_BURST_RADIUS: arg #{0} - parameter 1 must be float", i + 1));
  6526. return;
  6527. }
  6528. prules.BurstRadius = (float)tempf;
  6529. break;
  6530. case (int)ScriptBaseClass.PSYS_SRC_BURST_SPEED_MIN:
  6531. try
  6532. {
  6533. tempf = (float)rules.GetLSLFloatItem(i + 1);
  6534. }
  6535. catch(InvalidCastException)
  6536. {
  6537. Error(originFunc, string.Format("Error running rule PSYS_SRC_BURST_SPEED_MIN: arg #{0} - parameter 1 must be float", i + 1));
  6538. return;
  6539. }
  6540. prules.BurstSpeedMin = (float)tempf;
  6541. break;
  6542. case (int)ScriptBaseClass.PSYS_SRC_BURST_SPEED_MAX:
  6543. try
  6544. {
  6545. tempf = (float)rules.GetLSLFloatItem(i + 1);
  6546. }
  6547. catch(InvalidCastException)
  6548. {
  6549. Error(originFunc, string.Format("Error running rule PSYS_SRC_BURST_SPEED_MAX: arg #{0} - parameter 1 must be float", i + 1));
  6550. return;
  6551. }
  6552. prules.BurstSpeedMax = (float)tempf;
  6553. break;
  6554. case (int)ScriptBaseClass.PSYS_SRC_MAX_AGE:
  6555. try
  6556. {
  6557. tempf = (float)rules.GetLSLFloatItem(i + 1);
  6558. }
  6559. catch(InvalidCastException)
  6560. {
  6561. Error(originFunc, string.Format("Error running rule PSYS_SRC_MAX_AGE: arg #{0} - parameter 1 must be float", i + 1));
  6562. return;
  6563. }
  6564. prules.MaxAge = (float)tempf;
  6565. break;
  6566. case (int)ScriptBaseClass.PSYS_SRC_TARGET_KEY:
  6567. UUID key = UUID.Zero;
  6568. if (UUID.TryParse(rules.Data[i + 1].ToString(), out key))
  6569. {
  6570. prules.Target = key;
  6571. }
  6572. else
  6573. {
  6574. prules.Target = part.UUID;
  6575. }
  6576. break;
  6577. case (int)ScriptBaseClass.PSYS_SRC_OMEGA:
  6578. // AL: This is an assumption, since it is the only thing that would match.
  6579. try
  6580. {
  6581. tempv = rules.GetVector3Item(i + 1);
  6582. }
  6583. catch(InvalidCastException)
  6584. {
  6585. Error(originFunc, string.Format("Error running rule PSYS_SRC_OMEGA: arg #{0} - parameter 1 must be vector", i + 1));
  6586. return;
  6587. }
  6588. prules.AngularVelocity.X = (float)tempv.x;
  6589. prules.AngularVelocity.Y = (float)tempv.y;
  6590. prules.AngularVelocity.Z = (float)tempv.z;
  6591. break;
  6592. case (int)ScriptBaseClass.PSYS_SRC_ANGLE_BEGIN:
  6593. try
  6594. {
  6595. tempf = (float)rules.GetLSLFloatItem(i + 1);
  6596. }
  6597. catch(InvalidCastException)
  6598. {
  6599. Error(originFunc, string.Format("Error running rule PSYS_SRC_ANGLE_BEGIN: arg #{0} - parameter 1 must be float", i + 1));
  6600. return;
  6601. }
  6602. prules.InnerAngle = (float)tempf;
  6603. prules.PartFlags |= 0x02; // Set new angle format.
  6604. break;
  6605. case (int)ScriptBaseClass.PSYS_SRC_ANGLE_END:
  6606. try
  6607. {
  6608. tempf = (float)rules.GetLSLFloatItem(i + 1);
  6609. }
  6610. catch (InvalidCastException)
  6611. {
  6612. Error(originFunc, string.Format("Error running rule PSYS_SRC_ANGLE_END: arg #{0} - parameter 1 must be float", i + 1));
  6613. return;
  6614. }
  6615. prules.OuterAngle = (float)tempf;
  6616. prules.PartFlags |= 0x02; // Set new angle format.
  6617. break;
  6618. }
  6619. }
  6620. prules.CRC = 1;
  6621. part.AddNewParticleSystem(prules);
  6622. part.ParentGroup.HasGroupChanged = true;
  6623. }
  6624. part.SendFullUpdateToAllClients();
  6625. }
  6626. private float validParticleScale(float value)
  6627. {
  6628. if (value > 4.0f) return 4.0f;
  6629. return value;
  6630. }
  6631. public void llGroundRepel(double height, int water, double tau)
  6632. {
  6633. m_host.AddScriptLPS(1);
  6634. if (m_host.PhysActor != null)
  6635. {
  6636. float ground = (float)llGround(new LSL_Types.Vector3(0, 0, 0));
  6637. float waterLevel = (float)llWater(new LSL_Types.Vector3(0, 0, 0));
  6638. PIDHoverType hoverType = PIDHoverType.Ground;
  6639. if (water != 0)
  6640. {
  6641. hoverType = PIDHoverType.GroundAndWater;
  6642. if (ground < waterLevel)
  6643. height += waterLevel;
  6644. else
  6645. height += ground;
  6646. }
  6647. else
  6648. {
  6649. height += ground;
  6650. }
  6651. m_host.SetHoverHeight((float)height, hoverType, (float)tau);
  6652. }
  6653. }
  6654. public void llGiveInventoryList(string destination, string category, LSL_List inventory)
  6655. {
  6656. m_host.AddScriptLPS(1);
  6657. UUID destID;
  6658. if (!UUID.TryParse(destination, out destID))
  6659. return;
  6660. List<UUID> itemList = new List<UUID>();
  6661. foreach (Object item in inventory.Data)
  6662. {
  6663. string rawItemString = item.ToString();
  6664. UUID itemID;
  6665. if (UUID.TryParse(rawItemString, out itemID))
  6666. {
  6667. itemList.Add(itemID);
  6668. }
  6669. else
  6670. {
  6671. TaskInventoryItem taskItem = m_host.Inventory.GetInventoryItem(rawItemString);
  6672. if (taskItem != null)
  6673. itemList.Add(taskItem.ItemID);
  6674. }
  6675. }
  6676. if (itemList.Count == 0)
  6677. return;
  6678. UUID folderID = m_ScriptEngine.World.MoveTaskInventoryItems(destID, category, m_host, itemList);
  6679. if (folderID == UUID.Zero)
  6680. return;
  6681. if (m_TransferModule != null)
  6682. {
  6683. byte[] bucket = new byte[] { (byte)AssetType.Folder };
  6684. Vector3 pos = m_host.AbsolutePosition;
  6685. GridInstantMessage msg = new GridInstantMessage(World,
  6686. m_host.OwnerID, m_host.Name, destID,
  6687. (byte)InstantMessageDialog.TaskInventoryOffered,
  6688. false, string.Format("'{0}'", category),
  6689. // We won't go so far as to add a SLURL, but this is the format used by LL as of 2012-10-06
  6690. // false, string.Format("'{0}' ( http://slurl.com/secondlife/{1}/{2}/{3}/{4} )", category, World.Name, (int)pos.X, (int)pos.Y, (int)pos.Z),
  6691. folderID, false, pos,
  6692. bucket, false);
  6693. m_TransferModule.SendInstantMessage(msg, delegate(bool success) {});
  6694. }
  6695. }
  6696. public void llSetVehicleType(int type)
  6697. {
  6698. m_host.AddScriptLPS(1);
  6699. if (!m_host.ParentGroup.IsDeleted)
  6700. {
  6701. m_host.ParentGroup.RootPart.SetVehicleType(type);
  6702. }
  6703. }
  6704. //CFK 9/28: Most, but not all of the underlying plumbing between here and the physics modules is in
  6705. //CFK 9/28: so these are not complete yet.
  6706. public void llSetVehicleFloatParam(int param, LSL_Float value)
  6707. {
  6708. m_host.AddScriptLPS(1);
  6709. if (!m_host.ParentGroup.IsDeleted)
  6710. {
  6711. m_host.ParentGroup.RootPart.SetVehicleFloatParam(param, (float)value);
  6712. }
  6713. }
  6714. //CFK 9/28: Most, but not all of the underlying plumbing between here and the physics modules is in
  6715. //CFK 9/28: so these are not complete yet.
  6716. public void llSetVehicleVectorParam(int param, LSL_Vector vec)
  6717. {
  6718. m_host.AddScriptLPS(1);
  6719. if (!m_host.ParentGroup.IsDeleted)
  6720. {
  6721. m_host.ParentGroup.RootPart.SetVehicleVectorParam(param, vec);
  6722. }
  6723. }
  6724. //CFK 9/28: Most, but not all of the underlying plumbing between here and the physics modules is in
  6725. //CFK 9/28: so these are not complete yet.
  6726. public void llSetVehicleRotationParam(int param, LSL_Rotation rot)
  6727. {
  6728. m_host.AddScriptLPS(1);
  6729. if (!m_host.ParentGroup.IsDeleted)
  6730. {
  6731. m_host.ParentGroup.RootPart.SetVehicleRotationParam(param, rot);
  6732. }
  6733. }
  6734. public void llSetVehicleFlags(int flags)
  6735. {
  6736. m_host.AddScriptLPS(1);
  6737. if (!m_host.ParentGroup.IsDeleted)
  6738. {
  6739. m_host.ParentGroup.RootPart.SetVehicleFlags(flags, false);
  6740. }
  6741. }
  6742. public void llRemoveVehicleFlags(int flags)
  6743. {
  6744. m_host.AddScriptLPS(1);
  6745. if (!m_host.ParentGroup.IsDeleted)
  6746. {
  6747. m_host.ParentGroup.RootPart.SetVehicleFlags(flags, true);
  6748. }
  6749. }
  6750. protected void SitTarget(SceneObjectPart part, LSL_Vector offset, LSL_Rotation rot)
  6751. {
  6752. // LSL quaternions can normalize to 0, normal Quaternions can't.
  6753. if (rot.s == 0 && rot.x == 0 && rot.y == 0 && rot.z == 0)
  6754. rot.s = 1; // ZERO_ROTATION = 0,0,0,1
  6755. part.SitTargetPosition = offset;
  6756. part.SitTargetOrientation = rot;
  6757. part.ParentGroup.HasGroupChanged = true;
  6758. }
  6759. public void llSitTarget(LSL_Vector offset, LSL_Rotation rot)
  6760. {
  6761. m_host.AddScriptLPS(1);
  6762. SitTarget(m_host, offset, rot);
  6763. }
  6764. public void llLinkSitTarget(LSL_Integer link, LSL_Vector offset, LSL_Rotation rot)
  6765. {
  6766. m_host.AddScriptLPS(1);
  6767. if (link == ScriptBaseClass.LINK_ROOT)
  6768. SitTarget(m_host.ParentGroup.RootPart, offset, rot);
  6769. else if (link == ScriptBaseClass.LINK_THIS)
  6770. SitTarget(m_host, offset, rot);
  6771. else
  6772. {
  6773. SceneObjectPart part = m_host.ParentGroup.GetLinkNumPart(link);
  6774. if (null != part)
  6775. {
  6776. SitTarget(part, offset, rot);
  6777. }
  6778. }
  6779. }
  6780. public LSL_Key llAvatarOnSitTarget()
  6781. {
  6782. m_host.AddScriptLPS(1);
  6783. return m_host.SitTargetAvatar.ToString();
  6784. }
  6785. // http://wiki.secondlife.com/wiki/LlAvatarOnLinkSitTarget
  6786. public LSL_Key llAvatarOnLinkSitTarget(LSL_Integer linknum)
  6787. {
  6788. m_host.AddScriptLPS(1);
  6789. if(linknum == ScriptBaseClass.LINK_SET ||
  6790. linknum == ScriptBaseClass.LINK_ALL_CHILDREN ||
  6791. linknum == ScriptBaseClass.LINK_ALL_OTHERS ||
  6792. linknum == 0)
  6793. return UUID.Zero.ToString();
  6794. List<SceneObjectPart> parts = GetLinkParts(linknum);
  6795. if (parts.Count == 0)
  6796. return UUID.Zero.ToString();
  6797. return parts[0].SitTargetAvatar.ToString();
  6798. }
  6799. public void llAddToLandPassList(LSL_Key avatar, double hours)
  6800. {
  6801. m_host.AddScriptLPS(1);
  6802. UUID key;
  6803. ILandObject land = World.LandChannel.GetLandObject(m_host.AbsolutePosition);
  6804. if (World.Permissions.CanEditParcelProperties(m_host.OwnerID, land, GroupPowers.LandManagePasses, false))
  6805. {
  6806. int expires = 0;
  6807. if (hours != 0)
  6808. expires = Util.UnixTimeSinceEpoch() + (int)(3600.0 * hours);
  6809. if (UUID.TryParse(avatar, out key))
  6810. {
  6811. int idx = land.LandData.ParcelAccessList.FindIndex(
  6812. delegate(LandAccessEntry e)
  6813. {
  6814. if (e.AgentID == key && e.Flags == AccessList.Access)
  6815. return true;
  6816. return false;
  6817. });
  6818. if (idx != -1 && (land.LandData.ParcelAccessList[idx].Expires == 0 || (expires != 0 && expires < land.LandData.ParcelAccessList[idx].Expires)))
  6819. return;
  6820. if (idx != -1)
  6821. land.LandData.ParcelAccessList.RemoveAt(idx);
  6822. LandAccessEntry entry = new LandAccessEntry();
  6823. entry.AgentID = key;
  6824. entry.Flags = AccessList.Access;
  6825. entry.Expires = expires;
  6826. land.LandData.ParcelAccessList.Add(entry);
  6827. World.EventManager.TriggerLandObjectUpdated((uint)land.LandData.LocalID, land);
  6828. }
  6829. }
  6830. ScriptSleep(m_sleepMsOnAddToLandPassList);
  6831. }
  6832. public void llSetTouchText(string text)
  6833. {
  6834. m_host.AddScriptLPS(1);
  6835. m_host.TouchName = text;
  6836. }
  6837. public void llSetSitText(string text)
  6838. {
  6839. m_host.AddScriptLPS(1);
  6840. m_host.SitName = text;
  6841. }
  6842. public void llSetCameraEyeOffset(LSL_Vector offset)
  6843. {
  6844. m_host.AddScriptLPS(1);
  6845. m_host.SetCameraEyeOffset(offset);
  6846. if (m_host.ParentGroup.RootPart.GetCameraEyeOffset() == Vector3.Zero)
  6847. m_host.ParentGroup.RootPart.SetCameraEyeOffset(offset);
  6848. }
  6849. public void llSetCameraAtOffset(LSL_Vector offset)
  6850. {
  6851. m_host.AddScriptLPS(1);
  6852. m_host.SetCameraAtOffset(offset);
  6853. if (m_host.ParentGroup.RootPart.GetCameraAtOffset() == Vector3.Zero)
  6854. m_host.ParentGroup.RootPart.SetCameraAtOffset(offset);
  6855. }
  6856. public void llSetLinkCamera(LSL_Integer link, LSL_Vector eye, LSL_Vector at)
  6857. {
  6858. m_host.AddScriptLPS(1);
  6859. if (link == ScriptBaseClass.LINK_SET ||
  6860. link == ScriptBaseClass.LINK_ALL_CHILDREN ||
  6861. link == ScriptBaseClass.LINK_ALL_OTHERS) return;
  6862. SceneObjectPart part = null;
  6863. switch (link)
  6864. {
  6865. case ScriptBaseClass.LINK_ROOT:
  6866. part = m_host.ParentGroup.RootPart;
  6867. break;
  6868. case ScriptBaseClass.LINK_THIS:
  6869. part = m_host;
  6870. break;
  6871. default:
  6872. part = m_host.ParentGroup.GetLinkNumPart(link);
  6873. break;
  6874. }
  6875. if (null != part)
  6876. {
  6877. part.SetCameraEyeOffset(eye);
  6878. part.SetCameraAtOffset(at);
  6879. }
  6880. }
  6881. public LSL_String llDumpList2String(LSL_List src, string seperator)
  6882. {
  6883. m_host.AddScriptLPS(1);
  6884. if (src.Length == 0)
  6885. {
  6886. return String.Empty;
  6887. }
  6888. string ret = String.Empty;
  6889. foreach (object o in src.Data)
  6890. {
  6891. ret = ret + o.ToString() + seperator;
  6892. }
  6893. ret = ret.Substring(0, ret.Length - seperator.Length);
  6894. return ret;
  6895. }
  6896. public LSL_Integer llScriptDanger(LSL_Vector pos)
  6897. {
  6898. m_host.AddScriptLPS(1);
  6899. bool result = World.LSLScriptDanger(m_host, pos);
  6900. if (result)
  6901. {
  6902. return 1;
  6903. }
  6904. else
  6905. {
  6906. return 0;
  6907. }
  6908. }
  6909. public void llDialog(LSL_Key avatar, LSL_String message, LSL_List buttons, int chat_channel)
  6910. {
  6911. IDialogModule dm = World.RequestModuleInterface<IDialogModule>();
  6912. if (dm == null)
  6913. return;
  6914. m_host.AddScriptLPS(1);
  6915. UUID av = new UUID();
  6916. if (!UUID.TryParse(avatar,out av))
  6917. {
  6918. Error("llDialog", "First parameter must be a key");
  6919. return;
  6920. }
  6921. int length = buttons.Length;
  6922. if (length < 1)
  6923. {
  6924. buttons.Add(new LSL_String("Ok"));
  6925. length = 1;
  6926. }
  6927. else if (length > 12)
  6928. {
  6929. Error("llDialog", "No more than 12 buttons can be shown");
  6930. return;
  6931. }
  6932. if (message == string.Empty)
  6933. {
  6934. Error("llDialog", "Empty message");
  6935. }
  6936. else if (Encoding.UTF8.GetByteCount(message) > 512)
  6937. {
  6938. Error("llDialog", "Message longer than 512 bytes");
  6939. }
  6940. string[] buts = new string[length];
  6941. for (int i = 0; i < length; i++)
  6942. {
  6943. if (buttons.Data[i].ToString() == String.Empty)
  6944. {
  6945. Error("llDialog", "Button label cannot be blank");
  6946. return;
  6947. }
  6948. /*
  6949. if (buttons.Data[i].ToString().Length > 24)
  6950. {
  6951. Error("llDialog", "Button label cannot be longer than 24 characters");
  6952. return;
  6953. }
  6954. */
  6955. buts[i] = buttons.Data[i].ToString();
  6956. }
  6957. dm.SendDialogToUser(
  6958. av, m_host.Name, m_host.UUID, m_host.OwnerID,
  6959. message, new UUID("00000000-0000-2222-3333-100000001000"), chat_channel, buts);
  6960. ScriptSleep(m_sleepMsOnDialog);
  6961. }
  6962. public void llVolumeDetect(int detect)
  6963. {
  6964. m_host.AddScriptLPS(1);
  6965. if (!m_host.ParentGroup.IsDeleted)
  6966. m_host.ParentGroup.ScriptSetVolumeDetect(detect != 0);
  6967. }
  6968. public void llRemoteLoadScript(string target, string name, int running, int start_param)
  6969. {
  6970. m_host.AddScriptLPS(1);
  6971. Deprecated("llRemoteLoadScript", "Use llRemoteLoadScriptPin instead");
  6972. ScriptSleep(m_sleepMsOnRemoteLoadScript);
  6973. }
  6974. public void llSetRemoteScriptAccessPin(int pin)
  6975. {
  6976. m_host.AddScriptLPS(1);
  6977. m_host.ScriptAccessPin = pin;
  6978. }
  6979. public void llRemoteLoadScriptPin(string target, string name, int pin, int running, int start_param)
  6980. {
  6981. m_host.AddScriptLPS(1);
  6982. UUID destId = UUID.Zero;
  6983. if (!UUID.TryParse(target, out destId))
  6984. {
  6985. Error("llRemoteLoadScriptPin", "Can't parse key '" + target + "'");
  6986. return;
  6987. }
  6988. // target must be a different prim than the one containing the script
  6989. if (m_host.UUID == destId)
  6990. {
  6991. return;
  6992. }
  6993. // copy the first script found with this inventory name
  6994. TaskInventoryItem item = m_host.Inventory.GetInventoryItem(name);
  6995. // make sure the object is a script
  6996. if (item == null || item.Type != 10)
  6997. {
  6998. Error("llRemoteLoadScriptPin", "Can't find script '" + name + "'");
  6999. return;
  7000. }
  7001. SceneObjectPart dest = World.GetSceneObjectPart(destId);
  7002. if (dest != null)
  7003. {
  7004. if ((item.BasePermissions & (uint)PermissionMask.Transfer) != 0 || dest.ParentGroup.RootPart.OwnerID == m_host.ParentGroup.RootPart.OwnerID)
  7005. {
  7006. // the rest of the permission checks are done in RezScript, so check the pin there as well
  7007. World.RezScriptFromPrim(item.ItemID, m_host, destId, pin, running, start_param);
  7008. if ((item.BasePermissions & (uint)PermissionMask.Copy) == 0)
  7009. m_host.Inventory.RemoveInventoryItem(item.ItemID);
  7010. }
  7011. }
  7012. // this will cause the delay even if the script pin or permissions were wrong - seems ok
  7013. ScriptSleep(m_sleepMsOnRemoteLoadScriptPin);
  7014. }
  7015. public void llOpenRemoteDataChannel()
  7016. {
  7017. m_host.AddScriptLPS(1);
  7018. IXMLRPC xmlrpcMod = m_ScriptEngine.World.RequestModuleInterface<IXMLRPC>();
  7019. if (xmlrpcMod != null && xmlrpcMod.IsEnabled())
  7020. {
  7021. UUID channelID = xmlrpcMod.OpenXMLRPCChannel(m_host.LocalId, m_item.ItemID, UUID.Zero);
  7022. IXmlRpcRouter xmlRpcRouter = m_ScriptEngine.World.RequestModuleInterface<IXmlRpcRouter>();
  7023. if (xmlRpcRouter != null)
  7024. {
  7025. string ExternalHostName = m_ScriptEngine.World.RegionInfo.ExternalHostName;
  7026. xmlRpcRouter.RegisterNewReceiver(m_ScriptEngine.ScriptModule, channelID, m_host.UUID,
  7027. m_item.ItemID, String.Format("http://{0}:{1}/", ExternalHostName,
  7028. xmlrpcMod.Port.ToString()));
  7029. }
  7030. object[] resobj = new object[]
  7031. {
  7032. new LSL_Integer(1),
  7033. new LSL_String(channelID.ToString()),
  7034. new LSL_String(UUID.Zero.ToString()),
  7035. new LSL_String(String.Empty),
  7036. new LSL_Integer(0),
  7037. new LSL_String(String.Empty)
  7038. };
  7039. m_ScriptEngine.PostScriptEvent(m_item.ItemID, new EventParams("remote_data", resobj,
  7040. new DetectParams[0]));
  7041. }
  7042. ScriptSleep(m_sleepMsOnOpenRemoteDataChannel);
  7043. }
  7044. public LSL_Key llSendRemoteData(string channel, string dest, int idata, string sdata)
  7045. {
  7046. m_host.AddScriptLPS(1);
  7047. IXMLRPC xmlrpcMod = m_ScriptEngine.World.RequestModuleInterface<IXMLRPC>();
  7048. ScriptSleep(m_sleepMsOnSendRemoteData);
  7049. if (xmlrpcMod == null)
  7050. return "";
  7051. return (xmlrpcMod.SendRemoteData(m_host.LocalId, m_item.ItemID, channel, dest, idata, sdata)).ToString();
  7052. }
  7053. public void llRemoteDataReply(string channel, string message_id, string sdata, int idata)
  7054. {
  7055. m_host.AddScriptLPS(1);
  7056. IXMLRPC xmlrpcMod = m_ScriptEngine.World.RequestModuleInterface<IXMLRPC>();
  7057. if (xmlrpcMod != null)
  7058. xmlrpcMod.RemoteDataReply(channel, message_id, sdata, idata);
  7059. ScriptSleep(m_sleepMsOnRemoteDataReply);
  7060. }
  7061. public void llCloseRemoteDataChannel(string channel)
  7062. {
  7063. m_host.AddScriptLPS(1);
  7064. IXmlRpcRouter xmlRpcRouter = m_ScriptEngine.World.RequestModuleInterface<IXmlRpcRouter>();
  7065. if (xmlRpcRouter != null)
  7066. {
  7067. xmlRpcRouter.UnRegisterReceiver(channel, m_item.ItemID);
  7068. }
  7069. IXMLRPC xmlrpcMod = m_ScriptEngine.World.RequestModuleInterface<IXMLRPC>();
  7070. if (xmlrpcMod != null)
  7071. xmlrpcMod.CloseXMLRPCChannel((UUID)channel);
  7072. ScriptSleep(m_sleepMsOnCloseRemoteDataChannel);
  7073. }
  7074. public LSL_String llMD5String(string src, int nonce)
  7075. {
  7076. m_host.AddScriptLPS(1);
  7077. return Util.Md5Hash(String.Format("{0}:{1}", src, nonce.ToString()), Encoding.UTF8);
  7078. }
  7079. public LSL_String llSHA1String(string src)
  7080. {
  7081. m_host.AddScriptLPS(1);
  7082. return Util.SHA1Hash(src, Encoding.UTF8).ToLower();
  7083. }
  7084. protected ObjectShapePacket.ObjectDataBlock SetPrimitiveBlockShapeParams(SceneObjectPart part, int holeshape, LSL_Vector cut, float hollow, LSL_Vector twist, byte profileshape, byte pathcurve)
  7085. {
  7086. float tempFloat; // Use in float expressions below to avoid byte cast precision issues.
  7087. ObjectShapePacket.ObjectDataBlock shapeBlock = new ObjectShapePacket.ObjectDataBlock();
  7088. if (part == null || part.ParentGroup == null || part.ParentGroup.IsDeleted)
  7089. return shapeBlock;
  7090. if (holeshape != (int)ScriptBaseClass.PRIM_HOLE_DEFAULT &&
  7091. holeshape != (int)ScriptBaseClass.PRIM_HOLE_CIRCLE &&
  7092. holeshape != (int)ScriptBaseClass.PRIM_HOLE_SQUARE &&
  7093. holeshape != (int)ScriptBaseClass.PRIM_HOLE_TRIANGLE)
  7094. {
  7095. holeshape = (int)ScriptBaseClass.PRIM_HOLE_DEFAULT;
  7096. }
  7097. shapeBlock.PathCurve = pathcurve;
  7098. shapeBlock.ProfileCurve = (byte)holeshape; // Set the hole shape.
  7099. shapeBlock.ProfileCurve += profileshape; // Add in the profile shape.
  7100. if (cut.x < 0f)
  7101. {
  7102. cut.x = 0f;
  7103. }
  7104. else if (cut.x > 1f)
  7105. {
  7106. cut.x = 1f;
  7107. }
  7108. if (cut.y < 0f)
  7109. {
  7110. cut.y = 0f;
  7111. }
  7112. else if (cut.y > 1f)
  7113. {
  7114. cut.y = 1f;
  7115. }
  7116. if (cut.y - cut.x < 0.02f)
  7117. {
  7118. cut.x = cut.y - 0.02f;
  7119. if (cut.x < 0.0f)
  7120. {
  7121. cut.x = 0.0f;
  7122. cut.y = 0.02f;
  7123. }
  7124. }
  7125. shapeBlock.ProfileBegin = (ushort)(50000 * cut.x);
  7126. shapeBlock.ProfileEnd = (ushort)(50000 * (1 - cut.y));
  7127. if (hollow < 0f)
  7128. {
  7129. hollow = 0f;
  7130. }
  7131. // If the prim is a Cylinder, Prism, Sphere, Torus or Ring (or not a
  7132. // Box or Tube) and the hole shape is a square, hollow is limited to
  7133. // a max of 70%. The viewer performs its own check on this value but
  7134. // we need to do it here also so llGetPrimitiveParams can have access
  7135. // to the correct value.
  7136. if (profileshape != (byte)ProfileCurve.Square &&
  7137. holeshape == (int)ScriptBaseClass.PRIM_HOLE_SQUARE)
  7138. {
  7139. if (hollow > 0.70f)
  7140. {
  7141. hollow = 0.70f;
  7142. }
  7143. }
  7144. // Otherwise, hollow is limited to 99%.
  7145. else
  7146. {
  7147. if (hollow > 0.99f)
  7148. {
  7149. hollow = 0.99f;
  7150. }
  7151. }
  7152. shapeBlock.ProfileHollow = (ushort)(50000 * hollow);
  7153. if (twist.x < -1.0f)
  7154. {
  7155. twist.x = -1.0f;
  7156. }
  7157. else if (twist.x > 1.0f)
  7158. {
  7159. twist.x = 1.0f;
  7160. }
  7161. if (twist.y < -1.0f)
  7162. {
  7163. twist.y = -1.0f;
  7164. }
  7165. else if (twist.y > 1.0f)
  7166. {
  7167. twist.y = 1.0f;
  7168. }
  7169. tempFloat = 100.0f * (float)twist.x;
  7170. if (tempFloat >= 0)
  7171. tempFloat += 0.5f;
  7172. else
  7173. tempFloat -= 0.5f;
  7174. shapeBlock.PathTwistBegin = (sbyte)tempFloat;
  7175. tempFloat = 100.0f * (float)twist.y;
  7176. if (tempFloat >= 0)
  7177. tempFloat += 0.5f;
  7178. else
  7179. tempFloat -= 0.5f;
  7180. shapeBlock.PathTwist = (sbyte)tempFloat;
  7181. shapeBlock.ObjectLocalID = part.LocalId;
  7182. part.Shape.SculptEntry = false;
  7183. return shapeBlock;
  7184. }
  7185. // Prim type box, cylinder and prism.
  7186. 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)
  7187. {
  7188. if (part == null || part.ParentGroup == null || part.ParentGroup.IsDeleted)
  7189. return;
  7190. float tempFloat; // Use in float expressions below to avoid byte cast precision issues.
  7191. ObjectShapePacket.ObjectDataBlock shapeBlock;
  7192. shapeBlock = SetPrimitiveBlockShapeParams(part, holeshape, cut, hollow, twist, profileshape, pathcurve);
  7193. if (taper_b.x < 0f)
  7194. {
  7195. taper_b.x = 0f;
  7196. }
  7197. else if (taper_b.x > 2f)
  7198. {
  7199. taper_b.x = 2f;
  7200. }
  7201. if (taper_b.y < 0f)
  7202. {
  7203. taper_b.y = 0f;
  7204. }
  7205. else if (taper_b.y > 2f)
  7206. {
  7207. taper_b.y = 2f;
  7208. }
  7209. tempFloat = 100.0f * (2.0f - (float)taper_b.x);
  7210. if (tempFloat >= 0)
  7211. tempFloat += 0.5f;
  7212. else
  7213. tempFloat -= 0.5f;
  7214. shapeBlock.PathScaleX = (byte)tempFloat;
  7215. tempFloat = 100.0f * (2.0f - (float)taper_b.y);
  7216. if (tempFloat >= 0)
  7217. tempFloat += 0.5f;
  7218. else
  7219. tempFloat -= 0.5f;
  7220. shapeBlock.PathScaleY = (byte)tempFloat;
  7221. if (topshear.x < -0.5f)
  7222. {
  7223. topshear.x = -0.5f;
  7224. }
  7225. else if (topshear.x > 0.5f)
  7226. {
  7227. topshear.x = 0.5f;
  7228. }
  7229. if (topshear.y < -0.5f)
  7230. {
  7231. topshear.y = -0.5f;
  7232. }
  7233. else if (topshear.y > 0.5f)
  7234. {
  7235. topshear.y = 0.5f;
  7236. }
  7237. tempFloat = 100.0f * (float)topshear.x;
  7238. if (tempFloat >= 0)
  7239. tempFloat += 0.5f;
  7240. else
  7241. tempFloat -= 0.5f;
  7242. shapeBlock.PathShearX = (byte)tempFloat;
  7243. tempFloat = 100.0f * (float)topshear.y;
  7244. if (tempFloat >= 0)
  7245. tempFloat += 0.5f;
  7246. else
  7247. tempFloat -= 0.5f;
  7248. shapeBlock.PathShearY = (byte)tempFloat;
  7249. part.Shape.SculptEntry = false;
  7250. part.UpdateShape(shapeBlock);
  7251. }
  7252. // Prim type sphere.
  7253. protected void SetPrimitiveShapeParams(SceneObjectPart part, int holeshape, LSL_Vector cut, float hollow, LSL_Vector twist, LSL_Vector dimple, byte profileshape, byte pathcurve)
  7254. {
  7255. if (part == null || part.ParentGroup == null || part.ParentGroup.IsDeleted)
  7256. return;
  7257. ObjectShapePacket.ObjectDataBlock shapeBlock;
  7258. shapeBlock = SetPrimitiveBlockShapeParams(part, holeshape, cut, hollow, twist, profileshape, pathcurve);
  7259. // profile/path swapped for a sphere
  7260. shapeBlock.PathBegin = shapeBlock.ProfileBegin;
  7261. shapeBlock.PathEnd = shapeBlock.ProfileEnd;
  7262. shapeBlock.PathScaleX = 100;
  7263. shapeBlock.PathScaleY = 100;
  7264. if (dimple.x < 0f)
  7265. {
  7266. dimple.x = 0f;
  7267. }
  7268. else if (dimple.x > 1f)
  7269. {
  7270. dimple.x = 1f;
  7271. }
  7272. if (dimple.y < 0f)
  7273. {
  7274. dimple.y = 0f;
  7275. }
  7276. else if (dimple.y > 1f)
  7277. {
  7278. dimple.y = 1f;
  7279. }
  7280. if (dimple.y - dimple.x < 0.02f)
  7281. {
  7282. dimple.x = dimple.y - 0.02f;
  7283. if (dimple.x < 0.0f)
  7284. {
  7285. dimple.x = 0.0f;
  7286. dimple.y = 0.02f;
  7287. }
  7288. }
  7289. shapeBlock.ProfileBegin = (ushort)(50000 * dimple.x);
  7290. shapeBlock.ProfileEnd = (ushort)(50000 * (1 - dimple.y));
  7291. part.Shape.SculptEntry = false;
  7292. part.UpdateShape(shapeBlock);
  7293. }
  7294. // Prim type torus, tube and ring.
  7295. 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)
  7296. {
  7297. if (part == null || part.ParentGroup == null || part.ParentGroup.IsDeleted)
  7298. return;
  7299. float tempFloat; // Use in float expressions below to avoid byte cast precision issues.
  7300. ObjectShapePacket.ObjectDataBlock shapeBlock;
  7301. shapeBlock = SetPrimitiveBlockShapeParams(part, holeshape, cut, hollow, twist, profileshape, pathcurve);
  7302. // profile/path swapped for a torrus, tube, ring
  7303. shapeBlock.PathBegin = shapeBlock.ProfileBegin;
  7304. shapeBlock.PathEnd = shapeBlock.ProfileEnd;
  7305. if (holesize.x < 0.01f)
  7306. {
  7307. holesize.x = 0.01f;
  7308. }
  7309. else if (holesize.x > 1f)
  7310. {
  7311. holesize.x = 1f;
  7312. }
  7313. tempFloat = 100.0f * (2.0f - (float)holesize.x) + 0.5f;
  7314. shapeBlock.PathScaleX = (byte)tempFloat;
  7315. if (holesize.y < 0.01f)
  7316. {
  7317. holesize.y = 0.01f;
  7318. }
  7319. else if (holesize.y > 0.5f)
  7320. {
  7321. holesize.y = 0.5f;
  7322. }
  7323. tempFloat = 100.0f * (2.0f - (float)holesize.y) + 0.5f;
  7324. shapeBlock.PathScaleY = (byte)tempFloat;
  7325. if (topshear.x < -0.5f)
  7326. {
  7327. topshear.x = -0.5f;
  7328. }
  7329. else if (topshear.x > 0.5f)
  7330. {
  7331. topshear.x = 0.5f;
  7332. }
  7333. tempFloat = (float)(100.0d * topshear.x);
  7334. if (tempFloat >= 0)
  7335. tempFloat += 0.5f;
  7336. else
  7337. tempFloat -= 0.5f;
  7338. shapeBlock.PathShearX = (byte)tempFloat;
  7339. if (topshear.y < -0.5f)
  7340. {
  7341. topshear.y = -0.5f;
  7342. }
  7343. else if (topshear.y > 0.5f)
  7344. {
  7345. topshear.y = 0.5f;
  7346. }
  7347. tempFloat = (float)(100.0d * topshear.y);
  7348. if (tempFloat >= 0)
  7349. tempFloat += 0.5f;
  7350. else
  7351. tempFloat -= 0.5f;
  7352. shapeBlock.PathShearY = (byte)tempFloat;
  7353. if (profilecut.x < 0f)
  7354. {
  7355. profilecut.x = 0f;
  7356. }
  7357. else if (profilecut.x > 1f)
  7358. {
  7359. profilecut.x = 1f;
  7360. }
  7361. if (profilecut.y < 0f)
  7362. {
  7363. profilecut.y = 0f;
  7364. }
  7365. else if (profilecut.y > 1f)
  7366. {
  7367. profilecut.y = 1f;
  7368. }
  7369. if (profilecut.y - profilecut.x < 0.02f)
  7370. {
  7371. profilecut.x = profilecut.y - 0.02f;
  7372. if (profilecut.x < 0.0f)
  7373. {
  7374. profilecut.x = 0.0f;
  7375. profilecut.y = 0.02f;
  7376. }
  7377. }
  7378. shapeBlock.ProfileBegin = (ushort)(50000 * profilecut.x);
  7379. shapeBlock.ProfileEnd = (ushort)(50000 * (1 - profilecut.y));
  7380. if (taper_a.x < -1f)
  7381. {
  7382. taper_a.x = -1f;
  7383. }
  7384. if (taper_a.x > 1f)
  7385. {
  7386. taper_a.x = 1f;
  7387. }
  7388. tempFloat = 100.0f * (float)taper_a.x;
  7389. if (tempFloat >= 0)
  7390. tempFloat += 0.5f;
  7391. else
  7392. tempFloat -= 0.5f;
  7393. shapeBlock.PathTaperX = (sbyte)tempFloat;
  7394. if (taper_a.y < -1f)
  7395. {
  7396. taper_a.y = -1f;
  7397. }
  7398. else if (taper_a.y > 1f)
  7399. {
  7400. taper_a.y = 1f;
  7401. }
  7402. tempFloat = 100.0f * (float)taper_a.y;
  7403. if (tempFloat >= 0)
  7404. tempFloat += 0.5f;
  7405. else
  7406. tempFloat -= 0.5f;
  7407. shapeBlock.PathTaperY = (sbyte)tempFloat;
  7408. if (revolutions < 1f)
  7409. {
  7410. revolutions = 1f;
  7411. }
  7412. if (revolutions > 4f)
  7413. {
  7414. revolutions = 4f;
  7415. }
  7416. tempFloat = 66.66667f * (revolutions - 1.0f) + 0.5f;
  7417. shapeBlock.PathRevolutions = (byte)tempFloat;
  7418. // limits on radiusoffset depend on revolutions and hole size (how?) seems like the maximum range is 0 to 1
  7419. if (radiusoffset < 0f)
  7420. {
  7421. radiusoffset = 0f;
  7422. }
  7423. if (radiusoffset > 1f)
  7424. {
  7425. radiusoffset = 1f;
  7426. }
  7427. tempFloat = 100.0f * radiusoffset + 0.5f;
  7428. shapeBlock.PathRadiusOffset = (sbyte)tempFloat;
  7429. if (skew < -0.95f)
  7430. {
  7431. skew = -0.95f;
  7432. }
  7433. if (skew > 0.95f)
  7434. {
  7435. skew = 0.95f;
  7436. }
  7437. tempFloat = 100.0f * skew;
  7438. if (tempFloat >= 0)
  7439. tempFloat += 0.5f;
  7440. else
  7441. tempFloat -= 0.5f;
  7442. shapeBlock.PathSkew = (sbyte)tempFloat;
  7443. part.Shape.SculptEntry = false;
  7444. part.UpdateShape(shapeBlock);
  7445. }
  7446. // Prim type sculpt.
  7447. protected void SetPrimitiveShapeParams(SceneObjectPart part, string map, int type, byte pathcurve)
  7448. {
  7449. if (part == null || part.ParentGroup == null || part.ParentGroup.IsDeleted)
  7450. return;
  7451. ObjectShapePacket.ObjectDataBlock shapeBlock = new ObjectShapePacket.ObjectDataBlock();
  7452. UUID sculptId;
  7453. if (!UUID.TryParse(map, out sculptId))
  7454. sculptId = ScriptUtils.GetAssetIdFromItemName(m_host, map, (int)AssetType.Texture);
  7455. if (sculptId == UUID.Zero)
  7456. return;
  7457. shapeBlock.PathCurve = pathcurve;
  7458. shapeBlock.ObjectLocalID = part.LocalId;
  7459. shapeBlock.PathScaleX = 100;
  7460. shapeBlock.PathScaleY = 150;
  7461. int flag = type & (ScriptBaseClass.PRIM_SCULPT_FLAG_INVERT | ScriptBaseClass.PRIM_SCULPT_FLAG_MIRROR);
  7462. if (type != (ScriptBaseClass.PRIM_SCULPT_TYPE_CYLINDER | flag) &&
  7463. type != (ScriptBaseClass.PRIM_SCULPT_TYPE_PLANE | flag) &&
  7464. type != (ScriptBaseClass.PRIM_SCULPT_TYPE_SPHERE | flag) &&
  7465. type != (ScriptBaseClass.PRIM_SCULPT_TYPE_TORUS | flag))
  7466. {
  7467. // default
  7468. type = type | (int)ScriptBaseClass.PRIM_SCULPT_TYPE_SPHERE;
  7469. }
  7470. part.Shape.SetSculptProperties((byte)type, sculptId);
  7471. part.Shape.SculptEntry = true;
  7472. part.UpdateShape(shapeBlock);
  7473. }
  7474. public void llSetPrimitiveParams(LSL_List rules)
  7475. {
  7476. m_host.AddScriptLPS(1);
  7477. SetLinkPrimParams(ScriptBaseClass.LINK_THIS, rules, "llSetPrimitiveParams");
  7478. ScriptSleep(m_sleepMsOnSetPrimitiveParams);
  7479. }
  7480. public void llSetLinkPrimitiveParams(int linknumber, LSL_List rules)
  7481. {
  7482. m_host.AddScriptLPS(1);
  7483. SetLinkPrimParams(linknumber, rules, "llSetLinkPrimitiveParams");
  7484. ScriptSleep(m_sleepMsOnSetLinkPrimitiveParams);
  7485. }
  7486. public void llSetLinkPrimitiveParamsFast(int linknumber, LSL_List rules)
  7487. {
  7488. m_host.AddScriptLPS(1);
  7489. SetLinkPrimParams(linknumber, rules, "llSetLinkPrimitiveParamsFast");
  7490. }
  7491. private void SetLinkPrimParams(int linknumber, LSL_List rules, string originFunc)
  7492. {
  7493. List<object> parts = new List<object>();
  7494. List<SceneObjectPart> prims = GetLinkParts(linknumber);
  7495. List<ScenePresence> avatars = GetLinkAvatars(linknumber);
  7496. foreach (SceneObjectPart p in prims)
  7497. parts.Add(p);
  7498. foreach (ScenePresence p in avatars)
  7499. parts.Add(p);
  7500. LSL_List remaining = new LSL_List();
  7501. uint rulesParsed = 0;
  7502. if (parts.Count > 0)
  7503. {
  7504. foreach (object part in parts)
  7505. {
  7506. if (part is SceneObjectPart)
  7507. remaining = SetPrimParams((SceneObjectPart)part, rules, originFunc, ref rulesParsed);
  7508. else
  7509. remaining = SetPrimParams((ScenePresence)part, rules, originFunc, ref rulesParsed);
  7510. }
  7511. while (remaining.Length > 2)
  7512. {
  7513. linknumber = remaining.GetLSLIntegerItem(0);
  7514. rules = remaining.GetSublist(1, -1);
  7515. parts.Clear();
  7516. prims = GetLinkParts(linknumber);
  7517. avatars = GetLinkAvatars(linknumber);
  7518. foreach (SceneObjectPart p in prims)
  7519. parts.Add(p);
  7520. foreach (ScenePresence p in avatars)
  7521. parts.Add(p);
  7522. remaining = new LSL_List();
  7523. foreach (object part in parts)
  7524. {
  7525. if (part is SceneObjectPart)
  7526. remaining = SetPrimParams((SceneObjectPart)part, rules, originFunc, ref rulesParsed);
  7527. else
  7528. remaining = SetPrimParams((ScenePresence)part, rules, originFunc, ref rulesParsed);
  7529. }
  7530. }
  7531. }
  7532. }
  7533. public void llSetKeyframedMotion(LSL_List frames, LSL_List options)
  7534. {
  7535. SceneObjectGroup group = m_host.ParentGroup;
  7536. if (group.RootPart.PhysActor != null && group.RootPart.PhysActor.IsPhysical)
  7537. return;
  7538. if (group.IsAttachment)
  7539. return;
  7540. if (frames.Data.Length > 0) // We are getting a new motion
  7541. {
  7542. if (group.RootPart.KeyframeMotion != null)
  7543. group.RootPart.KeyframeMotion.Delete();
  7544. group.RootPart.KeyframeMotion = null;
  7545. int idx = 0;
  7546. KeyframeMotion.PlayMode mode = KeyframeMotion.PlayMode.Forward;
  7547. KeyframeMotion.DataFormat data = KeyframeMotion.DataFormat.Translation | KeyframeMotion.DataFormat.Rotation;
  7548. while (idx < options.Data.Length)
  7549. {
  7550. int option = (int)options.GetLSLIntegerItem(idx++);
  7551. int remain = options.Data.Length - idx;
  7552. switch (option)
  7553. {
  7554. case ScriptBaseClass.KFM_MODE:
  7555. if (remain < 1)
  7556. break;
  7557. int modeval = (int)options.GetLSLIntegerItem(idx++);
  7558. switch(modeval)
  7559. {
  7560. case ScriptBaseClass.KFM_FORWARD:
  7561. mode = KeyframeMotion.PlayMode.Forward;
  7562. break;
  7563. case ScriptBaseClass.KFM_REVERSE:
  7564. mode = KeyframeMotion.PlayMode.Reverse;
  7565. break;
  7566. case ScriptBaseClass.KFM_LOOP:
  7567. mode = KeyframeMotion.PlayMode.Loop;
  7568. break;
  7569. case ScriptBaseClass.KFM_PING_PONG:
  7570. mode = KeyframeMotion.PlayMode.PingPong;
  7571. break;
  7572. }
  7573. break;
  7574. case ScriptBaseClass.KFM_DATA:
  7575. if (remain < 1)
  7576. break;
  7577. int dataval = (int)options.GetLSLIntegerItem(idx++);
  7578. data = (KeyframeMotion.DataFormat)dataval;
  7579. break;
  7580. }
  7581. }
  7582. group.RootPart.KeyframeMotion = new KeyframeMotion(group, mode, data);
  7583. idx = 0;
  7584. int elemLength = 2;
  7585. if (data == (KeyframeMotion.DataFormat.Translation | KeyframeMotion.DataFormat.Rotation))
  7586. elemLength = 3;
  7587. List<KeyframeMotion.Keyframe> keyframes = new List<KeyframeMotion.Keyframe>();
  7588. while (idx < frames.Data.Length)
  7589. {
  7590. int remain = frames.Data.Length - idx;
  7591. if (remain < elemLength)
  7592. break;
  7593. KeyframeMotion.Keyframe frame = new KeyframeMotion.Keyframe();
  7594. frame.Position = null;
  7595. frame.Rotation = null;
  7596. if ((data & KeyframeMotion.DataFormat.Translation) != 0)
  7597. {
  7598. LSL_Types.Vector3 tempv = frames.GetVector3Item(idx++);
  7599. frame.Position = new Vector3((float)tempv.x, (float)tempv.y, (float)tempv.z);
  7600. }
  7601. if ((data & KeyframeMotion.DataFormat.Rotation) != 0)
  7602. {
  7603. LSL_Types.Quaternion tempq = frames.GetQuaternionItem(idx++);
  7604. Quaternion q = new Quaternion((float)tempq.x, (float)tempq.y, (float)tempq.z, (float)tempq.s);
  7605. q.Normalize();
  7606. frame.Rotation = q;
  7607. }
  7608. float tempf = (float)frames.GetLSLFloatItem(idx++);
  7609. frame.TimeMS = (int)(tempf * 1000.0f);
  7610. keyframes.Add(frame);
  7611. }
  7612. group.RootPart.KeyframeMotion.SetKeyframes(keyframes.ToArray());
  7613. group.RootPart.KeyframeMotion.Start();
  7614. }
  7615. else
  7616. {
  7617. if (group.RootPart.KeyframeMotion == null)
  7618. return;
  7619. if (options.Data.Length == 0)
  7620. {
  7621. group.RootPart.KeyframeMotion.Stop();
  7622. return;
  7623. }
  7624. int idx = 0;
  7625. while (idx < options.Data.Length)
  7626. {
  7627. int option = (int)options.GetLSLIntegerItem(idx++);
  7628. switch (option)
  7629. {
  7630. case ScriptBaseClass.KFM_COMMAND:
  7631. int cmd = (int)options.GetLSLIntegerItem(idx++);
  7632. switch (cmd)
  7633. {
  7634. case ScriptBaseClass.KFM_CMD_PLAY:
  7635. group.RootPart.KeyframeMotion.Start();
  7636. break;
  7637. case ScriptBaseClass.KFM_CMD_STOP:
  7638. group.RootPart.KeyframeMotion.Stop();
  7639. break;
  7640. case ScriptBaseClass.KFM_CMD_PAUSE:
  7641. group.RootPart.KeyframeMotion.Pause();
  7642. break;
  7643. }
  7644. break;
  7645. }
  7646. }
  7647. }
  7648. }
  7649. public LSL_List llGetPhysicsMaterial()
  7650. {
  7651. LSL_List result = new LSL_List();
  7652. result.Add(new LSL_Float(m_host.GravityModifier));
  7653. result.Add(new LSL_Float(m_host.Restitution));
  7654. result.Add(new LSL_Float(m_host.Friction));
  7655. result.Add(new LSL_Float(m_host.Density));
  7656. return result;
  7657. }
  7658. private void SetPhysicsMaterial(SceneObjectPart part, int material_bits,
  7659. float material_density, float material_friction,
  7660. float material_restitution, float material_gravity_modifier)
  7661. {
  7662. ExtraPhysicsData physdata = new ExtraPhysicsData();
  7663. physdata.PhysShapeType = (PhysShapeType)part.PhysicsShapeType;
  7664. physdata.Density = part.Density;
  7665. physdata.Friction = part.Friction;
  7666. physdata.Bounce = part.Restitution;
  7667. physdata.GravitationModifier = part.GravityModifier;
  7668. if ((material_bits & (int)ScriptBaseClass.DENSITY) != 0)
  7669. physdata.Density = material_density;
  7670. if ((material_bits & (int)ScriptBaseClass.FRICTION) != 0)
  7671. physdata.Friction = material_friction;
  7672. if ((material_bits & (int)ScriptBaseClass.RESTITUTION) != 0)
  7673. physdata.Bounce = material_restitution;
  7674. if ((material_bits & (int)ScriptBaseClass.GRAVITY_MULTIPLIER) != 0)
  7675. physdata.GravitationModifier = material_gravity_modifier;
  7676. part.UpdateExtraPhysics(physdata);
  7677. }
  7678. public void llSetPhysicsMaterial(int material_bits,
  7679. LSL_Float material_gravity_modifier, LSL_Float material_restitution,
  7680. LSL_Float material_friction, LSL_Float material_density)
  7681. {
  7682. SetPhysicsMaterial(m_host, material_bits, (float)material_density, (float)material_friction, (float)material_restitution, (float)material_gravity_modifier);
  7683. }
  7684. // vector up using libomv (c&p from sop )
  7685. // vector up rotated by r
  7686. private Vector3 Zrot(Quaternion r)
  7687. {
  7688. double x, y, z, m;
  7689. m = r.X * r.X + r.Y * r.Y + r.Z * r.Z + r.W * r.W;
  7690. if (Math.Abs(1.0 - m) > 0.000001)
  7691. {
  7692. m = 1.0 / Math.Sqrt(m);
  7693. r.X *= (float)m;
  7694. r.Y *= (float)m;
  7695. r.Z *= (float)m;
  7696. r.W *= (float)m;
  7697. }
  7698. x = 2 * (r.X * r.Z + r.Y * r.W);
  7699. y = 2 * (-r.X * r.W + r.Y * r.Z);
  7700. z = -r.X * r.X - r.Y * r.Y + r.Z * r.Z + r.W * r.W;
  7701. return new Vector3((float)x, (float)y, (float)z);
  7702. }
  7703. protected LSL_List SetPrimParams(SceneObjectPart part, LSL_List rules, string originFunc, ref uint rulesParsed)
  7704. {
  7705. if (part == null || part.ParentGroup == null || part.ParentGroup.IsDeleted)
  7706. return new LSL_List();
  7707. int idx = 0;
  7708. int idxStart = 0;
  7709. SceneObjectGroup parentgrp = part.ParentGroup;
  7710. bool positionChanged = false;
  7711. bool materialChanged = false;
  7712. LSL_Vector currentPosition = GetPartLocalPos(part);
  7713. try
  7714. {
  7715. while (idx < rules.Length)
  7716. {
  7717. ++rulesParsed;
  7718. int code = rules.GetLSLIntegerItem(idx++);
  7719. int remain = rules.Length - idx;
  7720. idxStart = idx;
  7721. int face;
  7722. LSL_Vector v;
  7723. switch (code)
  7724. {
  7725. case ScriptBaseClass.PRIM_POSITION:
  7726. case ScriptBaseClass.PRIM_POS_LOCAL:
  7727. if (remain < 1)
  7728. return new LSL_List();
  7729. try
  7730. {
  7731. v = rules.GetVector3Item(idx++);
  7732. }
  7733. catch(InvalidCastException)
  7734. {
  7735. if(code == ScriptBaseClass.PRIM_POSITION)
  7736. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_POSITION: arg #{1} - parameter 1 must be vector", rulesParsed, idx - idxStart - 1));
  7737. else
  7738. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_POS_LOCAL: arg #{1} - parameter 1 must be vector", rulesParsed, idx - idxStart - 1));
  7739. return new LSL_List();
  7740. }
  7741. if (part.IsRoot && !part.ParentGroup.IsAttachment)
  7742. currentPosition = GetSetPosTarget(part, v, currentPosition, true);
  7743. else
  7744. currentPosition = GetSetPosTarget(part, v, currentPosition, false);
  7745. positionChanged = true;
  7746. break;
  7747. case ScriptBaseClass.PRIM_SIZE:
  7748. if (remain < 1)
  7749. return new LSL_List();
  7750. v=rules.GetVector3Item(idx++);
  7751. SetScale(part, v);
  7752. break;
  7753. case ScriptBaseClass.PRIM_ROTATION:
  7754. if (remain < 1)
  7755. return new LSL_List();
  7756. LSL_Rotation q;
  7757. try
  7758. {
  7759. q = rules.GetQuaternionItem(idx++);
  7760. }
  7761. catch(InvalidCastException)
  7762. {
  7763. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_ROTATION: arg #{1} - parameter 1 must be rotation", rulesParsed, idx - idxStart - 1));
  7764. return new LSL_List();
  7765. }
  7766. // try to let this work as in SL...
  7767. if (part.ParentID == 0 || (part.ParentGroup != null && part == part.ParentGroup.RootPart))
  7768. {
  7769. // special case: If we are root, rotate complete SOG to new rotation
  7770. SetRot(part, q);
  7771. }
  7772. else
  7773. {
  7774. // we are a child. The rotation values will be set to the one of root modified by rot, as in SL. Don't ask.
  7775. SceneObjectPart rootPart = part.ParentGroup.RootPart;
  7776. SetRot(part, rootPart.RotationOffset * (Quaternion)q);
  7777. }
  7778. break;
  7779. case ScriptBaseClass.PRIM_TYPE:
  7780. if (remain < 3)
  7781. return new LSL_List();
  7782. try
  7783. {
  7784. code = (int)rules.GetLSLIntegerItem(idx++);
  7785. }
  7786. catch(InvalidCastException)
  7787. {
  7788. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TYPE: arg #{1} - parameter 1 must be integer", rulesParsed, idx - idxStart - 1));
  7789. return new LSL_List();
  7790. }
  7791. remain = rules.Length - idx;
  7792. float hollow;
  7793. LSL_Vector twist;
  7794. LSL_Vector taper_b;
  7795. LSL_Vector topshear;
  7796. float revolutions;
  7797. float radiusoffset;
  7798. float skew;
  7799. LSL_Vector holesize;
  7800. LSL_Vector profilecut;
  7801. switch (code)
  7802. {
  7803. case ScriptBaseClass.PRIM_TYPE_BOX:
  7804. if (remain < 6)
  7805. return new LSL_List();
  7806. try
  7807. {
  7808. face = (int)rules.GetLSLIntegerItem(idx++);
  7809. }
  7810. catch(InvalidCastException)
  7811. {
  7812. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TYPE, PRIM_TYPE_BOX: arg #{1} - parameter 2 must be integer", rulesParsed, idx - idxStart - 1));
  7813. return new LSL_List();
  7814. }
  7815. try
  7816. {
  7817. v = rules.GetVector3Item(idx++); // cut
  7818. }
  7819. catch(InvalidCastException)
  7820. {
  7821. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TYPE, PRIM_TYPE_BOX: arg #{1} - parameter 3 must be vector", rulesParsed, idx - idxStart - 1));
  7822. return new LSL_List();
  7823. }
  7824. try
  7825. {
  7826. hollow = (float)rules.GetLSLFloatItem(idx++);
  7827. }
  7828. catch(InvalidCastException)
  7829. {
  7830. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TYPE, PRIM_TYPE_BOX: arg #{1} - parameter 4 must be float", rulesParsed, idx - idxStart - 1));
  7831. return new LSL_List();
  7832. }
  7833. try
  7834. {
  7835. twist = rules.GetVector3Item(idx++);
  7836. }
  7837. catch(InvalidCastException)
  7838. {
  7839. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TYPE, PRIM_TYPE_BOX: arg #{1} - parameter 5 must be vector", rulesParsed, idx - idxStart - 1));
  7840. return new LSL_List();
  7841. }
  7842. try
  7843. {
  7844. taper_b = rules.GetVector3Item(idx++);
  7845. }
  7846. catch(InvalidCastException)
  7847. {
  7848. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TYPE, PRIM_TYPE_BOX: arg #{1} - parameter 6 must be vector", rulesParsed, idx - idxStart - 1));
  7849. return new LSL_List();
  7850. }
  7851. try
  7852. {
  7853. topshear = rules.GetVector3Item(idx++);
  7854. }
  7855. catch(InvalidCastException)
  7856. {
  7857. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TYPE, PRIM_TYPE_BOX: arg #{1} - parameter 7 must be vector", rulesParsed, idx - idxStart - 1));
  7858. return new LSL_List();
  7859. }
  7860. SetPrimitiveShapeParams(part, face, v, hollow, twist, taper_b, topshear,
  7861. (byte)ProfileShape.Square, (byte)Extrusion.Straight);
  7862. break;
  7863. case ScriptBaseClass.PRIM_TYPE_CYLINDER:
  7864. if (remain < 6)
  7865. return new LSL_List();
  7866. try
  7867. {
  7868. face = (int)rules.GetLSLIntegerItem(idx++); // holeshape
  7869. }
  7870. catch(InvalidCastException)
  7871. {
  7872. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TYPE, PRIM_TYPE_CYLINDER: arg #{1} - parameter 3 must be integer", rulesParsed, idx - idxStart - 1));
  7873. return new LSL_List();
  7874. }
  7875. try
  7876. {
  7877. v = rules.GetVector3Item(idx++); // cut
  7878. }
  7879. catch(InvalidCastException)
  7880. {
  7881. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TYPE, PRIM_TYPE_CYLINDER: arg #{1} - parameter 4 must be vector", rulesParsed, idx - idxStart - 1));
  7882. return new LSL_List();
  7883. }
  7884. try
  7885. {
  7886. hollow = (float)rules.GetLSLFloatItem(idx++);
  7887. }
  7888. catch(InvalidCastException)
  7889. {
  7890. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TYPE, PRIM_TYPE_CYLINDER: arg #{1} - parameter 5 must be float", rulesParsed, idx - idxStart - 1));
  7891. return new LSL_List();
  7892. }
  7893. try
  7894. {
  7895. twist = rules.GetVector3Item(idx++);
  7896. }
  7897. catch(InvalidCastException)
  7898. {
  7899. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TYPE, PRIM_TYPE_CYLINDER: arg #{1} - parameter 6 must be vector", rulesParsed, idx - idxStart - 1));
  7900. return new LSL_List();
  7901. }
  7902. try
  7903. {
  7904. taper_b = rules.GetVector3Item(idx++);
  7905. }
  7906. catch(InvalidCastException)
  7907. {
  7908. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TYPE, PRIM_TYPE_CYLINDER: arg #{1} - parameter 7 must be vector", rulesParsed, idx - idxStart - 1));
  7909. return new LSL_List();
  7910. }
  7911. try
  7912. {
  7913. topshear = rules.GetVector3Item(idx++);
  7914. }
  7915. catch(InvalidCastException)
  7916. {
  7917. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TYPE, PRIM_TYPE_CYLINDER: arg #{1} - parameter 8 must be vector", rulesParsed, idx - idxStart - 1));
  7918. return new LSL_List();
  7919. }
  7920. SetPrimitiveShapeParams(part, face, v, hollow, twist, taper_b, topshear,
  7921. (byte)ProfileShape.Circle, (byte)Extrusion.Straight);
  7922. break;
  7923. case ScriptBaseClass.PRIM_TYPE_PRISM:
  7924. if (remain < 6)
  7925. return new LSL_List();
  7926. try
  7927. {
  7928. face = (int)rules.GetLSLIntegerItem(idx++); // holeshape
  7929. }
  7930. catch(InvalidCastException)
  7931. {
  7932. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TYPE, PRIM_TYPE_PRISM: arg #{1} - parameter 3 must be integer", rulesParsed, idx - idxStart - 1));
  7933. return new LSL_List();
  7934. }
  7935. try
  7936. {
  7937. v = rules.GetVector3Item(idx++); //cut
  7938. }
  7939. catch(InvalidCastException)
  7940. {
  7941. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TYPE, PRIM_TYPE_PRISM: arg #{1} - parameter 4 must be vector", rulesParsed, idx - idxStart - 1));
  7942. return new LSL_List();
  7943. }
  7944. try
  7945. {
  7946. hollow = (float)rules.GetLSLFloatItem(idx++);
  7947. }
  7948. catch(InvalidCastException)
  7949. {
  7950. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TYPE, PRIM_TYPE_PRISM: arg #{1} - parameter 5 must be float", rulesParsed, idx - idxStart - 1));
  7951. return new LSL_List();
  7952. }
  7953. try
  7954. {
  7955. twist = rules.GetVector3Item(idx++);
  7956. }
  7957. catch(InvalidCastException)
  7958. {
  7959. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TYPE, PRIM_TYPE_PRISM: arg #{1} - parameter 6 must be vector", rulesParsed, idx - idxStart - 1));
  7960. return new LSL_List();
  7961. }
  7962. try
  7963. {
  7964. taper_b = rules.GetVector3Item(idx++);
  7965. }
  7966. catch(InvalidCastException)
  7967. {
  7968. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TYPE, PRIM_TYPE_PRISM: arg #{1} - parameter 7 must be vector", rulesParsed, idx - idxStart - 1));
  7969. return new LSL_List();
  7970. }
  7971. try
  7972. {
  7973. topshear = rules.GetVector3Item(idx++);
  7974. }
  7975. catch(InvalidCastException)
  7976. {
  7977. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TYPE, PRIM_TYPE_PRISM: arg #{1} - parameter 8 must be vector", rulesParsed, idx - idxStart - 1));
  7978. return new LSL_List();
  7979. }
  7980. SetPrimitiveShapeParams(part, face, v, hollow, twist, taper_b, topshear,
  7981. (byte)ProfileShape.EquilateralTriangle, (byte)Extrusion.Straight);
  7982. break;
  7983. case ScriptBaseClass.PRIM_TYPE_SPHERE:
  7984. if (remain < 5)
  7985. return new LSL_List();
  7986. try
  7987. {
  7988. face = (int)rules.GetLSLIntegerItem(idx++); // holeshape
  7989. }
  7990. catch(InvalidCastException)
  7991. {
  7992. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TYPE, PRIM_TYPE_SPHERE: arg #{1} - parameter 3 must be integer", rulesParsed, idx - idxStart - 1));
  7993. return new LSL_List();
  7994. }
  7995. try
  7996. {
  7997. v = rules.GetVector3Item(idx++); // cut
  7998. }
  7999. catch(InvalidCastException)
  8000. {
  8001. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TYPE, PRIM_TYPE_SPHERE: arg #{1} - parameter 4 must be vector", rulesParsed, idx - idxStart - 1));
  8002. return new LSL_List();
  8003. }
  8004. try
  8005. {
  8006. hollow = (float)rules.GetLSLFloatItem(idx++);
  8007. }
  8008. catch(InvalidCastException)
  8009. {
  8010. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TYPE, PRIM_TYPE_SPHERE: arg #{1} - parameter 5 must be float", rulesParsed, idx - idxStart - 1));
  8011. return new LSL_List();
  8012. }
  8013. try
  8014. {
  8015. twist = rules.GetVector3Item(idx++);
  8016. }
  8017. catch(InvalidCastException)
  8018. {
  8019. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TYPE, PRIM_TYPE_SPHERE: arg #{1} - parameter 6 must be vector", rulesParsed, idx - idxStart - 1));
  8020. return new LSL_List();
  8021. }
  8022. try
  8023. {
  8024. taper_b = rules.GetVector3Item(idx++); // dimple
  8025. }
  8026. catch(InvalidCastException)
  8027. {
  8028. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TYPE, PRIM_TYPE_SPHERE: arg #{1} - parameter 7 must be vector", rulesParsed, idx - idxStart - 1));
  8029. return new LSL_List();
  8030. }
  8031. SetPrimitiveShapeParams(part, face, v, hollow, twist, taper_b,
  8032. (byte)ProfileShape.HalfCircle, (byte)Extrusion.Curve1);
  8033. break;
  8034. case ScriptBaseClass.PRIM_TYPE_TORUS:
  8035. if (remain < 11)
  8036. return new LSL_List();
  8037. try
  8038. {
  8039. face = (int)rules.GetLSLIntegerItem(idx++); // holeshape
  8040. }
  8041. catch(InvalidCastException)
  8042. {
  8043. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TYPE, PRIM_TYPE_TORUS: arg #{1} - parameter 3 must be integer", rulesParsed, idx - idxStart - 1));
  8044. return new LSL_List();
  8045. }
  8046. try
  8047. {
  8048. v = rules.GetVector3Item(idx++); //cut
  8049. }
  8050. catch(InvalidCastException)
  8051. {
  8052. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TYPE, PRIM_TYPE_TORUS: arg #{1} - parameter 4 must be vector", rulesParsed, idx - idxStart - 1));
  8053. return new LSL_List();
  8054. }
  8055. try
  8056. {
  8057. hollow = (float)rules.GetLSLFloatItem(idx++);
  8058. }
  8059. catch(InvalidCastException)
  8060. {
  8061. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TYPE, PRIM_TYPE_TORUS: arg #{1} - parameter 5 must be float", rulesParsed, idx - idxStart - 1));
  8062. return new LSL_List();
  8063. }
  8064. try
  8065. {
  8066. twist = rules.GetVector3Item(idx++);
  8067. }
  8068. catch(InvalidCastException)
  8069. {
  8070. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TYPE, PRIM_TYPE_TORUS: arg #{1} - parameter 6 must be vector", rulesParsed, idx - idxStart - 1));
  8071. return new LSL_List();
  8072. }
  8073. try
  8074. {
  8075. holesize = rules.GetVector3Item(idx++);
  8076. }
  8077. catch(InvalidCastException)
  8078. {
  8079. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TYPE, PRIM_TYPE_TORUS: arg #{1} - parameter 7 must be vector", rulesParsed, idx - idxStart - 1));
  8080. return new LSL_List();
  8081. }
  8082. try
  8083. {
  8084. topshear = rules.GetVector3Item(idx++);
  8085. }
  8086. catch(InvalidCastException)
  8087. {
  8088. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TYPE, PRIM_TYPE_TORUS: arg #{1} - parameter 8 must be vector", rulesParsed, idx - idxStart - 1));
  8089. return new LSL_List();
  8090. }
  8091. try
  8092. {
  8093. profilecut = rules.GetVector3Item(idx++);
  8094. }
  8095. catch(InvalidCastException)
  8096. {
  8097. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TYPE, PRIM_TYPE_TORUS: arg #{1} - parameter 9 must be vector", rulesParsed, idx - idxStart - 1));
  8098. return new LSL_List();
  8099. }
  8100. try
  8101. {
  8102. taper_b = rules.GetVector3Item(idx++); // taper_a
  8103. }
  8104. catch(InvalidCastException)
  8105. {
  8106. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TYPE, PRIM_TYPE_TORUS: arg #{1} - parameter 10 must be vector", rulesParsed, idx - idxStart - 1));
  8107. return new LSL_List();
  8108. }
  8109. try
  8110. {
  8111. revolutions = (float)rules.GetLSLFloatItem(idx++);
  8112. }
  8113. catch(InvalidCastException)
  8114. {
  8115. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TYPE, PRIM_TYPE_TORUS: arg #{1} - parameter 11 must be float", rulesParsed, idx - idxStart - 1));
  8116. return new LSL_List();
  8117. }
  8118. try
  8119. {
  8120. radiusoffset = (float)rules.GetLSLFloatItem(idx++);
  8121. }
  8122. catch(InvalidCastException)
  8123. {
  8124. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TYPE, PRIM_TYPE_TORUS: arg #{1} - parameter 12 must be float", rulesParsed, idx - idxStart - 1));
  8125. return new LSL_List();
  8126. }
  8127. try
  8128. {
  8129. skew = (float)rules.GetLSLFloatItem(idx++);
  8130. }
  8131. catch(InvalidCastException)
  8132. {
  8133. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TYPE, PRIM_TYPE_TORUS: arg #{1} - parameter 13 must be vector", rulesParsed, idx - idxStart - 1));
  8134. return new LSL_List();
  8135. }
  8136. SetPrimitiveShapeParams(part, face, v, hollow, twist, holesize, topshear, profilecut, taper_b,
  8137. revolutions, radiusoffset, skew, (byte)ProfileShape.Circle, (byte)Extrusion.Curve1);
  8138. break;
  8139. case ScriptBaseClass.PRIM_TYPE_TUBE:
  8140. if (remain < 11)
  8141. return new LSL_List();
  8142. try
  8143. {
  8144. face = (int)rules.GetLSLIntegerItem(idx++); // holeshape
  8145. }
  8146. catch(InvalidCastException)
  8147. {
  8148. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TYPE, PRIM_TYPE_TUBE: arg #{1} - parameter 3 must be integer", rulesParsed, idx - idxStart - 1));
  8149. return new LSL_List();
  8150. }
  8151. try
  8152. {
  8153. v = rules.GetVector3Item(idx++); //cut
  8154. }
  8155. catch(InvalidCastException)
  8156. {
  8157. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TYPE, PRIM_TYPE_TUBE: arg #{1} - parameter 4 must be vector", rulesParsed, idx - idxStart - 1));
  8158. return new LSL_List();
  8159. }
  8160. try
  8161. {
  8162. hollow = (float)rules.GetLSLFloatItem(idx++);
  8163. }
  8164. catch(InvalidCastException)
  8165. {
  8166. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TYPE, PRIM_TYPE_TUBE: arg #{1} - parameter 5 must be float", rulesParsed, idx - idxStart - 1));
  8167. return new LSL_List();
  8168. }
  8169. try
  8170. {
  8171. twist = rules.GetVector3Item(idx++);
  8172. }
  8173. catch(InvalidCastException)
  8174. {
  8175. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TYPE, PRIM_TYPE_TUBE: arg #{1} - parameter 6 must be vector", rulesParsed, idx - idxStart - 1));
  8176. return new LSL_List();
  8177. }
  8178. try
  8179. {
  8180. holesize = rules.GetVector3Item(idx++);
  8181. }
  8182. catch(InvalidCastException)
  8183. {
  8184. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TYPE, PRIM_TYPE_TUBE: arg #{1} - parameter 7 must be vector", rulesParsed, idx - idxStart - 1));
  8185. return new LSL_List();
  8186. }
  8187. try
  8188. {
  8189. topshear = rules.GetVector3Item(idx++);
  8190. }
  8191. catch(InvalidCastException)
  8192. {
  8193. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TYPE, PRIM_TYPE_TUBE: arg #{1} - parameter 8 must be vector", rulesParsed, idx - idxStart - 1));
  8194. return new LSL_List();
  8195. }
  8196. try
  8197. {
  8198. profilecut = rules.GetVector3Item(idx++);
  8199. }
  8200. catch(InvalidCastException)
  8201. {
  8202. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TYPE, PRIM_TYPE_TUBE: arg #{1} - parameter 9 must be vector", rulesParsed, idx - idxStart - 1));
  8203. return new LSL_List();
  8204. }
  8205. try
  8206. {
  8207. taper_b = rules.GetVector3Item(idx++); // taper_a
  8208. }
  8209. catch(InvalidCastException)
  8210. {
  8211. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TYPE, PRIM_TYPE_TUBE: arg #{1} - parameter 10 must be vector", rulesParsed, idx - idxStart - 1));
  8212. return new LSL_List();
  8213. }
  8214. try
  8215. {
  8216. revolutions = (float)rules.GetLSLFloatItem(idx++);
  8217. }
  8218. catch(InvalidCastException)
  8219. {
  8220. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TYPE, PRIM_TYPE_TUBE: arg #{1} - parameter 11 must be float", rulesParsed, idx - idxStart - 1));
  8221. return new LSL_List();
  8222. }
  8223. try
  8224. {
  8225. radiusoffset = (float)rules.GetLSLFloatItem(idx++);
  8226. }
  8227. catch(InvalidCastException)
  8228. {
  8229. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TYPE, PRIM_TYPE_TUBE: arg #{1} - parameter 12 must be float", rulesParsed, idx - idxStart - 1));
  8230. return new LSL_List();
  8231. }
  8232. try
  8233. {
  8234. skew = (float)rules.GetLSLFloatItem(idx++);
  8235. }
  8236. catch(InvalidCastException)
  8237. {
  8238. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TYPE, PRIM_TYPE_TUBE: arg #{1} - parameter 13 must be float", rulesParsed, idx - idxStart - 1));
  8239. return new LSL_List();
  8240. }
  8241. SetPrimitiveShapeParams(part, face, v, hollow, twist, holesize, topshear, profilecut, taper_b,
  8242. revolutions, radiusoffset, skew, (byte)ProfileShape.Square, (byte)Extrusion.Curve1);
  8243. break;
  8244. case ScriptBaseClass.PRIM_TYPE_RING:
  8245. if (remain < 11)
  8246. return new LSL_List();
  8247. try
  8248. {
  8249. face = (int)rules.GetLSLIntegerItem(idx++); // holeshape
  8250. }
  8251. catch(InvalidCastException)
  8252. {
  8253. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TYPE, PRIM_TYPE_RING: arg #{1} - parameter 3 must be integer", rulesParsed, idx - idxStart - 1));
  8254. return new LSL_List();
  8255. }
  8256. try
  8257. {
  8258. v = rules.GetVector3Item(idx++); //cut
  8259. }
  8260. catch(InvalidCastException)
  8261. {
  8262. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TYPE, PRIM_TYPE_RING: arg #{1} - parameter 4 must be vector", rulesParsed, idx - idxStart - 1));
  8263. return new LSL_List();
  8264. }
  8265. try
  8266. {
  8267. hollow = (float)rules.GetLSLFloatItem(idx++);
  8268. }
  8269. catch(InvalidCastException)
  8270. {
  8271. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TYPE, PRIM_TYPE_RING: arg #{1} - parameter 5 must be float", rulesParsed, idx - idxStart - 1));
  8272. return new LSL_List();
  8273. }
  8274. try
  8275. {
  8276. twist = rules.GetVector3Item(idx++);
  8277. }
  8278. catch(InvalidCastException)
  8279. {
  8280. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TYPE, PRIM_TYPE_RING: arg #{1} - parameter 6 must be vector", rulesParsed, idx - idxStart - 1));
  8281. return new LSL_List();
  8282. }
  8283. try
  8284. {
  8285. holesize = rules.GetVector3Item(idx++);
  8286. }
  8287. catch(InvalidCastException)
  8288. {
  8289. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TYPE, PRIM_TYPE_RING: arg #{1} - parameter 7 must be vector", rulesParsed, idx - idxStart - 1));
  8290. return new LSL_List();
  8291. }
  8292. try
  8293. {
  8294. topshear = rules.GetVector3Item(idx++);
  8295. }
  8296. catch(InvalidCastException)
  8297. {
  8298. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TYPE, PRIM_TYPE_RING: arg #{1} - parameter 8 must be vector", rulesParsed, idx - idxStart - 1));
  8299. return new LSL_List();
  8300. }
  8301. try
  8302. {
  8303. profilecut = rules.GetVector3Item(idx++);
  8304. }
  8305. catch(InvalidCastException)
  8306. {
  8307. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TYPE, PRIM_TYPE_RING: arg #{1} - parameter 9 must be vector", rulesParsed, idx - idxStart - 1));
  8308. return new LSL_List();
  8309. }
  8310. try
  8311. {
  8312. taper_b = rules.GetVector3Item(idx++); // taper_a
  8313. }
  8314. catch(InvalidCastException)
  8315. {
  8316. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TYPE, PRIM_TYPE_RING: arg #{1} - parameter 10 must be vector", rulesParsed, idx - idxStart - 1));
  8317. return new LSL_List();
  8318. }
  8319. try
  8320. {
  8321. revolutions = (float)rules.GetLSLFloatItem(idx++);
  8322. }
  8323. catch(InvalidCastException)
  8324. {
  8325. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TYPE, PRIM_TYPE_RING: arg #{1} - parameter 11 must be float", rulesParsed, idx - idxStart - 1));
  8326. return new LSL_List();
  8327. }
  8328. try
  8329. {
  8330. radiusoffset = (float)rules.GetLSLFloatItem(idx++);
  8331. }
  8332. catch(InvalidCastException)
  8333. {
  8334. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TYPE, PRIM_TYPE_RING: arg #{1} - parameter 12 must be float", rulesParsed, idx - idxStart - 1));
  8335. return new LSL_List();
  8336. }
  8337. try
  8338. {
  8339. skew = (float)rules.GetLSLFloatItem(idx++);
  8340. }
  8341. catch(InvalidCastException)
  8342. {
  8343. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TYPE, PRIM_TYPE_RING: arg #{1} - parameter 13 must be float", rulesParsed, idx - idxStart - 1));
  8344. return new LSL_List();
  8345. }
  8346. SetPrimitiveShapeParams(part, face, v, hollow, twist, holesize, topshear, profilecut, taper_b,
  8347. revolutions, radiusoffset, skew, (byte)ProfileShape.EquilateralTriangle, (byte)Extrusion.Curve1);
  8348. break;
  8349. case ScriptBaseClass.PRIM_TYPE_SCULPT:
  8350. if (remain < 2)
  8351. return new LSL_List();
  8352. string map = rules.Data[idx++].ToString();
  8353. try
  8354. {
  8355. face = (int)rules.GetLSLIntegerItem(idx++); // type
  8356. }
  8357. catch(InvalidCastException)
  8358. {
  8359. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TYPE, PRIM_TYPE_SCULPT: arg #{1} - parameter 4 must be integer", rulesParsed, idx - idxStart - 1));
  8360. return new LSL_List();
  8361. }
  8362. SetPrimitiveShapeParams(part, map, face, (byte)Extrusion.Curve1);
  8363. break;
  8364. }
  8365. break;
  8366. case ScriptBaseClass.PRIM_TEXTURE:
  8367. if (remain < 5)
  8368. return new LSL_List();
  8369. face=(int)rules.GetLSLIntegerItem(idx++);
  8370. string tex;
  8371. LSL_Vector repeats;
  8372. LSL_Vector offsets;
  8373. double rotation;
  8374. tex = rules.Data[idx++].ToString();
  8375. try
  8376. {
  8377. repeats = rules.GetVector3Item(idx++);
  8378. }
  8379. catch(InvalidCastException)
  8380. {
  8381. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TEXTURE: arg #{1} - parameter 3 must be vector", rulesParsed, idx - idxStart - 1));
  8382. return new LSL_List();
  8383. }
  8384. try
  8385. {
  8386. offsets = rules.GetVector3Item(idx++);
  8387. }
  8388. catch(InvalidCastException)
  8389. {
  8390. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TEXTURE: arg #{1} - parameter 4 must be vector", rulesParsed, idx - idxStart - 1));
  8391. return new LSL_List();
  8392. }
  8393. try
  8394. {
  8395. rotation = (double)rules.GetLSLFloatItem(idx++);
  8396. }
  8397. catch(InvalidCastException)
  8398. {
  8399. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TEXTURE: arg #{1} - parameter 5 must be float", rulesParsed, idx - idxStart - 1));
  8400. return new LSL_List();
  8401. }
  8402. SetTexture(part, tex, face);
  8403. ScaleTexture(part, repeats.x, repeats.y, face);
  8404. OffsetTexture(part, offsets.x, offsets.y, face);
  8405. RotateTexture(part, rotation, face);
  8406. break;
  8407. case ScriptBaseClass.PRIM_COLOR:
  8408. if (remain < 3)
  8409. return new LSL_List();
  8410. LSL_Vector color;
  8411. double alpha;
  8412. try
  8413. {
  8414. face = (int)rules.GetLSLIntegerItem(idx++);
  8415. }
  8416. catch(InvalidCastException)
  8417. {
  8418. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_COLOR: arg #{1} - parameter 2 must be integer", rulesParsed, idx - idxStart - 1));
  8419. return new LSL_List();
  8420. }
  8421. try
  8422. {
  8423. color = rules.GetVector3Item(idx++);
  8424. }
  8425. catch(InvalidCastException)
  8426. {
  8427. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_COLOR: arg #{1} - parameter 3 must be vector", rulesParsed, idx - idxStart - 1));
  8428. return new LSL_List();
  8429. }
  8430. try
  8431. {
  8432. alpha = (double)rules.GetLSLFloatItem(idx++);
  8433. }
  8434. catch(InvalidCastException)
  8435. {
  8436. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_COLOR: arg #{1} - parameter 4 must be float", rulesParsed, idx - idxStart - 1));
  8437. return new LSL_List();
  8438. }
  8439. part.SetFaceColorAlpha(face, color, alpha);
  8440. break;
  8441. case ScriptBaseClass.PRIM_FLEXIBLE:
  8442. if (remain < 7)
  8443. return new LSL_List();
  8444. bool flexi;
  8445. int softness;
  8446. float gravity;
  8447. float friction;
  8448. float wind;
  8449. float tension;
  8450. LSL_Vector force;
  8451. try
  8452. {
  8453. flexi = rules.GetLSLIntegerItem(idx++);
  8454. }
  8455. catch(InvalidCastException)
  8456. {
  8457. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_FLEXIBLE: arg #{1} - parameter 2 must be integer", rulesParsed, idx - idxStart - 1));
  8458. return new LSL_List();
  8459. }
  8460. try
  8461. {
  8462. softness = rules.GetLSLIntegerItem(idx++);
  8463. }
  8464. catch(InvalidCastException)
  8465. {
  8466. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_FLEXIBLE: arg #{1} - parameter 3 must be integer", rulesParsed, idx - idxStart - 1));
  8467. return new LSL_List();
  8468. }
  8469. try
  8470. {
  8471. gravity = (float)rules.GetLSLFloatItem(idx++);
  8472. }
  8473. catch(InvalidCastException)
  8474. {
  8475. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_FLEXIBLE: arg #{1} - parameter 4 must be float", rulesParsed, idx - idxStart - 1));
  8476. return new LSL_List();
  8477. }
  8478. try
  8479. {
  8480. friction = (float)rules.GetLSLFloatItem(idx++);
  8481. }
  8482. catch(InvalidCastException)
  8483. {
  8484. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_FLEXIBLE: arg #{1} - parameter 5 must be float", rulesParsed, idx - idxStart - 1));
  8485. return new LSL_List();
  8486. }
  8487. try
  8488. {
  8489. wind = (float)rules.GetLSLFloatItem(idx++);
  8490. }
  8491. catch(InvalidCastException)
  8492. {
  8493. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_FLEXIBLE: arg #{1} - parameter 6 must be float", rulesParsed, idx - idxStart - 1));
  8494. return new LSL_List();
  8495. }
  8496. try
  8497. {
  8498. tension = (float)rules.GetLSLFloatItem(idx++);
  8499. }
  8500. catch(InvalidCastException)
  8501. {
  8502. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_FLEXIBLE: arg #{1} - parameter 7 must be float", rulesParsed, idx - idxStart - 1));
  8503. return new LSL_List();
  8504. }
  8505. try
  8506. {
  8507. force = rules.GetVector3Item(idx++);
  8508. }
  8509. catch(InvalidCastException)
  8510. {
  8511. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_FLEXIBLE: arg #{1} - parameter 8 must be vector", rulesParsed, idx - idxStart - 1));
  8512. return new LSL_List();
  8513. }
  8514. SetFlexi(part, flexi, softness, gravity, friction, wind, tension, force);
  8515. break;
  8516. case ScriptBaseClass.PRIM_POINT_LIGHT:
  8517. if (remain < 5)
  8518. return new LSL_List();
  8519. bool light;
  8520. LSL_Vector lightcolor;
  8521. float intensity;
  8522. float radius;
  8523. float falloff;
  8524. try
  8525. {
  8526. light = rules.GetLSLIntegerItem(idx++);
  8527. }
  8528. catch(InvalidCastException)
  8529. {
  8530. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_POINT_LIGHT: arg #{1} - parameter 2 must be integer", rulesParsed, idx - idxStart - 1));
  8531. return new LSL_List();
  8532. }
  8533. try
  8534. {
  8535. lightcolor = rules.GetVector3Item(idx++);
  8536. }
  8537. catch(InvalidCastException)
  8538. {
  8539. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_POINT_LIGHT: arg #{1} - parameter 3 must be vector", rulesParsed, idx - idxStart - 1));
  8540. return new LSL_List();
  8541. }
  8542. try
  8543. {
  8544. intensity = (float)rules.GetLSLFloatItem(idx++);
  8545. }
  8546. catch(InvalidCastException)
  8547. {
  8548. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_POINT_LIGHT: arg #{1} - parameter 4 must be float", rulesParsed, idx - idxStart - 1));
  8549. return new LSL_List();
  8550. }
  8551. try
  8552. {
  8553. radius = (float)rules.GetLSLFloatItem(idx++);
  8554. }
  8555. catch(InvalidCastException)
  8556. {
  8557. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_POINT_LIGHT: arg #{1} - parameter 5 must be float", rulesParsed, idx - idxStart - 1));
  8558. return new LSL_List();
  8559. }
  8560. try
  8561. {
  8562. falloff = (float)rules.GetLSLFloatItem(idx++);
  8563. }
  8564. catch(InvalidCastException)
  8565. {
  8566. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_POINT_LIGHT: arg #{1} - parameter 6 must be float", rulesParsed, idx - idxStart - 1));
  8567. return new LSL_List();
  8568. }
  8569. SetPointLight(part, light, lightcolor, intensity, radius, falloff);
  8570. break;
  8571. case ScriptBaseClass.PRIM_GLOW:
  8572. if (remain < 2)
  8573. return new LSL_List();
  8574. float glow;
  8575. try
  8576. {
  8577. face = rules.GetLSLIntegerItem(idx++);
  8578. }
  8579. catch(InvalidCastException)
  8580. {
  8581. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_GLOW: arg #{1} - parameter 2 must be integer", rulesParsed, idx - idxStart - 1));
  8582. return new LSL_List();
  8583. }
  8584. try
  8585. {
  8586. glow = (float)rules.GetLSLFloatItem(idx++);
  8587. }
  8588. catch(InvalidCastException)
  8589. {
  8590. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_GLOW: arg #{1} - parameter 3 must be float", rulesParsed, idx - idxStart - 1));
  8591. return new LSL_List();
  8592. }
  8593. SetGlow(part, face, glow);
  8594. break;
  8595. case ScriptBaseClass.PRIM_BUMP_SHINY:
  8596. if (remain < 3)
  8597. return new LSL_List();
  8598. int shiny;
  8599. Bumpiness bump;
  8600. try
  8601. {
  8602. face = (int)rules.GetLSLIntegerItem(idx++);
  8603. }
  8604. catch(InvalidCastException)
  8605. {
  8606. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_BUMP_SHINY: arg #{1} - parameter 2 must be integer", rulesParsed, idx - idxStart - 1));
  8607. return new LSL_List();
  8608. }
  8609. try
  8610. {
  8611. shiny = (int)rules.GetLSLIntegerItem(idx++);
  8612. }
  8613. catch(InvalidCastException)
  8614. {
  8615. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_BUMP_SHINY: arg #{1} - parameter 3 must be integer", rulesParsed, idx - idxStart - 1));
  8616. return new LSL_List();
  8617. }
  8618. try
  8619. {
  8620. bump = (Bumpiness)(int)rules.GetLSLIntegerItem(idx++);
  8621. }
  8622. catch(InvalidCastException)
  8623. {
  8624. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_BUMP_SHINY: arg #{1} - parameter 4 must be integer", rulesParsed, idx - idxStart - 1));
  8625. return new LSL_List();
  8626. }
  8627. SetShiny(part, face, shiny, bump);
  8628. break;
  8629. case ScriptBaseClass.PRIM_FULLBRIGHT:
  8630. if (remain < 2)
  8631. return new LSL_List();
  8632. bool st;
  8633. try
  8634. {
  8635. face = rules.GetLSLIntegerItem(idx++);
  8636. }
  8637. catch(InvalidCastException)
  8638. {
  8639. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_FULLBRIGHT: arg #{1} - parameter 2 must be integer", rulesParsed, idx - idxStart - 1));
  8640. return new LSL_List();
  8641. }
  8642. try
  8643. {
  8644. st = rules.GetLSLIntegerItem(idx++);
  8645. }
  8646. catch(InvalidCastException)
  8647. {
  8648. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_FULLBRIGHT: arg #{1} - parameter 4 must be integer", rulesParsed, idx - idxStart - 1));
  8649. return new LSL_List();
  8650. }
  8651. SetFullBright(part, face , st);
  8652. break;
  8653. case ScriptBaseClass.PRIM_MATERIAL:
  8654. if (remain < 1)
  8655. return new LSL_List();
  8656. int mat;
  8657. try
  8658. {
  8659. mat = rules.GetLSLIntegerItem(idx++);
  8660. }
  8661. catch(InvalidCastException)
  8662. {
  8663. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_MATERIAL: arg #{1} - parameter 2 must be integer", rulesParsed, idx - idxStart - 1));
  8664. return new LSL_List();
  8665. }
  8666. if (mat < 0 || mat > 7)
  8667. return new LSL_List();
  8668. part.Material = Convert.ToByte(mat);
  8669. break;
  8670. case ScriptBaseClass.PRIM_PHANTOM:
  8671. if (remain < 1)
  8672. return new LSL_List();
  8673. string ph = rules.Data[idx++].ToString();
  8674. part.ParentGroup.ScriptSetPhantomStatus(ph.Equals("1"));
  8675. break;
  8676. case ScriptBaseClass.PRIM_PHYSICS:
  8677. if (remain < 1)
  8678. return new LSL_List();
  8679. string phy = rules.Data[idx++].ToString();
  8680. part.ScriptSetPhysicsStatus(phy.Equals("1"));
  8681. break;
  8682. case ScriptBaseClass.PRIM_PHYSICS_SHAPE_TYPE:
  8683. if (remain < 1)
  8684. return new LSL_List();
  8685. int shape_type;
  8686. try
  8687. {
  8688. shape_type = rules.GetLSLIntegerItem(idx++);
  8689. }
  8690. catch(InvalidCastException)
  8691. {
  8692. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_PHYSICS_SHAPE_TYPE: arg #{1} - parameter 2 must be integer", rulesParsed, idx - idxStart - 1));
  8693. return new LSL_List();
  8694. }
  8695. ExtraPhysicsData physdata = new ExtraPhysicsData();
  8696. physdata.Density = part.Density;
  8697. physdata.Bounce = part.Restitution;
  8698. physdata.GravitationModifier = part.GravityModifier;
  8699. physdata.PhysShapeType = (PhysShapeType)shape_type;
  8700. part.UpdateExtraPhysics(physdata);
  8701. break;
  8702. case (int)ScriptBaseClass.PRIM_PHYSICS_MATERIAL:
  8703. if (remain < 5)
  8704. return new LSL_List();
  8705. int material_bits = rules.GetLSLIntegerItem(idx++);
  8706. float material_density = (float)rules.GetLSLFloatItem(idx++);
  8707. float material_friction = (float)rules.GetLSLFloatItem(idx++);
  8708. float material_restitution = (float)rules.GetLSLFloatItem(idx++);
  8709. float material_gravity_modifier = (float)rules.GetLSLFloatItem(idx++);
  8710. SetPhysicsMaterial(part, material_bits, material_density, material_friction, material_restitution, material_gravity_modifier);
  8711. break;
  8712. case (int)ScriptBaseClass.PRIM_TEMP_ON_REZ:
  8713. if (remain < 1)
  8714. return new LSL_List();
  8715. string temp = rules.Data[idx++].ToString();
  8716. part.ParentGroup.ScriptSetTemporaryStatus(temp.Equals("1"));
  8717. break;
  8718. case ScriptBaseClass.PRIM_TEXGEN:
  8719. if (remain < 2)
  8720. return new LSL_List();
  8721. //face,type
  8722. int style;
  8723. try
  8724. {
  8725. face = rules.GetLSLIntegerItem(idx++);
  8726. }
  8727. catch(InvalidCastException)
  8728. {
  8729. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TEXGEN: arg #{1} - parameter 2 must be integer", rulesParsed, idx - idxStart - 1));
  8730. return new LSL_List();
  8731. }
  8732. try
  8733. {
  8734. style = rules.GetLSLIntegerItem(idx++);
  8735. }
  8736. catch(InvalidCastException)
  8737. {
  8738. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TEXGEN: arg #{1} - parameter 3 must be integer", rulesParsed, idx - idxStart - 1));
  8739. return new LSL_List();
  8740. }
  8741. SetTexGen(part, face, style);
  8742. break;
  8743. case ScriptBaseClass.PRIM_TEXT:
  8744. if (remain < 3)
  8745. return new LSL_List();
  8746. string primText;
  8747. LSL_Vector primTextColor;
  8748. LSL_Float primTextAlpha;
  8749. try
  8750. {
  8751. primText = rules.GetLSLStringItem(idx++);
  8752. }
  8753. catch(InvalidCastException)
  8754. {
  8755. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TEXT: arg #{1} - parameter 2 must be string", rulesParsed, idx - idxStart - 1));
  8756. return new LSL_List();
  8757. }
  8758. try
  8759. {
  8760. primTextColor = rules.GetVector3Item(idx++);
  8761. }
  8762. catch(InvalidCastException)
  8763. {
  8764. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TEXT: arg #{1} - parameter 3 must be vector", rulesParsed, idx - idxStart - 1));
  8765. return new LSL_List();
  8766. }
  8767. try
  8768. {
  8769. primTextAlpha = rules.GetLSLFloatItem(idx++);
  8770. }
  8771. catch(InvalidCastException)
  8772. {
  8773. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TEXT: arg #{1} - parameter 4 must be float", rulesParsed, idx - idxStart - 1));
  8774. return new LSL_List();
  8775. }
  8776. Vector3 av3 = Util.Clip(primTextColor, 0.0f, 1.0f);
  8777. part.SetText(primText, av3, Util.Clip((float)primTextAlpha, 0.0f, 1.0f));
  8778. break;
  8779. case ScriptBaseClass.PRIM_NAME:
  8780. if (remain < 1)
  8781. return new LSL_List();
  8782. try
  8783. {
  8784. string primName = rules.GetLSLStringItem(idx++);
  8785. part.Name = primName;
  8786. }
  8787. catch(InvalidCastException)
  8788. {
  8789. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_NAME: arg #{1} - parameter 2 must be string", rulesParsed, idx - idxStart - 1));
  8790. return new LSL_List();
  8791. }
  8792. break;
  8793. case ScriptBaseClass.PRIM_DESC:
  8794. if (remain < 1)
  8795. return new LSL_List();
  8796. try
  8797. {
  8798. string primDesc = rules.GetLSLStringItem(idx++);
  8799. part.Description = primDesc;
  8800. }
  8801. catch(InvalidCastException)
  8802. {
  8803. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_DESC: arg #{1} - parameter 2 must be string", rulesParsed, idx - idxStart - 1));
  8804. return new LSL_List();
  8805. }
  8806. break;
  8807. case ScriptBaseClass.PRIM_ROT_LOCAL:
  8808. if (remain < 1)
  8809. return new LSL_List();
  8810. LSL_Rotation rot;
  8811. try
  8812. {
  8813. rot = rules.GetQuaternionItem(idx++);
  8814. }
  8815. catch(InvalidCastException)
  8816. {
  8817. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_ROT_LOCAL: arg #{1} - parameter 2 must be rotation", rulesParsed, idx - idxStart - 1));
  8818. return new LSL_List();
  8819. }
  8820. SetRot(part, rot);
  8821. break;
  8822. case ScriptBaseClass.PRIM_OMEGA:
  8823. if (remain < 3)
  8824. return new LSL_List();
  8825. LSL_Vector axis;
  8826. LSL_Float spinrate;
  8827. LSL_Float gain;
  8828. try
  8829. {
  8830. axis = rules.GetVector3Item(idx++);
  8831. }
  8832. catch(InvalidCastException)
  8833. {
  8834. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_OMEGA: arg #{1} - parameter 2 must be vector", rulesParsed, idx - idxStart - 1));
  8835. return new LSL_List();
  8836. }
  8837. try
  8838. {
  8839. spinrate = rules.GetLSLFloatItem(idx++);
  8840. }
  8841. catch(InvalidCastException)
  8842. {
  8843. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_OMEGA: arg #{1} - parameter 3 must be float", rulesParsed, idx - idxStart - 1));
  8844. return new LSL_List();
  8845. }
  8846. try
  8847. {
  8848. gain = rules.GetLSLFloatItem(idx++);
  8849. }
  8850. catch(InvalidCastException)
  8851. {
  8852. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_OMEGA: arg #{1} - parameter 4 must be float", rulesParsed, idx - idxStart - 1));
  8853. return new LSL_List();
  8854. }
  8855. TargetOmega(part, axis, (double)spinrate, (double)gain);
  8856. break;
  8857. case ScriptBaseClass.PRIM_SLICE:
  8858. if (remain < 1)
  8859. return new LSL_List();
  8860. LSL_Vector slice;
  8861. try
  8862. {
  8863. slice = rules.GetVector3Item(idx++);
  8864. }
  8865. catch(InvalidCastException)
  8866. {
  8867. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_SLICE: arg #{1} - parameter 2 must be vector", rulesParsed, idx - idxStart - 1));
  8868. return new LSL_List();
  8869. }
  8870. part.UpdateSlice((float)slice.x, (float)slice.y);
  8871. break;
  8872. case ScriptBaseClass.PRIM_SIT_TARGET:
  8873. if (remain < 3)
  8874. return new LSL_List();
  8875. int active;
  8876. try
  8877. {
  8878. active = rules.GetLSLIntegerItem(idx++);
  8879. }
  8880. catch(InvalidCastException)
  8881. {
  8882. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_SIT_TARGET: arg #{1} - parameter 1 must be integer", rulesParsed, idx - idxStart - 1));
  8883. return new LSL_List();
  8884. }
  8885. LSL_Vector offset;
  8886. try
  8887. {
  8888. offset = rules.GetVector3Item(idx++);
  8889. }
  8890. catch(InvalidCastException)
  8891. {
  8892. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_SIT_TARGET: arg #{1} - parameter 2 must be vector", rulesParsed, idx - idxStart - 1));
  8893. return new LSL_List();
  8894. }
  8895. LSL_Rotation sitrot;
  8896. try
  8897. {
  8898. sitrot = rules.GetQuaternionItem(idx++);
  8899. }
  8900. catch(InvalidCastException)
  8901. {
  8902. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_SIT_TARGET: arg #{1} - parameter 3 must be rotation", rulesParsed, idx - idxStart - 1));
  8903. return new LSL_List();
  8904. }
  8905. // not SL compatible since we don't have a independent flag to control active target but use the values of offset and rotation
  8906. if(active == 1)
  8907. {
  8908. if(offset.x == 0 && offset.y == 0 && offset.z == 0 && sitrot.s == 1.0)
  8909. offset.z = 1e-5f; // hack
  8910. SitTarget(part,offset,sitrot);
  8911. }
  8912. else if(active == 0)
  8913. SitTarget(part, Vector3.Zero , Quaternion.Identity);
  8914. break;
  8915. case ScriptBaseClass.PRIM_ALPHA_MODE:
  8916. if (remain < 3)
  8917. return new LSL_List();
  8918. try
  8919. {
  8920. face = rules.GetLSLIntegerItem(idx++);
  8921. }
  8922. catch(InvalidCastException)
  8923. {
  8924. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_ALPHA_MODE: arg #{1} - must be integer", rulesParsed, idx - idxStart - 1));
  8925. return new LSL_List();
  8926. }
  8927. int materialAlphaMode;
  8928. try
  8929. {
  8930. materialAlphaMode = rules.GetLSLIntegerItem(idx++);
  8931. }
  8932. catch(InvalidCastException)
  8933. {
  8934. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_ALPHA_MODE: arg #{1} - must be integer", rulesParsed, idx - idxStart - 1));
  8935. return new LSL_List();
  8936. }
  8937. if(materialAlphaMode < 0 || materialAlphaMode > 3)
  8938. {
  8939. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_ALPHA_MODE: arg #{1} - must be 0 to 3", rulesParsed, idx - idxStart - 1));
  8940. return new LSL_List();
  8941. }
  8942. int materialMaskCutoff;
  8943. try
  8944. {
  8945. materialMaskCutoff = rules.GetLSLIntegerItem(idx++);
  8946. }
  8947. catch(InvalidCastException)
  8948. {
  8949. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_ALPHA_MODE: arg #{1} - must be integer", rulesParsed, idx - idxStart - 1));
  8950. return new LSL_List();
  8951. }
  8952. if(materialMaskCutoff < 0 || materialMaskCutoff > 255)
  8953. {
  8954. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_ALPHA_MODE: arg #{1} - must be 0 to 255", rulesParsed, idx - idxStart - 1));
  8955. return new LSL_List();
  8956. }
  8957. materialChanged |= SetMaterialAlphaMode(part, face, materialAlphaMode, materialMaskCutoff);
  8958. break;
  8959. case ScriptBaseClass.PRIM_NORMAL:
  8960. if (remain < 5)
  8961. return new LSL_List();
  8962. try
  8963. {
  8964. face = rules.GetLSLIntegerItem(idx++);
  8965. }
  8966. catch(InvalidCastException)
  8967. {
  8968. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_NORMAL: arg #{1} - must be integer", rulesParsed, idx - idxStart - 1));
  8969. return new LSL_List();
  8970. }
  8971. string mapname = rules.Data[idx++].ToString();
  8972. UUID mapID = ScriptUtils.GetAssetIdFromItemName(m_host, mapname, (int)AssetType.Texture);
  8973. if (mapID == UUID.Zero)
  8974. {
  8975. if (!UUID.TryParse(mapname, out mapID))
  8976. {
  8977. 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));
  8978. return new LSL_List();
  8979. }
  8980. }
  8981. LSL_Vector mnrepeat;
  8982. try
  8983. {
  8984. mnrepeat = rules.GetVector3Item(idx++);
  8985. }
  8986. catch(InvalidCastException)
  8987. {
  8988. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_NORMAL: arg #{1} - must be vector", rulesParsed, idx - idxStart - 1));
  8989. return new LSL_List();
  8990. }
  8991. LSL_Vector mnoffset;
  8992. try
  8993. {
  8994. mnoffset = rules.GetVector3Item(idx++);
  8995. }
  8996. catch(InvalidCastException)
  8997. {
  8998. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_NORMAL: arg #{1} - must be vector", rulesParsed, idx - idxStart - 1));
  8999. return new LSL_List();
  9000. }
  9001. LSL_Float mnrot;
  9002. try
  9003. {
  9004. mnrot = rules.GetLSLFloatItem(idx++);
  9005. }
  9006. catch(InvalidCastException)
  9007. {
  9008. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_NORMAL: arg #{1} - must be float", rulesParsed, idx - idxStart - 1));
  9009. return new LSL_List();
  9010. }
  9011. float repeatX = (float)Util.Clamp(mnrepeat.x,-100.0, 100.0);
  9012. float repeatY = (float)Util.Clamp(mnrepeat.y,-100.0, 100.0);
  9013. float offsetX = (float)Util.Clamp(mnoffset.x, 0, 1.0);
  9014. float offsetY = (float)Util.Clamp(mnoffset.y, 0, 1.0);
  9015. materialChanged |= SetMaterialNormalMap(part, face, mapID, repeatX, repeatY, offsetX, offsetY, (float)mnrot);
  9016. break;
  9017. case ScriptBaseClass.PRIM_SPECULAR:
  9018. if (remain < 8)
  9019. return new LSL_List();
  9020. try
  9021. {
  9022. face = rules.GetLSLIntegerItem(idx++);
  9023. }
  9024. catch(InvalidCastException)
  9025. {
  9026. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_SPECULAR: arg #{1} - must be integer", rulesParsed, idx - idxStart - 1));
  9027. return new LSL_List();
  9028. }
  9029. string smapname = rules.Data[idx++].ToString();
  9030. UUID smapID = ScriptUtils.GetAssetIdFromItemName(m_host, smapname, (int)AssetType.Texture);
  9031. if (smapID == UUID.Zero)
  9032. {
  9033. if (!UUID.TryParse(smapname, out smapID))
  9034. {
  9035. 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));
  9036. return new LSL_List();
  9037. }
  9038. }
  9039. LSL_Vector msrepeat;
  9040. try
  9041. {
  9042. msrepeat = rules.GetVector3Item(idx++);
  9043. }
  9044. catch(InvalidCastException)
  9045. {
  9046. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_SPECULAR: arg #{1} - must be vector", rulesParsed, idx - idxStart - 1));
  9047. return new LSL_List();
  9048. }
  9049. LSL_Vector msoffset;
  9050. try
  9051. {
  9052. msoffset = rules.GetVector3Item(idx++);
  9053. }
  9054. catch(InvalidCastException)
  9055. {
  9056. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_SPECULAR: arg #{1} - must be vector", rulesParsed, idx - idxStart - 1));
  9057. return new LSL_List();
  9058. }
  9059. LSL_Float msrot;
  9060. try
  9061. {
  9062. msrot = rules.GetLSLFloatItem(idx++);
  9063. }
  9064. catch(InvalidCastException)
  9065. {
  9066. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_SPECULAR: arg #{1} - must be float", rulesParsed, idx - idxStart - 1));
  9067. return new LSL_List();
  9068. }
  9069. LSL_Vector mscolor;
  9070. try
  9071. {
  9072. mscolor = rules.GetVector3Item(idx++);
  9073. }
  9074. catch(InvalidCastException)
  9075. {
  9076. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_SPECULAR: arg #{1} - must be vector", rulesParsed, idx - idxStart - 1));
  9077. return new LSL_List();
  9078. }
  9079. LSL_Integer msgloss;
  9080. try
  9081. {
  9082. msgloss = rules.GetLSLIntegerItem(idx++);
  9083. }
  9084. catch(InvalidCastException)
  9085. {
  9086. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_SPECULAR: arg #{1} - must be integer", rulesParsed, idx - idxStart - 1));
  9087. return new LSL_List();
  9088. }
  9089. LSL_Integer msenv;
  9090. try
  9091. {
  9092. msenv = rules.GetLSLIntegerItem(idx++);
  9093. }
  9094. catch(InvalidCastException)
  9095. {
  9096. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_SPECULAR: arg #{1} - must be integer", rulesParsed, idx - idxStart - 1));
  9097. return new LSL_List();
  9098. }
  9099. float srepeatX = (float)Util.Clamp(msrepeat.x, -100.0, 100.0);
  9100. float srepeatY = (float)Util.Clamp(msrepeat.y, -100.0, 100.0);
  9101. float soffsetX = (float)Util.Clamp(msoffset.x, -1.0, 1.0);
  9102. float soffsetY = (float)Util.Clamp(msoffset.y, -1.0, 1.0);
  9103. byte colorR = (byte)(255.0 * Util.Clamp(mscolor.x, 0, 1.0) + 0.5);
  9104. byte colorG = (byte)(255.0 * Util.Clamp(mscolor.y, 0, 1.0) + 0.5);
  9105. byte colorB = (byte)(255.0 * Util.Clamp(mscolor.z, 0, 1.0) + 0.5);
  9106. byte gloss = (byte)Util.Clamp((int)msgloss, 0, 255);
  9107. byte env = (byte)Util.Clamp((int)msenv, 0, 255);
  9108. materialChanged |= SetMaterialSpecMap(part, face, smapID, srepeatX, srepeatY, soffsetX, soffsetY,
  9109. (float)msrot, colorR, colorG, colorB, gloss, env);
  9110. break;
  9111. case ScriptBaseClass.PRIM_LINK_TARGET:
  9112. if (remain < 3) // setting to 3 on the basis that parsing any usage of PRIM_LINK_TARGET that has nothing following it is pointless.
  9113. return new LSL_List();
  9114. return rules.GetSublist(idx, -1);
  9115. default:
  9116. Error(originFunc, string.Format("Error running rule #{0}: arg #{1} - unsupported parameter", rulesParsed, idx - idxStart));
  9117. return new LSL_List();
  9118. }
  9119. }
  9120. }
  9121. catch (InvalidCastException e)
  9122. {
  9123. Error(originFunc, string.Format("Error running rule #{0}: arg #{1} - ", rulesParsed, idx - idxStart) + e.Message);
  9124. }
  9125. finally
  9126. {
  9127. if (positionChanged)
  9128. {
  9129. if (part.ParentGroup.RootPart == part)
  9130. {
  9131. SceneObjectGroup parent = part.ParentGroup;
  9132. // Util.FireAndForget(delegate(object x) {
  9133. parent.UpdateGroupPosition(currentPosition);
  9134. // });
  9135. }
  9136. else
  9137. {
  9138. part.OffsetPosition = currentPosition;
  9139. // SceneObjectGroup parent = part.ParentGroup;
  9140. // parent.HasGroupChanged = true;
  9141. // parent.ScheduleGroupForTerseUpdate();
  9142. part.ScheduleTerseUpdate();
  9143. }
  9144. }
  9145. if(materialChanged)
  9146. {
  9147. if (part.ParentGroup != null && !part.ParentGroup.IsDeleted)
  9148. {
  9149. part.TriggerScriptChangedEvent(Changed.TEXTURE);
  9150. part.ScheduleFullUpdate();
  9151. part.ParentGroup.HasGroupChanged = true;
  9152. }
  9153. }
  9154. }
  9155. return new LSL_List();
  9156. }
  9157. protected bool SetMaterialAlphaMode(SceneObjectPart part, int face, int materialAlphaMode, int materialMaskCutoff)
  9158. {
  9159. if(m_materialsModule == null)
  9160. return false;
  9161. int nsides = part.GetNumberOfSides();
  9162. if(face == ScriptBaseClass.ALL_SIDES)
  9163. {
  9164. bool changed = false;
  9165. for(int i = 0; i < nsides; i++)
  9166. changed |= SetFaceMaterialAlphaMode(part, i, materialAlphaMode, materialMaskCutoff);
  9167. return changed;
  9168. }
  9169. if( face >= 0 && face < nsides)
  9170. return SetFaceMaterialAlphaMode(part, face, materialAlphaMode, materialMaskCutoff);
  9171. return false;
  9172. }
  9173. protected bool SetFaceMaterialAlphaMode(SceneObjectPart part, int face, int materialAlphaMode, int materialMaskCutoff)
  9174. {
  9175. Primitive.TextureEntry tex = part.Shape.Textures;
  9176. Primitive.TextureEntryFace texface = tex.CreateFace((uint)face);
  9177. if(texface == null)
  9178. return false;
  9179. FaceMaterial mat = null;
  9180. UUID oldid = texface.MaterialID;
  9181. if(oldid != UUID.Zero)
  9182. mat = m_materialsModule.GetMaterialCopy(oldid);
  9183. if(mat == null)
  9184. mat = new FaceMaterial();
  9185. mat.DiffuseAlphaMode = (byte)materialAlphaMode;
  9186. mat.AlphaMaskCutoff = (byte)materialMaskCutoff;
  9187. UUID id = m_materialsModule.AddNewMaterial(mat);
  9188. if(oldid == id)
  9189. return false;
  9190. texface.MaterialID = id;
  9191. part.Shape.TextureEntry = tex.GetBytes();
  9192. m_materialsModule.RemoveMaterial(oldid);
  9193. return true;
  9194. }
  9195. protected bool SetMaterialNormalMap(SceneObjectPart part, int face, UUID mapID, float repeatX, float repeatY,
  9196. float offsetX, float offsetY, float rot)
  9197. {
  9198. if(m_materialsModule == null)
  9199. return false;
  9200. int nsides = part.GetNumberOfSides();
  9201. if(face == ScriptBaseClass.ALL_SIDES)
  9202. {
  9203. bool changed = false;
  9204. for(int i = 0; i < nsides; i++)
  9205. changed |= SetFaceMaterialNormalMap(part, i, mapID, repeatX, repeatY, offsetX, offsetY, rot);
  9206. return changed;
  9207. }
  9208. if( face >= 0 && face < nsides)
  9209. return SetFaceMaterialNormalMap(part, face, mapID, repeatX, repeatY, offsetX, offsetY, rot);
  9210. return false;
  9211. }
  9212. protected bool SetFaceMaterialNormalMap(SceneObjectPart part, int face, UUID mapID, float repeatX, float repeatY,
  9213. float offsetX, float offsetY, float rot)
  9214. {
  9215. Primitive.TextureEntry tex = part.Shape.Textures;
  9216. Primitive.TextureEntryFace texface = tex.CreateFace((uint)face);
  9217. if(texface == null)
  9218. return false;
  9219. FaceMaterial mat = null;
  9220. UUID oldid = texface.MaterialID;
  9221. if(oldid != UUID.Zero)
  9222. mat = m_materialsModule.GetMaterialCopy(oldid);
  9223. if(mat == null)
  9224. mat = new FaceMaterial();
  9225. mat.NormalMapID = mapID;
  9226. mat.NormalOffsetX = offsetX;
  9227. mat.NormalOffsetY = offsetY;
  9228. mat.NormalRepeatX = repeatX;
  9229. mat.NormalRepeatY = repeatY;
  9230. mat.NormalRotation = rot;
  9231. UUID id = m_materialsModule.AddNewMaterial(mat);
  9232. if(oldid == id)
  9233. return false;
  9234. texface.MaterialID = id;
  9235. part.Shape.TextureEntry = tex.GetBytes();
  9236. m_materialsModule.RemoveMaterial(oldid);
  9237. return true;
  9238. }
  9239. protected bool SetMaterialSpecMap(SceneObjectPart part, int face, UUID mapID, float repeatX, float repeatY,
  9240. float offsetX, float offsetY, float rot,
  9241. byte colorR, byte colorG, byte colorB,
  9242. byte gloss, byte env)
  9243. {
  9244. if(m_materialsModule == null)
  9245. return false;
  9246. int nsides = part.GetNumberOfSides();
  9247. if(face == ScriptBaseClass.ALL_SIDES)
  9248. {
  9249. bool changed = false;
  9250. for(int i = 0; i < nsides; i++)
  9251. changed |= SetFaceMaterialSpecMap(part, i, mapID, repeatX, repeatY, offsetX, offsetY, rot,
  9252. colorR, colorG, colorB, gloss, env);
  9253. return changed;
  9254. }
  9255. if( face >= 0 && face < nsides)
  9256. return SetFaceMaterialSpecMap(part, face, mapID, repeatX, repeatY, offsetX, offsetY, rot,
  9257. colorR, colorG, colorB, gloss, env);
  9258. return false;
  9259. }
  9260. protected bool SetFaceMaterialSpecMap(SceneObjectPart part, int face, UUID mapID, float repeatX, float repeatY,
  9261. float offsetX, float offsetY, float rot,
  9262. byte colorR, byte colorG, byte colorB,
  9263. byte gloss, byte env)
  9264. {
  9265. Primitive.TextureEntry tex = part.Shape.Textures;
  9266. Primitive.TextureEntryFace texface = tex.CreateFace((uint)face);
  9267. if(texface == null)
  9268. return false;
  9269. FaceMaterial mat = null;
  9270. UUID oldid = texface.MaterialID;
  9271. if(oldid != UUID.Zero)
  9272. mat = m_materialsModule.GetMaterialCopy(oldid);
  9273. if(mat == null)
  9274. mat = new FaceMaterial();
  9275. mat.SpecularMapID = mapID;
  9276. mat.SpecularOffsetX = offsetX;
  9277. mat.SpecularOffsetY = offsetY;
  9278. mat.SpecularRepeatX = repeatX;
  9279. mat.SpecularRepeatY = repeatY;
  9280. mat.SpecularRotation = rot;
  9281. mat.SpecularLightColorR = colorR;
  9282. mat.SpecularLightColorG = colorG;
  9283. mat.SpecularLightColorB = colorB;
  9284. mat.SpecularLightExponent = gloss;
  9285. mat.EnvironmentIntensity = env;
  9286. UUID id = m_materialsModule.AddNewMaterial(mat);
  9287. if(oldid == id)
  9288. return false;
  9289. texface.MaterialID = id;
  9290. part.Shape.TextureEntry = tex.GetBytes();
  9291. m_materialsModule.RemoveMaterial(oldid);
  9292. return true;
  9293. }
  9294. protected LSL_List SetAgentParams(ScenePresence sp, LSL_List rules, string originFunc, ref uint rulesParsed)
  9295. {
  9296. int idx = 0;
  9297. int idxStart = 0;
  9298. try
  9299. {
  9300. while (idx < rules.Length)
  9301. {
  9302. ++rulesParsed;
  9303. int code = rules.GetLSLIntegerItem(idx++);
  9304. int remain = rules.Length - idx;
  9305. idxStart = idx;
  9306. switch (code)
  9307. {
  9308. case ScriptBaseClass.PRIM_POSITION:
  9309. case ScriptBaseClass.PRIM_POS_LOCAL:
  9310. if (remain < 1)
  9311. return new LSL_List();
  9312. try
  9313. {
  9314. sp.OffsetPosition = rules.GetVector3Item(idx++);
  9315. }
  9316. catch(InvalidCastException)
  9317. {
  9318. if (code == ScriptBaseClass.PRIM_POSITION)
  9319. {
  9320. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_POSITION: arg #{1} - parameter 2 must be vector", rulesParsed, idx - idxStart - 1));
  9321. }
  9322. else
  9323. {
  9324. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_POS_LOCAL: arg #{1} - parameter 2 must be vector", rulesParsed, idx - idxStart - 1));
  9325. }
  9326. return new LSL_List();
  9327. }
  9328. break;
  9329. case ScriptBaseClass.PRIM_ROTATION:
  9330. if (remain < 1)
  9331. return new LSL_List();
  9332. Quaternion inRot;
  9333. try
  9334. {
  9335. inRot = rules.GetQuaternionItem(idx++);
  9336. }
  9337. catch(InvalidCastException)
  9338. {
  9339. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_ROTATION: arg #{1} - parameter 2 must be rotation", rulesParsed, idx - idxStart - 1));
  9340. return new LSL_List();
  9341. }
  9342. SceneObjectPart parentPart = sp.ParentPart;
  9343. if (parentPart != null)
  9344. sp.Rotation = m_host.GetWorldRotation() * inRot;
  9345. break;
  9346. case ScriptBaseClass.PRIM_ROT_LOCAL:
  9347. if (remain < 1)
  9348. return new LSL_List();
  9349. try
  9350. {
  9351. sp.Rotation = rules.GetQuaternionItem(idx++);
  9352. }
  9353. catch(InvalidCastException)
  9354. {
  9355. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_ROT_LOCAL: arg #{1} - parameter 2 must be rotation", rulesParsed, idx - idxStart - 1));
  9356. return new LSL_List();
  9357. }
  9358. break;
  9359. case ScriptBaseClass.PRIM_TYPE:
  9360. Error(originFunc, "PRIM_TYPE disallowed on agent");
  9361. return new LSL_List();
  9362. case ScriptBaseClass.PRIM_OMEGA:
  9363. Error(originFunc, "PRIM_OMEGA disallowed on agent");
  9364. return new LSL_List();
  9365. case ScriptBaseClass.PRIM_LINK_TARGET:
  9366. if (remain < 3) // setting to 3 on the basis that parsing any usage of PRIM_LINK_TARGET that has nothing following it is pointless.
  9367. return new LSL_List();
  9368. return rules.GetSublist(idx, -1);
  9369. default:
  9370. Error(originFunc,
  9371. string.Format("Error running rule #{0} on agent: arg #{1} - disallowed on agent", rulesParsed, idx - idxStart));
  9372. return new LSL_List();
  9373. }
  9374. }
  9375. }
  9376. catch (InvalidCastException e)
  9377. {
  9378. Error(
  9379. originFunc,
  9380. string.Format("Error running rule #{0}: arg #{1} - ", rulesParsed, idx - idxStart) + e.Message);
  9381. }
  9382. return new LSL_List();
  9383. }
  9384. public LSL_String llStringToBase64(string str)
  9385. {
  9386. m_host.AddScriptLPS(1);
  9387. try
  9388. {
  9389. byte[] encData_byte;
  9390. encData_byte = Util.UTF8.GetBytes(str);
  9391. string encodedData = Convert.ToBase64String(encData_byte);
  9392. return encodedData;
  9393. }
  9394. catch
  9395. {
  9396. Error("llBase64ToString", "Error encoding string");
  9397. return String.Empty;
  9398. }
  9399. }
  9400. public LSL_String llBase64ToString(string str)
  9401. {
  9402. m_host.AddScriptLPS(1);
  9403. try
  9404. {
  9405. byte[] b = Convert.FromBase64String(str);
  9406. return Encoding.UTF8.GetString(b);
  9407. }
  9408. catch
  9409. {
  9410. Error("llBase64ToString", "Error decoding string");
  9411. return String.Empty;
  9412. }
  9413. }
  9414. public LSL_String llXorBase64Strings(string str1, string str2)
  9415. {
  9416. int padding = 0;
  9417. string b64 = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
  9418. ScriptSleep(300);
  9419. m_host.AddScriptLPS(1);
  9420. if (str1 == String.Empty)
  9421. return String.Empty;
  9422. if (str2 == String.Empty)
  9423. return str1;
  9424. int len = str2.Length;
  9425. if ((len % 4) != 0) // LL is EVIL!!!!
  9426. {
  9427. while (str2.EndsWith("="))
  9428. str2 = str2.Substring(0, str2.Length - 1);
  9429. len = str2.Length;
  9430. int mod = len % 4;
  9431. if (mod == 1)
  9432. str2 = str2.Substring(0, str2.Length - 1);
  9433. else if (mod == 2)
  9434. str2 += "==";
  9435. else if (mod == 3)
  9436. str2 += "=";
  9437. }
  9438. byte[] data1;
  9439. byte[] data2;
  9440. try
  9441. {
  9442. data1 = Convert.FromBase64String(str1);
  9443. data2 = Convert.FromBase64String(str2);
  9444. }
  9445. catch (Exception)
  9446. {
  9447. return new LSL_String(String.Empty);
  9448. }
  9449. // For cases where the decoded length of s2 is greater
  9450. // than the decoded length of s1, simply perform a normal
  9451. // decode and XOR
  9452. //
  9453. /*
  9454. if (data2.Length >= data1.Length)
  9455. {
  9456. for (int pos = 0 ; pos < data1.Length ; pos++ )
  9457. data1[pos] ^= data2[pos];
  9458. return Convert.ToBase64String(data1);
  9459. }
  9460. */
  9461. // Remove padding
  9462. while (str1.EndsWith("="))
  9463. {
  9464. str1 = str1.Substring(0, str1.Length - 1);
  9465. padding++;
  9466. }
  9467. while (str2.EndsWith("="))
  9468. str2 = str2.Substring(0, str2.Length - 1);
  9469. byte[] d1 = new byte[str1.Length];
  9470. byte[] d2 = new byte[str2.Length];
  9471. for (int i = 0 ; i < str1.Length ; i++)
  9472. {
  9473. int idx = b64.IndexOf(str1.Substring(i, 1));
  9474. if (idx == -1)
  9475. idx = 0;
  9476. d1[i] = (byte)idx;
  9477. }
  9478. for (int i = 0 ; i < str2.Length ; i++)
  9479. {
  9480. int idx = b64.IndexOf(str2.Substring(i, 1));
  9481. if (idx == -1)
  9482. idx = 0;
  9483. d2[i] = (byte)idx;
  9484. }
  9485. string output = String.Empty;
  9486. for (int pos = 0 ; pos < d1.Length ; pos++)
  9487. output += b64[d1[pos] ^ d2[pos % d2.Length]];
  9488. // Here's a funny thing: LL blithely violate the base64
  9489. // standard pretty much everywhere. Here, padding is
  9490. // added only if the first input string had it, rather
  9491. // than when the data actually needs it. This can result
  9492. // in invalid base64 being returned. Go figure.
  9493. while (padding-- > 0)
  9494. output += "=";
  9495. return output;
  9496. }
  9497. public void llRemoteDataSetRegion()
  9498. {
  9499. m_host.AddScriptLPS(1);
  9500. Deprecated("llRemoteDataSetRegion", "Use llOpenRemoteDataChannel instead");
  9501. }
  9502. public LSL_Float llLog10(double val)
  9503. {
  9504. m_host.AddScriptLPS(1);
  9505. return (double)Math.Log10(val);
  9506. }
  9507. public LSL_Float llLog(double val)
  9508. {
  9509. m_host.AddScriptLPS(1);
  9510. return (double)Math.Log(val);
  9511. }
  9512. public LSL_List llGetAnimationList(string id)
  9513. {
  9514. m_host.AddScriptLPS(1);
  9515. LSL_List l = new LSL_List();
  9516. ScenePresence av = World.GetScenePresence((UUID)id);
  9517. if (av == null || av.IsChildAgent) // only if in the region
  9518. return l;
  9519. UUID[] anims;
  9520. anims = av.Animator.GetAnimationArray();
  9521. foreach (UUID foo in anims)
  9522. l.Add(new LSL_Key(foo.ToString()));
  9523. return l;
  9524. }
  9525. public void llSetParcelMusicURL(string url)
  9526. {
  9527. m_host.AddScriptLPS(1);
  9528. ILandObject land = World.LandChannel.GetLandObject(m_host.AbsolutePosition);
  9529. if (land.LandData.OwnerID != m_host.OwnerID)
  9530. return;
  9531. land.SetMusicUrl(url);
  9532. ScriptSleep(m_sleepMsOnSetParcelMusicURL);
  9533. }
  9534. public LSL_String llGetParcelMusicURL()
  9535. {
  9536. m_host.AddScriptLPS(1);
  9537. ILandObject land = World.LandChannel.GetLandObject(m_host.AbsolutePosition);
  9538. if (land.LandData.OwnerID != m_host.OwnerID)
  9539. return String.Empty;
  9540. return land.GetMusicUrl();
  9541. }
  9542. public LSL_Vector llGetRootPosition()
  9543. {
  9544. m_host.AddScriptLPS(1);
  9545. return new LSL_Vector(m_host.ParentGroup.AbsolutePosition);
  9546. }
  9547. /// <summary>
  9548. /// http://lslwiki.net/lslwiki/wakka.php?wakka=llGetRot
  9549. /// http://lslwiki.net/lslwiki/wakka.php?wakka=ChildRotation
  9550. /// Also tested in sl in regards to the behaviour in attachments/mouselook
  9551. /// In the root prim:-
  9552. /// Returns the object rotation if not attached
  9553. /// Returns the avatars rotation if attached
  9554. /// Returns the camera rotation if attached and the avatar is in mouselook
  9555. /// </summary>
  9556. public LSL_Rotation llGetRootRotation()
  9557. {
  9558. m_host.AddScriptLPS(1);
  9559. Quaternion q;
  9560. if (m_host.ParentGroup.AttachmentPoint != 0)
  9561. {
  9562. ScenePresence avatar = World.GetScenePresence(m_host.ParentGroup.AttachedAvatar);
  9563. if (avatar != null)
  9564. if ((avatar.AgentControlFlags & (uint)AgentManager.ControlFlags.AGENT_CONTROL_MOUSELOOK) != 0)
  9565. q = avatar.CameraRotation; // Mouselook
  9566. else
  9567. q = avatar.GetWorldRotation(); // Currently infrequently updated so may be inaccurate
  9568. else
  9569. q = m_host.ParentGroup.GroupRotation; // Likely never get here but just in case
  9570. }
  9571. else
  9572. q = m_host.ParentGroup.GroupRotation; // just the group rotation
  9573. return new LSL_Rotation(q);
  9574. }
  9575. public LSL_String llGetObjectDesc()
  9576. {
  9577. return m_host.Description!=null?m_host.Description:String.Empty;
  9578. }
  9579. public void llSetObjectDesc(string desc)
  9580. {
  9581. m_host.AddScriptLPS(1);
  9582. m_host.Description = desc!=null?desc:String.Empty;
  9583. }
  9584. public LSL_Key llGetCreator()
  9585. {
  9586. m_host.AddScriptLPS(1);
  9587. return m_host.CreatorID.ToString();
  9588. }
  9589. public LSL_String llGetTimestamp()
  9590. {
  9591. m_host.AddScriptLPS(1);
  9592. return DateTime.Now.ToUniversalTime().ToString("yyyy-MM-ddTHH:mm:ss.fffffffZ");
  9593. }
  9594. public LSL_Integer llGetNumberOfPrims()
  9595. {
  9596. m_host.AddScriptLPS(1);
  9597. return m_host.ParentGroup.PrimCount + m_host.ParentGroup.GetSittingAvatarsCount();
  9598. }
  9599. /// <summary>
  9600. /// Full implementation of llGetBoundingBox according to SL 2015-04-15.
  9601. /// http://wiki.secondlife.com/wiki/LlGetBoundingBox
  9602. /// http://lslwiki.net/lslwiki/wakka.php?wakka=llGetBoundingBox
  9603. /// Returns local bounding box of avatar without attachments
  9604. /// if target is non-seated avatar or prim/mesh in avatar attachment.
  9605. /// Returns local bounding box of object including seated avatars
  9606. /// if target is seated avatar or prim/mesh in object.
  9607. /// Uses meshing of prims for high accuracy
  9608. /// or less accurate box models for speed.
  9609. /// </summary>
  9610. public LSL_List llGetBoundingBox(string obj)
  9611. {
  9612. m_host.AddScriptLPS(1);
  9613. UUID objID = UUID.Zero;
  9614. LSL_List result = new LSL_List();
  9615. // If the ID is not valid, return null result
  9616. if (!UUID.TryParse(obj, out objID))
  9617. {
  9618. result.Add(new LSL_Vector());
  9619. result.Add(new LSL_Vector());
  9620. return result;
  9621. }
  9622. // Check if this is an attached prim. If so, replace
  9623. // the UUID with the avatar UUID and report it's bounding box
  9624. SceneObjectPart part = World.GetSceneObjectPart(objID);
  9625. if (part != null && part.ParentGroup.IsAttachment)
  9626. objID = part.ParentGroup.AttachedAvatar;
  9627. // Find out if this is an avatar ID. If so, return it's box
  9628. ScenePresence presence = World.GetScenePresence(objID);
  9629. if (presence != null)
  9630. {
  9631. // As per LSL Wiki, there is no difference between sitting
  9632. // and standing avatar since server 1.36
  9633. LSL_Vector lower;
  9634. LSL_Vector upper;
  9635. Vector3 box = presence.Appearance.AvatarBoxSize * 0.5f;
  9636. if (presence.Animator.Animations.ImplicitDefaultAnimation.AnimID
  9637. == DefaultAvatarAnimations.AnimsUUID["SIT_GROUND_CONSTRAINED"])
  9638. /*
  9639. {
  9640. // This is for ground sitting avatars
  9641. float height = presence.Appearance.AvatarHeight / 2.66666667f;
  9642. lower = new LSL_Vector(-0.3375f, -0.45f, height * -1.0f);
  9643. upper = new LSL_Vector(0.3375f, 0.45f, 0.0f);
  9644. }
  9645. else
  9646. {
  9647. // This is for standing/flying avatars
  9648. float height = presence.Appearance.AvatarHeight / 2.0f;
  9649. lower = new LSL_Vector(-0.225f, -0.3f, height * -1.0f);
  9650. upper = new LSL_Vector(0.225f, 0.3f, height + 0.05f);
  9651. }
  9652. // Adjust to the documented error offsets (see LSL Wiki)
  9653. lower += new LSL_Vector(0.05f, 0.05f, 0.05f);
  9654. upper -= new LSL_Vector(0.05f, 0.05f, 0.05f);
  9655. */
  9656. {
  9657. // This is for ground sitting avatars TODO!
  9658. lower = new LSL_Vector(-box.X - 0.1125, -box.Y, box.Z * -1.0f);
  9659. upper = new LSL_Vector(box.X + 0.1125, box.Y, box.Z * -1.0f);
  9660. }
  9661. else
  9662. {
  9663. // This is for standing/flying avatars
  9664. lower = new LSL_Vector(-box.X, -box.Y, -box.Z);
  9665. upper = new LSL_Vector(box.X, box.Y, box.Z);
  9666. }
  9667. if (lower.x > upper.x)
  9668. lower.x = upper.x;
  9669. if (lower.y > upper.y)
  9670. lower.y = upper.y;
  9671. if (lower.z > upper.z)
  9672. lower.z = upper.z;
  9673. result.Add(lower);
  9674. result.Add(upper);
  9675. return result;
  9676. }
  9677. part = World.GetSceneObjectPart(objID);
  9678. // Currently only works for single prims without a sitting avatar
  9679. if (part == null)
  9680. {
  9681. result.Add(new LSL_Vector());
  9682. result.Add(new LSL_Vector());
  9683. return result;
  9684. }
  9685. SceneObjectGroup sog = part.ParentGroup;
  9686. if(sog.IsDeleted)
  9687. {
  9688. result.Add(new LSL_Vector());
  9689. result.Add(new LSL_Vector());
  9690. return result;
  9691. }
  9692. float minX;
  9693. float maxX;
  9694. float minY;
  9695. float maxY;
  9696. float minZ;
  9697. float maxZ;
  9698. sog.GetBoundingBox(out minX, out maxX, out minY, out maxY, out minZ, out maxZ);
  9699. result.Add(new LSL_Vector(minX, minY, minZ));
  9700. result.Add(new LSL_Vector(maxX, maxY, maxZ));
  9701. return result;
  9702. }
  9703. /// <summary>
  9704. /// Helper to calculate bounding box of an avatar.
  9705. /// </summary>
  9706. private void BoundingBoxOfScenePresence(ScenePresence sp, out Vector3 lower, out Vector3 upper)
  9707. {
  9708. // Adjust from OS model
  9709. // avatar height = visual height - 0.2, bounding box height = visual height
  9710. // to SL model
  9711. // avatar height = visual height, bounding box height = visual height + 0.2
  9712. float height = sp.Appearance.AvatarHeight + m_avatarHeightCorrection;
  9713. // According to avatar bounding box in SL 2015-04-18:
  9714. // standing = <-0.275,-0.35,-0.1-0.5*h> : <0.275,0.35,0.1+0.5*h>
  9715. // groundsitting = <-0.3875,-0.5,-0.05-0.375*h> : <0.3875,0.5,0.5>
  9716. // sitting = <-0.5875,-0.35,-0.35-0.375*h> : <0.1875,0.35,-0.25+0.25*h>
  9717. // When avatar is sitting
  9718. if (sp.ParentPart != null)
  9719. {
  9720. lower = new Vector3(m_lABB1SitX0, m_lABB1SitY0, m_lABB1SitZ0 + m_lABB1SitZ1 * height);
  9721. upper = new Vector3(m_lABB2SitX0, m_lABB2SitY0, m_lABB2SitZ0 + m_lABB2SitZ1 * height);
  9722. }
  9723. // When avatar is groundsitting
  9724. else if (sp.Animator.Animations.ImplicitDefaultAnimation.AnimID == DefaultAvatarAnimations.AnimsUUID["SIT_GROUND_CONSTRAINED"])
  9725. {
  9726. lower = new Vector3(m_lABB1GrsX0, m_lABB1GrsY0, m_lABB1GrsZ0 + m_lABB1GrsZ1 * height);
  9727. upper = new Vector3(m_lABB2GrsX0, m_lABB2GrsY0, m_lABB2GrsZ0 + m_lABB2GrsZ1 * height);
  9728. }
  9729. // When avatar is standing or flying
  9730. else
  9731. {
  9732. lower = new Vector3(m_lABB1StdX0, m_lABB1StdY0, m_lABB1StdZ0 + m_lABB1StdZ1 * height);
  9733. upper = new Vector3(m_lABB2StdX0, m_lABB2StdY0, m_lABB2StdZ0 + m_lABB2StdZ1 * height);
  9734. }
  9735. }
  9736. public LSL_Vector llGetGeometricCenter()
  9737. {
  9738. return new LSL_Vector(m_host.GetGeometricCenter());
  9739. }
  9740. public LSL_List llGetPrimitiveParams(LSL_List rules)
  9741. {
  9742. m_host.AddScriptLPS(1);
  9743. LSL_List result = new LSL_List();
  9744. LSL_List remaining = GetPrimParams(m_host, rules, ref result);
  9745. while ((object)remaining != null && remaining.Length > 1)
  9746. {
  9747. int linknumber = remaining.GetLSLIntegerItem(0);
  9748. rules = remaining.GetSublist(1, -1);
  9749. List<SceneObjectPart> parts = GetLinkParts(linknumber);
  9750. if(parts.Count == 0)
  9751. break;
  9752. foreach (SceneObjectPart part in parts)
  9753. remaining = GetPrimParams(part, rules, ref result);
  9754. }
  9755. return result;
  9756. }
  9757. public LSL_List llGetLinkPrimitiveParams(int linknumber, LSL_List rules)
  9758. {
  9759. m_host.AddScriptLPS(1);
  9760. // acording to SL wiki this must indicate a single link number or link_root or link_this.
  9761. // keep other options as before
  9762. List<SceneObjectPart> parts;
  9763. List<ScenePresence> avatars;
  9764. LSL_List res = new LSL_List();
  9765. LSL_List remaining = new LSL_List();
  9766. while (rules.Length > 0)
  9767. {
  9768. parts = GetLinkParts(linknumber);
  9769. avatars = GetLinkAvatars(linknumber);
  9770. remaining = new LSL_List();
  9771. foreach (SceneObjectPart part in parts)
  9772. {
  9773. remaining = GetPrimParams(part, rules, ref res);
  9774. }
  9775. foreach (ScenePresence avatar in avatars)
  9776. {
  9777. remaining = GetPrimParams(avatar, rules, ref res);
  9778. }
  9779. if (remaining.Length > 0)
  9780. {
  9781. linknumber = remaining.GetLSLIntegerItem(0);
  9782. rules = remaining.GetSublist(1, -1);
  9783. }
  9784. else
  9785. break;
  9786. }
  9787. return res;
  9788. }
  9789. public LSL_List GetPrimParams(SceneObjectPart part, LSL_List rules, ref LSL_List res)
  9790. {
  9791. int idx = 0;
  9792. int face;
  9793. Primitive.TextureEntry tex;
  9794. int nsides = GetNumberOfSides(part);
  9795. while (idx < rules.Length)
  9796. {
  9797. int code = (int)rules.GetLSLIntegerItem(idx++);
  9798. int remain = rules.Length - idx;
  9799. switch (code)
  9800. {
  9801. case (int)ScriptBaseClass.PRIM_MATERIAL:
  9802. res.Add(new LSL_Integer(part.Material));
  9803. break;
  9804. case (int)ScriptBaseClass.PRIM_PHYSICS:
  9805. if ((part.GetEffectiveObjectFlags() & (uint)PrimFlags.Physics) != 0)
  9806. res.Add(new LSL_Integer(1));
  9807. else
  9808. res.Add(new LSL_Integer(0));
  9809. break;
  9810. case (int)ScriptBaseClass.PRIM_TEMP_ON_REZ:
  9811. if ((part.GetEffectiveObjectFlags() & (uint)PrimFlags.TemporaryOnRez) != 0)
  9812. res.Add(new LSL_Integer(1));
  9813. else
  9814. res.Add(new LSL_Integer(0));
  9815. break;
  9816. case (int)ScriptBaseClass.PRIM_PHANTOM:
  9817. if ((part.GetEffectiveObjectFlags() & (uint)PrimFlags.Phantom) != 0)
  9818. res.Add(new LSL_Integer(1));
  9819. else
  9820. res.Add(new LSL_Integer(0));
  9821. break;
  9822. case (int)ScriptBaseClass.PRIM_POSITION:
  9823. LSL_Vector v = new LSL_Vector(part.AbsolutePosition.X,
  9824. part.AbsolutePosition.Y,
  9825. part.AbsolutePosition.Z);
  9826. res.Add(v);
  9827. break;
  9828. case (int)ScriptBaseClass.PRIM_SIZE:
  9829. res.Add(new LSL_Vector(part.Scale));
  9830. break;
  9831. case (int)ScriptBaseClass.PRIM_ROTATION:
  9832. res.Add(GetPartRot(part));
  9833. break;
  9834. case (int)ScriptBaseClass.PRIM_PHYSICS_SHAPE_TYPE:
  9835. res.Add(new LSL_Integer((int)part.PhysicsShapeType));
  9836. break;
  9837. case (int)ScriptBaseClass.PRIM_TYPE:
  9838. // implementing box
  9839. PrimitiveBaseShape Shape = part.Shape;
  9840. int primType = (int)part.GetPrimType();
  9841. res.Add(new LSL_Integer(primType));
  9842. double topshearx = (double)(sbyte)Shape.PathShearX / 100.0; // Fix negative values for PathShearX
  9843. double topsheary = (double)(sbyte)Shape.PathShearY / 100.0; // and PathShearY.
  9844. switch (primType)
  9845. {
  9846. case ScriptBaseClass.PRIM_TYPE_BOX:
  9847. case ScriptBaseClass.PRIM_TYPE_CYLINDER:
  9848. case ScriptBaseClass.PRIM_TYPE_PRISM:
  9849. res.Add(new LSL_Integer(Shape.ProfileCurve) & 0xf0); // Isolate hole shape nibble.
  9850. res.Add(new LSL_Vector(Shape.ProfileBegin / 50000.0, 1 - Shape.ProfileEnd / 50000.0, 0));
  9851. res.Add(new LSL_Float(Shape.ProfileHollow / 50000.0));
  9852. res.Add(new LSL_Vector(Shape.PathTwistBegin / 100.0, Shape.PathTwist / 100.0, 0));
  9853. res.Add(new LSL_Vector(1 - (Shape.PathScaleX / 100.0 - 1), 1 - (Shape.PathScaleY / 100.0 - 1), 0));
  9854. res.Add(new LSL_Vector(topshearx, topsheary, 0));
  9855. break;
  9856. case ScriptBaseClass.PRIM_TYPE_SPHERE:
  9857. res.Add(new LSL_Integer(Shape.ProfileCurve) & 0xf0); // Isolate hole shape nibble.
  9858. res.Add(new LSL_Vector(Shape.PathBegin / 50000.0, 1 - Shape.PathEnd / 50000.0, 0));
  9859. res.Add(new LSL_Float(Shape.ProfileHollow / 50000.0));
  9860. res.Add(new LSL_Vector(Shape.PathTwistBegin / 100.0, Shape.PathTwist / 100.0, 0));
  9861. res.Add(new LSL_Vector(Shape.ProfileBegin / 50000.0, 1 - Shape.ProfileEnd / 50000.0, 0));
  9862. break;
  9863. case ScriptBaseClass.PRIM_TYPE_SCULPT:
  9864. res.Add(new LSL_String(Shape.SculptTexture.ToString()));
  9865. res.Add(new LSL_Integer(Shape.SculptType));
  9866. break;
  9867. case ScriptBaseClass.PRIM_TYPE_RING:
  9868. case ScriptBaseClass.PRIM_TYPE_TUBE:
  9869. case ScriptBaseClass.PRIM_TYPE_TORUS:
  9870. // holeshape
  9871. res.Add(new LSL_Integer(Shape.ProfileCurve) & 0xf0); // Isolate hole shape nibble.
  9872. // cut
  9873. res.Add(new LSL_Vector(Shape.PathBegin / 50000.0, 1 - Shape.PathEnd / 50000.0, 0));
  9874. // hollow
  9875. res.Add(new LSL_Float(Shape.ProfileHollow / 50000.0));
  9876. // twist
  9877. res.Add(new LSL_Vector(Shape.PathTwistBegin / 100.0, Shape.PathTwist / 100.0, 0));
  9878. // vector holesize
  9879. res.Add(new LSL_Vector(1 - (Shape.PathScaleX / 100.0 - 1), 1 - (Shape.PathScaleY / 100.0 - 1), 0));
  9880. // vector topshear
  9881. res.Add(new LSL_Vector(topshearx, topsheary, 0));
  9882. // vector profilecut
  9883. res.Add(new LSL_Vector(Shape.ProfileBegin / 50000.0, 1 - Shape.ProfileEnd / 50000.0, 0));
  9884. // vector tapera
  9885. res.Add(new LSL_Vector(Shape.PathTaperX / 100.0, Shape.PathTaperY / 100.0, 0));
  9886. // float revolutions
  9887. res.Add(new LSL_Float(Math.Round(Shape.PathRevolutions * 0.015d, 2, MidpointRounding.AwayFromZero)) + 1.0d);
  9888. // Slightly inaccurate, because an unsigned byte is being used to represent
  9889. // the entire range of floating-point values from 1.0 through 4.0 (which is how
  9890. // SL does it).
  9891. //
  9892. // Using these formulas to store and retrieve PathRevolutions, it is not
  9893. // possible to use all values between 1.00 and 4.00. For instance, you can't
  9894. // represent 1.10. You can represent 1.09 and 1.11, but not 1.10. So, if you
  9895. // use llSetPrimitiveParams to set revolutions to 1.10 and then retreive them
  9896. // with llGetPrimitiveParams, you'll retrieve 1.09. You can also see a similar
  9897. // behavior in the viewer as you cannot set 1.10. The viewer jumps to 1.11.
  9898. // In SL, llSetPrimitveParams and llGetPrimitiveParams can set and get a value
  9899. // such as 1.10. So, SL must store and retreive the actual user input rather
  9900. // than only storing the encoded value.
  9901. // float radiusoffset
  9902. res.Add(new LSL_Float(Shape.PathRadiusOffset / 100.0));
  9903. // float skew
  9904. res.Add(new LSL_Float(Shape.PathSkew / 100.0));
  9905. break;
  9906. }
  9907. break;
  9908. case (int)ScriptBaseClass.PRIM_TEXTURE:
  9909. if (remain < 1)
  9910. return new LSL_List();
  9911. face = (int)rules.GetLSLIntegerItem(idx++);
  9912. tex = part.Shape.Textures;
  9913. if (face == ScriptBaseClass.ALL_SIDES)
  9914. {
  9915. for (face = 0; face < nsides; face++)
  9916. {
  9917. Primitive.TextureEntryFace texface = tex.GetFace((uint)face);
  9918. res.Add(new LSL_String(texface.TextureID.ToString()));
  9919. res.Add(new LSL_Vector(texface.RepeatU,
  9920. texface.RepeatV,
  9921. 0));
  9922. res.Add(new LSL_Vector(texface.OffsetU,
  9923. texface.OffsetV,
  9924. 0));
  9925. res.Add(new LSL_Float(texface.Rotation));
  9926. }
  9927. }
  9928. else
  9929. {
  9930. if (face >= 0 && face < nsides)
  9931. {
  9932. Primitive.TextureEntryFace texface = tex.GetFace((uint)face);
  9933. res.Add(new LSL_String(texface.TextureID.ToString()));
  9934. res.Add(new LSL_Vector(texface.RepeatU,
  9935. texface.RepeatV,
  9936. 0));
  9937. res.Add(new LSL_Vector(texface.OffsetU,
  9938. texface.OffsetV,
  9939. 0));
  9940. res.Add(new LSL_Float(texface.Rotation));
  9941. }
  9942. }
  9943. break;
  9944. case (int)ScriptBaseClass.PRIM_COLOR:
  9945. if (remain < 1)
  9946. return new LSL_List();
  9947. face = (int)rules.GetLSLIntegerItem(idx++);
  9948. tex = part.Shape.Textures;
  9949. Color4 texcolor;
  9950. if (face == ScriptBaseClass.ALL_SIDES)
  9951. {
  9952. for (face = 0; face < nsides; face++)
  9953. {
  9954. texcolor = tex.GetFace((uint)face).RGBA;
  9955. res.Add(new LSL_Vector(texcolor.R,
  9956. texcolor.G,
  9957. texcolor.B));
  9958. res.Add(new LSL_Float(texcolor.A));
  9959. }
  9960. }
  9961. else
  9962. {
  9963. texcolor = tex.GetFace((uint)face).RGBA;
  9964. res.Add(new LSL_Vector(texcolor.R,
  9965. texcolor.G,
  9966. texcolor.B));
  9967. res.Add(new LSL_Float(texcolor.A));
  9968. }
  9969. break;
  9970. case (int)ScriptBaseClass.PRIM_BUMP_SHINY:
  9971. {
  9972. if (remain < 1)
  9973. return new LSL_List();
  9974. face = (int)rules.GetLSLIntegerItem(idx++);
  9975. tex = part.Shape.Textures;
  9976. int shiny;
  9977. if (face == ScriptBaseClass.ALL_SIDES)
  9978. {
  9979. for (face = 0; face < nsides; face++)
  9980. {
  9981. Shininess shinyness = tex.GetFace((uint)face).Shiny;
  9982. if (shinyness == Shininess.High)
  9983. {
  9984. shiny = ScriptBaseClass.PRIM_SHINY_HIGH;
  9985. }
  9986. else if (shinyness == Shininess.Medium)
  9987. {
  9988. shiny = ScriptBaseClass.PRIM_SHINY_MEDIUM;
  9989. }
  9990. else if (shinyness == Shininess.Low)
  9991. {
  9992. shiny = ScriptBaseClass.PRIM_SHINY_LOW;
  9993. }
  9994. else
  9995. {
  9996. shiny = ScriptBaseClass.PRIM_SHINY_NONE;
  9997. }
  9998. res.Add(new LSL_Integer(shiny));
  9999. res.Add(new LSL_Integer((int)tex.GetFace((uint)face).Bump));
  10000. }
  10001. }
  10002. else
  10003. {
  10004. Shininess shinyness = tex.GetFace((uint)face).Shiny;
  10005. if (shinyness == Shininess.High)
  10006. {
  10007. shiny = ScriptBaseClass.PRIM_SHINY_HIGH;
  10008. }
  10009. else if (shinyness == Shininess.Medium)
  10010. {
  10011. shiny = ScriptBaseClass.PRIM_SHINY_MEDIUM;
  10012. }
  10013. else if (shinyness == Shininess.Low)
  10014. {
  10015. shiny = ScriptBaseClass.PRIM_SHINY_LOW;
  10016. }
  10017. else
  10018. {
  10019. shiny = ScriptBaseClass.PRIM_SHINY_NONE;
  10020. }
  10021. res.Add(new LSL_Integer(shiny));
  10022. res.Add(new LSL_Integer((int)tex.GetFace((uint)face).Bump));
  10023. }
  10024. break;
  10025. }
  10026. case (int)ScriptBaseClass.PRIM_FULLBRIGHT:
  10027. {
  10028. if (remain < 1)
  10029. return new LSL_List();
  10030. face = (int)rules.GetLSLIntegerItem(idx++);
  10031. tex = part.Shape.Textures;
  10032. int fullbright;
  10033. if (face == ScriptBaseClass.ALL_SIDES)
  10034. {
  10035. for (face = 0; face < nsides; face++)
  10036. {
  10037. if (tex.GetFace((uint)face).Fullbright == true)
  10038. {
  10039. fullbright = ScriptBaseClass.TRUE;
  10040. }
  10041. else
  10042. {
  10043. fullbright = ScriptBaseClass.FALSE;
  10044. }
  10045. res.Add(new LSL_Integer(fullbright));
  10046. }
  10047. }
  10048. else
  10049. {
  10050. if (tex.GetFace((uint)face).Fullbright == true)
  10051. {
  10052. fullbright = ScriptBaseClass.TRUE;
  10053. }
  10054. else
  10055. {
  10056. fullbright = ScriptBaseClass.FALSE;
  10057. }
  10058. res.Add(new LSL_Integer(fullbright));
  10059. }
  10060. break;
  10061. }
  10062. case (int)ScriptBaseClass.PRIM_FLEXIBLE:
  10063. PrimitiveBaseShape shape = part.Shape;
  10064. if (shape.FlexiEntry)
  10065. res.Add(new LSL_Integer(1)); // active
  10066. else
  10067. res.Add(new LSL_Integer(0));
  10068. res.Add(new LSL_Integer(shape.FlexiSoftness));// softness
  10069. res.Add(new LSL_Float(shape.FlexiGravity)); // gravity
  10070. res.Add(new LSL_Float(shape.FlexiDrag)); // friction
  10071. res.Add(new LSL_Float(shape.FlexiWind)); // wind
  10072. res.Add(new LSL_Float(shape.FlexiTension)); // tension
  10073. res.Add(new LSL_Vector(shape.FlexiForceX, // force
  10074. shape.FlexiForceY,
  10075. shape.FlexiForceZ));
  10076. break;
  10077. case (int)ScriptBaseClass.PRIM_TEXGEN:
  10078. // (PRIM_TEXGEN_DEFAULT, PRIM_TEXGEN_PLANAR)
  10079. if (remain < 1)
  10080. return new LSL_List();
  10081. face = (int)rules.GetLSLIntegerItem(idx++);
  10082. tex = part.Shape.Textures;
  10083. if (face == ScriptBaseClass.ALL_SIDES)
  10084. {
  10085. for (face = 0; face < nsides; face++)
  10086. {
  10087. if (tex.GetFace((uint)face).TexMapType == MappingType.Planar)
  10088. {
  10089. res.Add(new LSL_Integer(ScriptBaseClass.PRIM_TEXGEN_PLANAR));
  10090. }
  10091. else
  10092. {
  10093. res.Add(new LSL_Integer(ScriptBaseClass.PRIM_TEXGEN_DEFAULT));
  10094. }
  10095. }
  10096. }
  10097. else
  10098. {
  10099. if (tex.GetFace((uint)face).TexMapType == MappingType.Planar)
  10100. {
  10101. res.Add(new LSL_Integer(ScriptBaseClass.PRIM_TEXGEN_PLANAR));
  10102. }
  10103. else
  10104. {
  10105. res.Add(new LSL_Integer(ScriptBaseClass.PRIM_TEXGEN_DEFAULT));
  10106. }
  10107. }
  10108. break;
  10109. case (int)ScriptBaseClass.PRIM_POINT_LIGHT:
  10110. shape = part.Shape;
  10111. if (shape.LightEntry)
  10112. res.Add(new LSL_Integer(1)); // active
  10113. else
  10114. res.Add(new LSL_Integer(0));
  10115. res.Add(new LSL_Vector(shape.LightColorR, // color
  10116. shape.LightColorG,
  10117. shape.LightColorB));
  10118. res.Add(new LSL_Float(shape.LightIntensity)); // intensity
  10119. res.Add(new LSL_Float(shape.LightRadius)); // radius
  10120. res.Add(new LSL_Float(shape.LightFalloff)); // falloff
  10121. break;
  10122. case (int)ScriptBaseClass.PRIM_GLOW:
  10123. if (remain < 1)
  10124. return new LSL_List();
  10125. face = (int)rules.GetLSLIntegerItem(idx++);
  10126. tex = part.Shape.Textures;
  10127. float primglow;
  10128. if (face == ScriptBaseClass.ALL_SIDES)
  10129. {
  10130. for (face = 0; face < nsides; face++)
  10131. {
  10132. primglow = tex.GetFace((uint)face).Glow;
  10133. res.Add(new LSL_Float(primglow));
  10134. }
  10135. }
  10136. else
  10137. {
  10138. primglow = tex.GetFace((uint)face).Glow;
  10139. res.Add(new LSL_Float(primglow));
  10140. }
  10141. break;
  10142. case (int)ScriptBaseClass.PRIM_TEXT:
  10143. Color4 textColor = part.GetTextColor();
  10144. res.Add(new LSL_String(part.Text));
  10145. res.Add(new LSL_Vector(textColor.R,
  10146. textColor.G,
  10147. textColor.B));
  10148. res.Add(new LSL_Float(textColor.A));
  10149. break;
  10150. case (int)ScriptBaseClass.PRIM_NAME:
  10151. res.Add(new LSL_String(part.Name));
  10152. break;
  10153. case (int)ScriptBaseClass.PRIM_DESC:
  10154. res.Add(new LSL_String(part.Description));
  10155. break;
  10156. case (int)ScriptBaseClass.PRIM_ROT_LOCAL:
  10157. res.Add(new LSL_Rotation(part.RotationOffset));
  10158. break;
  10159. case (int)ScriptBaseClass.PRIM_POS_LOCAL:
  10160. res.Add(new LSL_Vector(GetPartLocalPos(part)));
  10161. break;
  10162. case (int)ScriptBaseClass.PRIM_SLICE:
  10163. PrimType prim_type = part.GetPrimType();
  10164. bool useProfileBeginEnd = (prim_type == PrimType.SPHERE || prim_type == PrimType.TORUS || prim_type == PrimType.TUBE || prim_type == PrimType.RING);
  10165. res.Add(new LSL_Vector(
  10166. (useProfileBeginEnd ? part.Shape.ProfileBegin : part.Shape.PathBegin) / 50000.0,
  10167. 1 - (useProfileBeginEnd ? part.Shape.ProfileEnd : part.Shape.PathEnd) / 50000.0,
  10168. 0
  10169. ));
  10170. break;
  10171. case (int)ScriptBaseClass.PRIM_OMEGA:
  10172. // this may return values diferent from SL since we don't handle set the same way
  10173. float gain = 1.0f; // we don't use gain and don't store it
  10174. Vector3 axis = part.AngularVelocity;
  10175. float spin = axis.Length();
  10176. if(spin < 1.0e-6)
  10177. {
  10178. axis = Vector3.Zero;
  10179. gain = 0.0f;
  10180. spin = 0.0f;
  10181. }
  10182. else
  10183. {
  10184. axis = axis * (1.0f/spin);
  10185. }
  10186. res.Add(new LSL_Vector(axis.X,
  10187. axis.Y,
  10188. axis.Z));
  10189. res.Add(new LSL_Float(spin));
  10190. res.Add(new LSL_Float(gain));
  10191. break;
  10192. case (int)ScriptBaseClass.PRIM_SIT_TARGET:
  10193. if(part.IsSitTargetSet)
  10194. {
  10195. res.Add(new LSL_Integer(1));
  10196. res.Add(new LSL_Vector(part.SitTargetPosition));
  10197. res.Add(new LSL_Rotation(part.SitTargetOrientation));
  10198. }
  10199. else
  10200. {
  10201. res.Add(new LSL_Integer(0));
  10202. res.Add(new LSL_Vector(Vector3.Zero));
  10203. res.Add(new LSL_Rotation(Quaternion.Identity));
  10204. }
  10205. break;
  10206. case (int)ScriptBaseClass.PRIM_NORMAL:
  10207. case (int)ScriptBaseClass.PRIM_SPECULAR:
  10208. case (int)ScriptBaseClass.PRIM_ALPHA_MODE:
  10209. if (remain < 1)
  10210. return new LSL_List();
  10211. face = (int)rules.GetLSLIntegerItem(idx++);
  10212. tex = part.Shape.Textures;
  10213. if (face == ScriptBaseClass.ALL_SIDES)
  10214. {
  10215. for (face = 0; face < nsides; face++)
  10216. {
  10217. Primitive.TextureEntryFace texface = tex.GetFace((uint)face);
  10218. getLSLFaceMaterial(ref res, code, part, texface);
  10219. }
  10220. }
  10221. else
  10222. {
  10223. if (face >= 0 && face < nsides)
  10224. {
  10225. Primitive.TextureEntryFace texface = tex.GetFace((uint)face);
  10226. getLSLFaceMaterial(ref res, code, part, texface);
  10227. }
  10228. }
  10229. break;
  10230. case (int)ScriptBaseClass.PRIM_LINK_TARGET:
  10231. // TODO: Should be issuing a runtime script warning in this case.
  10232. if (remain < 2)
  10233. return new LSL_List();
  10234. return rules.GetSublist(idx, -1);
  10235. }
  10236. }
  10237. return new LSL_List();
  10238. }
  10239. private string GetMaterialTextureUUIDbyRights(UUID origID, SceneObjectPart part)
  10240. {
  10241. if(World.Permissions.CanEditObject(m_host.ParentGroup.UUID, m_host.ParentGroup.RootPart.OwnerID))
  10242. return origID.ToString();
  10243. lock(part.TaskInventory)
  10244. {
  10245. foreach(KeyValuePair<UUID, TaskInventoryItem> inv in part.TaskInventory)
  10246. {
  10247. if(inv.Value.InvType == (int)InventoryType.Texture && inv.Value.AssetID == origID)
  10248. return origID.ToString();
  10249. }
  10250. }
  10251. return UUID.Zero.ToString();
  10252. }
  10253. private void getLSLFaceMaterial(ref LSL_List res, int code, SceneObjectPart part, Primitive.TextureEntryFace texface)
  10254. {
  10255. UUID matID = UUID.Zero;
  10256. if(m_materialsModule != null)
  10257. matID = texface.MaterialID;
  10258. if(matID != UUID.Zero)
  10259. {
  10260. FaceMaterial mat = m_materialsModule.GetMaterial(matID);
  10261. if(mat != null)
  10262. {
  10263. if(code == ScriptBaseClass.PRIM_NORMAL)
  10264. {
  10265. res.Add(new LSL_String(GetMaterialTextureUUIDbyRights(mat.NormalMapID, part)));
  10266. res.Add(new LSL_Vector(mat.NormalRepeatX, mat.NormalRepeatY, 0));
  10267. res.Add(new LSL_Vector(mat.NormalOffsetX, mat.NormalOffsetY, 0));
  10268. res.Add(new LSL_Float(mat.NormalRotation));
  10269. }
  10270. else if(code == ScriptBaseClass.PRIM_SPECULAR)
  10271. {
  10272. const float colorScale = 1.0f / 255f;
  10273. res.Add(new LSL_String(GetMaterialTextureUUIDbyRights(mat.SpecularMapID, part)));
  10274. res.Add(new LSL_Vector(mat.SpecularRepeatX, mat.SpecularRepeatY, 0));
  10275. res.Add(new LSL_Vector(mat.SpecularOffsetX, mat.SpecularOffsetY, 0));
  10276. res.Add(new LSL_Float(mat.SpecularRotation));
  10277. res.Add(new LSL_Vector(mat.SpecularLightColorR * colorScale,
  10278. mat.SpecularLightColorG * colorScale,
  10279. mat.SpecularLightColorB * colorScale));
  10280. res.Add(new LSL_Integer(mat.SpecularLightExponent));
  10281. res.Add(new LSL_Integer(mat.EnvironmentIntensity));
  10282. }
  10283. else if(code == ScriptBaseClass.PRIM_ALPHA_MODE)
  10284. {
  10285. res.Add(new LSL_Integer(mat.DiffuseAlphaMode));
  10286. res.Add(new LSL_Integer(mat.AlphaMaskCutoff));
  10287. }
  10288. return;
  10289. }
  10290. }
  10291. // material not found
  10292. if(code == (int)ScriptBaseClass.PRIM_NORMAL || code == (int)ScriptBaseClass.PRIM_SPECULAR)
  10293. {
  10294. res.Add(new LSL_String(UUID.Zero.ToString()));
  10295. res.Add(new LSL_Vector(1.0, 1.0, 0));
  10296. res.Add(new LSL_Vector(0, 0, 0));
  10297. res.Add(new LSL_Float(0));
  10298. if(code == (int)ScriptBaseClass.PRIM_SPECULAR)
  10299. {
  10300. res.Add(new LSL_Vector(1.0, 1.0, 1.0));
  10301. res.Add(new LSL_Integer(51));
  10302. res.Add(new LSL_Integer(0));
  10303. }
  10304. }
  10305. else if(code == (int)ScriptBaseClass.PRIM_ALPHA_MODE)
  10306. {
  10307. res.Add(new LSL_Integer(1));
  10308. res.Add(new LSL_Integer(0));
  10309. }
  10310. }
  10311. public LSL_List llGetPrimMediaParams(int face, LSL_List rules)
  10312. {
  10313. m_host.AddScriptLPS(1);
  10314. ScriptSleep(m_sleepMsOnGetPrimMediaParams);
  10315. return GetPrimMediaParams(m_host, face, rules);
  10316. }
  10317. public LSL_List llGetLinkMedia(LSL_Integer link, LSL_Integer face, LSL_List rules)
  10318. {
  10319. m_host.AddScriptLPS(1);
  10320. ScriptSleep(m_sleepMsOnGetLinkMedia);
  10321. if (link == ScriptBaseClass.LINK_ROOT)
  10322. return GetPrimMediaParams(m_host.ParentGroup.RootPart, face, rules);
  10323. else if (link == ScriptBaseClass.LINK_THIS)
  10324. return GetPrimMediaParams(m_host, face, rules);
  10325. else
  10326. {
  10327. SceneObjectPart part = m_host.ParentGroup.GetLinkNumPart(link);
  10328. if (null != part)
  10329. return GetPrimMediaParams(part, face, rules);
  10330. }
  10331. return new LSL_List();
  10332. }
  10333. private LSL_List GetPrimMediaParams(SceneObjectPart part, int face, LSL_List rules)
  10334. {
  10335. // LSL Spec http://wiki.secondlife.com/wiki/LlGetPrimMediaParams says to fail silently if face is invalid
  10336. // TODO: Need to correctly handle case where a face has no media (which gives back an empty list).
  10337. // Assuming silently fail means give back an empty list. Ideally, need to check this.
  10338. if (face < 0 || face > part.GetNumberOfSides() - 1)
  10339. return new LSL_List();
  10340. IMoapModule module = m_ScriptEngine.World.RequestModuleInterface<IMoapModule>();
  10341. if (null == module)
  10342. return new LSL_List();
  10343. MediaEntry me = module.GetMediaEntry(part, face);
  10344. // As per http://wiki.secondlife.com/wiki/LlGetPrimMediaParams
  10345. if (null == me)
  10346. return new LSL_List();
  10347. LSL_List res = new LSL_List();
  10348. for (int i = 0; i < rules.Length; i++)
  10349. {
  10350. int code = (int)rules.GetLSLIntegerItem(i);
  10351. switch (code)
  10352. {
  10353. case ScriptBaseClass.PRIM_MEDIA_ALT_IMAGE_ENABLE:
  10354. // Not implemented
  10355. res.Add(new LSL_Integer(0));
  10356. break;
  10357. case ScriptBaseClass.PRIM_MEDIA_CONTROLS:
  10358. if (me.Controls == MediaControls.Standard)
  10359. res.Add(new LSL_Integer(ScriptBaseClass.PRIM_MEDIA_CONTROLS_STANDARD));
  10360. else
  10361. res.Add(new LSL_Integer(ScriptBaseClass.PRIM_MEDIA_CONTROLS_MINI));
  10362. break;
  10363. case ScriptBaseClass.PRIM_MEDIA_CURRENT_URL:
  10364. res.Add(new LSL_String(me.CurrentURL));
  10365. break;
  10366. case ScriptBaseClass.PRIM_MEDIA_HOME_URL:
  10367. res.Add(new LSL_String(me.HomeURL));
  10368. break;
  10369. case ScriptBaseClass.PRIM_MEDIA_AUTO_LOOP:
  10370. res.Add(me.AutoLoop ? ScriptBaseClass.TRUE : ScriptBaseClass.FALSE);
  10371. break;
  10372. case ScriptBaseClass.PRIM_MEDIA_AUTO_PLAY:
  10373. res.Add(me.AutoPlay ? ScriptBaseClass.TRUE : ScriptBaseClass.FALSE);
  10374. break;
  10375. case ScriptBaseClass.PRIM_MEDIA_AUTO_SCALE:
  10376. res.Add(me.AutoScale ? ScriptBaseClass.TRUE : ScriptBaseClass.FALSE);
  10377. break;
  10378. case ScriptBaseClass.PRIM_MEDIA_AUTO_ZOOM:
  10379. res.Add(me.AutoZoom ? ScriptBaseClass.TRUE : ScriptBaseClass.FALSE);
  10380. break;
  10381. case ScriptBaseClass.PRIM_MEDIA_FIRST_CLICK_INTERACT:
  10382. res.Add(me.InteractOnFirstClick ? ScriptBaseClass.TRUE : ScriptBaseClass.FALSE);
  10383. break;
  10384. case ScriptBaseClass.PRIM_MEDIA_WIDTH_PIXELS:
  10385. res.Add(new LSL_Integer(me.Width));
  10386. break;
  10387. case ScriptBaseClass.PRIM_MEDIA_HEIGHT_PIXELS:
  10388. res.Add(new LSL_Integer(me.Height));
  10389. break;
  10390. case ScriptBaseClass.PRIM_MEDIA_WHITELIST_ENABLE:
  10391. res.Add(me.EnableWhiteList ? ScriptBaseClass.TRUE : ScriptBaseClass.FALSE);
  10392. break;
  10393. case ScriptBaseClass.PRIM_MEDIA_WHITELIST:
  10394. string[] urls = (string[])me.WhiteList.Clone();
  10395. for (int j = 0; j < urls.Length; j++)
  10396. urls[j] = Uri.EscapeDataString(urls[j]);
  10397. res.Add(new LSL_String(string.Join(", ", urls)));
  10398. break;
  10399. case ScriptBaseClass.PRIM_MEDIA_PERMS_INTERACT:
  10400. res.Add(new LSL_Integer((int)me.InteractPermissions));
  10401. break;
  10402. case ScriptBaseClass.PRIM_MEDIA_PERMS_CONTROL:
  10403. res.Add(new LSL_Integer((int)me.ControlPermissions));
  10404. break;
  10405. default: return ScriptBaseClass.LSL_STATUS_MALFORMED_PARAMS;
  10406. }
  10407. }
  10408. return res;
  10409. }
  10410. public LSL_Integer llSetPrimMediaParams(LSL_Integer face, LSL_List rules)
  10411. {
  10412. m_host.AddScriptLPS(1);
  10413. ScriptSleep(m_sleepMsOnSetPrimMediaParams);
  10414. return SetPrimMediaParams(m_host, face, rules);
  10415. }
  10416. public LSL_Integer llSetLinkMedia(LSL_Integer link, LSL_Integer face, LSL_List rules)
  10417. {
  10418. m_host.AddScriptLPS(1);
  10419. ScriptSleep(m_sleepMsOnSetLinkMedia);
  10420. if (link == ScriptBaseClass.LINK_ROOT)
  10421. return SetPrimMediaParams(m_host.ParentGroup.RootPart, face, rules);
  10422. else if (link == ScriptBaseClass.LINK_THIS)
  10423. return SetPrimMediaParams(m_host, face, rules);
  10424. else
  10425. {
  10426. SceneObjectPart part = m_host.ParentGroup.GetLinkNumPart(link);
  10427. if (null != part)
  10428. return SetPrimMediaParams(part, face, rules);
  10429. }
  10430. return ScriptBaseClass.LSL_STATUS_NOT_FOUND;
  10431. }
  10432. private LSL_Integer SetPrimMediaParams(SceneObjectPart part, LSL_Integer face, LSL_List rules)
  10433. {
  10434. // LSL Spec http://wiki.secondlife.com/wiki/LlSetPrimMediaParams says to fail silently if face is invalid
  10435. // Assuming silently fail means sending back LSL_STATUS_OK. Ideally, need to check this.
  10436. // Don't perform the media check directly
  10437. if (face < 0 || face > part.GetNumberOfSides() - 1)
  10438. return ScriptBaseClass.LSL_STATUS_NOT_FOUND;
  10439. IMoapModule module = m_ScriptEngine.World.RequestModuleInterface<IMoapModule>();
  10440. if (null == module)
  10441. return ScriptBaseClass.LSL_STATUS_NOT_SUPPORTED;
  10442. MediaEntry me = module.GetMediaEntry(part, face);
  10443. if (null == me)
  10444. me = new MediaEntry();
  10445. int i = 0;
  10446. while (i < rules.Length - 1)
  10447. {
  10448. int code = rules.GetLSLIntegerItem(i++);
  10449. switch (code)
  10450. {
  10451. case ScriptBaseClass.PRIM_MEDIA_ALT_IMAGE_ENABLE:
  10452. me.EnableAlterntiveImage = (rules.GetLSLIntegerItem(i++) != 0 ? true : false);
  10453. break;
  10454. case ScriptBaseClass.PRIM_MEDIA_CONTROLS:
  10455. int v = rules.GetLSLIntegerItem(i++);
  10456. if (ScriptBaseClass.PRIM_MEDIA_CONTROLS_STANDARD == v)
  10457. me.Controls = MediaControls.Standard;
  10458. else
  10459. me.Controls = MediaControls.Mini;
  10460. break;
  10461. case ScriptBaseClass.PRIM_MEDIA_CURRENT_URL:
  10462. me.CurrentURL = rules.GetLSLStringItem(i++);
  10463. break;
  10464. case ScriptBaseClass.PRIM_MEDIA_HOME_URL:
  10465. me.HomeURL = rules.GetLSLStringItem(i++);
  10466. break;
  10467. case ScriptBaseClass.PRIM_MEDIA_AUTO_LOOP:
  10468. me.AutoLoop = (ScriptBaseClass.TRUE == rules.GetLSLIntegerItem(i++) ? true : false);
  10469. break;
  10470. case ScriptBaseClass.PRIM_MEDIA_AUTO_PLAY:
  10471. me.AutoPlay = (ScriptBaseClass.TRUE == rules.GetLSLIntegerItem(i++) ? true : false);
  10472. break;
  10473. case ScriptBaseClass.PRIM_MEDIA_AUTO_SCALE:
  10474. me.AutoScale = (ScriptBaseClass.TRUE == rules.GetLSLIntegerItem(i++) ? true : false);
  10475. break;
  10476. case ScriptBaseClass.PRIM_MEDIA_AUTO_ZOOM:
  10477. me.AutoZoom = (ScriptBaseClass.TRUE == rules.GetLSLIntegerItem(i++) ? true : false);
  10478. break;
  10479. case ScriptBaseClass.PRIM_MEDIA_FIRST_CLICK_INTERACT:
  10480. me.InteractOnFirstClick = (ScriptBaseClass.TRUE == rules.GetLSLIntegerItem(i++) ? true : false);
  10481. break;
  10482. case ScriptBaseClass.PRIM_MEDIA_WIDTH_PIXELS:
  10483. me.Width = (int)rules.GetLSLIntegerItem(i++);
  10484. break;
  10485. case ScriptBaseClass.PRIM_MEDIA_HEIGHT_PIXELS:
  10486. me.Height = (int)rules.GetLSLIntegerItem(i++);
  10487. break;
  10488. case ScriptBaseClass.PRIM_MEDIA_WHITELIST_ENABLE:
  10489. me.EnableWhiteList = (ScriptBaseClass.TRUE == rules.GetLSLIntegerItem(i++) ? true : false);
  10490. break;
  10491. case ScriptBaseClass.PRIM_MEDIA_WHITELIST:
  10492. string[] rawWhiteListUrls = rules.GetLSLStringItem(i++).ToString().Split(new char[] { ',' });
  10493. List<string> whiteListUrls = new List<string>();
  10494. Array.ForEach(
  10495. rawWhiteListUrls, delegate(string rawUrl) { whiteListUrls.Add(rawUrl.Trim()); });
  10496. me.WhiteList = whiteListUrls.ToArray();
  10497. break;
  10498. case ScriptBaseClass.PRIM_MEDIA_PERMS_INTERACT:
  10499. me.InteractPermissions = (MediaPermission)(byte)(int)rules.GetLSLIntegerItem(i++);
  10500. break;
  10501. case ScriptBaseClass.PRIM_MEDIA_PERMS_CONTROL:
  10502. me.ControlPermissions = (MediaPermission)(byte)(int)rules.GetLSLIntegerItem(i++);
  10503. break;
  10504. default: return ScriptBaseClass.LSL_STATUS_MALFORMED_PARAMS;
  10505. }
  10506. }
  10507. module.SetMediaEntry(part, face, me);
  10508. return ScriptBaseClass.LSL_STATUS_OK;
  10509. }
  10510. public LSL_Integer llClearPrimMedia(LSL_Integer face)
  10511. {
  10512. m_host.AddScriptLPS(1);
  10513. ScriptSleep(m_sleepMsOnClearPrimMedia);
  10514. return ClearPrimMedia(m_host, face);
  10515. }
  10516. public LSL_Integer llClearLinkMedia(LSL_Integer link, LSL_Integer face)
  10517. {
  10518. m_host.AddScriptLPS(1);
  10519. ScriptSleep(m_sleepMsOnClearLinkMedia);
  10520. if (link == ScriptBaseClass.LINK_ROOT)
  10521. return ClearPrimMedia(m_host.ParentGroup.RootPart, face);
  10522. else if (link == ScriptBaseClass.LINK_THIS)
  10523. return ClearPrimMedia(m_host, face);
  10524. else
  10525. {
  10526. SceneObjectPart part = m_host.ParentGroup.GetLinkNumPart(link);
  10527. if (null != part)
  10528. return ClearPrimMedia(part, face);
  10529. }
  10530. return ScriptBaseClass.LSL_STATUS_NOT_FOUND;
  10531. }
  10532. private LSL_Integer ClearPrimMedia(SceneObjectPart part, LSL_Integer face)
  10533. {
  10534. // LSL Spec http://wiki.secondlife.com/wiki/LlClearPrimMedia says to fail silently if face is invalid
  10535. // Assuming silently fail means sending back LSL_STATUS_OK. Ideally, need to check this.
  10536. // FIXME: Don't perform the media check directly
  10537. if (face < 0 || face > part.GetNumberOfSides() - 1)
  10538. return ScriptBaseClass.LSL_STATUS_NOT_FOUND;
  10539. IMoapModule module = m_ScriptEngine.World.RequestModuleInterface<IMoapModule>();
  10540. if (null == module)
  10541. return ScriptBaseClass.LSL_STATUS_NOT_SUPPORTED;
  10542. module.ClearMediaEntry(part, face);
  10543. return ScriptBaseClass.LSL_STATUS_OK;
  10544. }
  10545. // <remarks>
  10546. // <para>
  10547. // The .NET definition of base 64 is:
  10548. // <list>
  10549. // <item>
  10550. // Significant: A-Z a-z 0-9 + -
  10551. // </item>
  10552. // <item>
  10553. // Whitespace: \t \n \r ' '
  10554. // </item>
  10555. // <item>
  10556. // Valueless: =
  10557. // </item>
  10558. // <item>
  10559. // End-of-string: \0 or '=='
  10560. // </item>
  10561. // </list>
  10562. // </para>
  10563. // <para>
  10564. // Each point in a base-64 string represents
  10565. // a 6 bit value. A 32-bit integer can be
  10566. // represented using 6 characters (with some
  10567. // redundancy).
  10568. // </para>
  10569. // <para>
  10570. // LSL requires a base64 string to be 8
  10571. // characters in length. LSL also uses '/'
  10572. // rather than '-' (MIME compliant).
  10573. // </para>
  10574. // <para>
  10575. // RFC 1341 used as a reference (as specified
  10576. // by the SecondLife Wiki).
  10577. // </para>
  10578. // <para>
  10579. // SL do not record any kind of exception for
  10580. // these functions, so the string to integer
  10581. // conversion returns '0' if an invalid
  10582. // character is encountered during conversion.
  10583. // </para>
  10584. // <para>
  10585. // References
  10586. // <list>
  10587. // <item>
  10588. // http://lslwiki.net/lslwiki/wakka.php?wakka=Base64
  10589. // </item>
  10590. // <item>
  10591. // </item>
  10592. // </list>
  10593. // </para>
  10594. // </remarks>
  10595. // <summary>
  10596. // Table for converting 6-bit integers into
  10597. // base-64 characters
  10598. // </summary>
  10599. protected static readonly char[] i2ctable =
  10600. {
  10601. 'A','B','C','D','E','F','G','H',
  10602. 'I','J','K','L','M','N','O','P',
  10603. 'Q','R','S','T','U','V','W','X',
  10604. 'Y','Z',
  10605. 'a','b','c','d','e','f','g','h',
  10606. 'i','j','k','l','m','n','o','p',
  10607. 'q','r','s','t','u','v','w','x',
  10608. 'y','z',
  10609. '0','1','2','3','4','5','6','7',
  10610. '8','9',
  10611. '+','/'
  10612. };
  10613. // <summary>
  10614. // Table for converting base-64 characters
  10615. // into 6-bit integers.
  10616. // </summary>
  10617. protected static readonly int[] c2itable =
  10618. {
  10619. -1,-1,-1,-1,-1,-1,-1,-1, // 0x
  10620. -1,-1,-1,-1,-1,-1,-1,-1,
  10621. -1,-1,-1,-1,-1,-1,-1,-1, // 1x
  10622. -1,-1,-1,-1,-1,-1,-1,-1,
  10623. -1,-1,-1,-1,-1,-1,-1,-1, // 2x
  10624. -1,-1,-1,63,-1,-1,-1,64,
  10625. 53,54,55,56,57,58,59,60, // 3x
  10626. 61,62,-1,-1,-1,0,-1,-1,
  10627. -1,1,2,3,4,5,6,7, // 4x
  10628. 8,9,10,11,12,13,14,15,
  10629. 16,17,18,19,20,21,22,23, // 5x
  10630. 24,25,26,-1,-1,-1,-1,-1,
  10631. -1,27,28,29,30,31,32,33, // 6x
  10632. 34,35,36,37,38,39,40,41,
  10633. 42,43,44,45,46,47,48,49, // 7x
  10634. 50,51,52,-1,-1,-1,-1,-1,
  10635. -1,-1,-1,-1,-1,-1,-1,-1, // 8x
  10636. -1,-1,-1,-1,-1,-1,-1,-1,
  10637. -1,-1,-1,-1,-1,-1,-1,-1, // 9x
  10638. -1,-1,-1,-1,-1,-1,-1,-1,
  10639. -1,-1,-1,-1,-1,-1,-1,-1, // Ax
  10640. -1,-1,-1,-1,-1,-1,-1,-1,
  10641. -1,-1,-1,-1,-1,-1,-1,-1, // Bx
  10642. -1,-1,-1,-1,-1,-1,-1,-1,
  10643. -1,-1,-1,-1,-1,-1,-1,-1, // Cx
  10644. -1,-1,-1,-1,-1,-1,-1,-1,
  10645. -1,-1,-1,-1,-1,-1,-1,-1, // Dx
  10646. -1,-1,-1,-1,-1,-1,-1,-1,
  10647. -1,-1,-1,-1,-1,-1,-1,-1, // Ex
  10648. -1,-1,-1,-1,-1,-1,-1,-1,
  10649. -1,-1,-1,-1,-1,-1,-1,-1, // Fx
  10650. -1,-1,-1,-1,-1,-1,-1,-1
  10651. };
  10652. // <summary>
  10653. // Converts a 32-bit integer into a Base64
  10654. // character string. Base64 character strings
  10655. // are always 8 characters long. All iinteger
  10656. // values are acceptable.
  10657. // </summary>
  10658. // <param name="number">
  10659. // 32-bit integer to be converted.
  10660. // </param>
  10661. // <returns>
  10662. // 8 character string. The 1st six characters
  10663. // contain the encoded number, the last two
  10664. // characters are padded with "=".
  10665. // </returns>
  10666. public LSL_String llIntegerToBase64(int number)
  10667. {
  10668. // uninitialized string
  10669. char[] imdt = new char[8];
  10670. m_host.AddScriptLPS(1);
  10671. // Manually unroll the loop
  10672. imdt[7] = '=';
  10673. imdt[6] = '=';
  10674. imdt[5] = i2ctable[number<<4 & 0x3F];
  10675. imdt[4] = i2ctable[number>>2 & 0x3F];
  10676. imdt[3] = i2ctable[number>>8 & 0x3F];
  10677. imdt[2] = i2ctable[number>>14 & 0x3F];
  10678. imdt[1] = i2ctable[number>>20 & 0x3F];
  10679. imdt[0] = i2ctable[number>>26 & 0x3F];
  10680. return new string(imdt);
  10681. }
  10682. // <summary>
  10683. // Converts an eight character base-64 string
  10684. // into a 32-bit integer.
  10685. // </summary>
  10686. // <param name="str">
  10687. // 8 characters string to be converted. Other
  10688. // length strings return zero.
  10689. // </param>
  10690. // <returns>
  10691. // Returns an integer representing the
  10692. // encoded value providedint he 1st 6
  10693. // characters of the string.
  10694. // </returns>
  10695. // <remarks>
  10696. // This is coded to behave like LSL's
  10697. // implementation (I think), based upon the
  10698. // information available at the Wiki.
  10699. // If more than 8 characters are supplied,
  10700. // zero is returned.
  10701. // If a NULL string is supplied, zero will
  10702. // be returned.
  10703. // If fewer than 6 characters are supplied, then
  10704. // the answer will reflect a partial
  10705. // accumulation.
  10706. // <para>
  10707. // The 6-bit segments are
  10708. // extracted left-to-right in big-endian mode,
  10709. // which means that segment 6 only contains the
  10710. // two low-order bits of the 32 bit integer as
  10711. // its high order 2 bits. A short string therefore
  10712. // means loss of low-order information. E.g.
  10713. //
  10714. // |<---------------------- 32-bit integer ----------------------->|<-Pad->|
  10715. // |<--Byte 0----->|<--Byte 1----->|<--Byte 2----->|<--Byte 3----->|<-Pad->|
  10716. // |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|
  10717. // |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|
  10718. // | str[0] | str[1] | str[2] | str[3] | str[4] | str[6] |
  10719. //
  10720. // </para>
  10721. // </remarks>
  10722. public LSL_Integer llBase64ToInteger(string str)
  10723. {
  10724. int number = 0;
  10725. int digit;
  10726. m_host.AddScriptLPS(1);
  10727. // Require a well-fromed base64 string
  10728. if (str.Length > 8)
  10729. return 0;
  10730. // The loop is unrolled in the interests
  10731. // of performance and simple necessity.
  10732. //
  10733. // MUST find 6 digits to be well formed
  10734. // -1 == invalid
  10735. // 0 == padding
  10736. if ((digit = c2itable[str[0]]) <= 0)
  10737. {
  10738. return digit < 0 ? (int)0 : number;
  10739. }
  10740. number += --digit<<26;
  10741. if ((digit = c2itable[str[1]]) <= 0)
  10742. {
  10743. return digit < 0 ? (int)0 : number;
  10744. }
  10745. number += --digit<<20;
  10746. if ((digit = c2itable[str[2]]) <= 0)
  10747. {
  10748. return digit < 0 ? (int)0 : number;
  10749. }
  10750. number += --digit<<14;
  10751. if ((digit = c2itable[str[3]]) <= 0)
  10752. {
  10753. return digit < 0 ? (int)0 : number;
  10754. }
  10755. number += --digit<<8;
  10756. if ((digit = c2itable[str[4]]) <= 0)
  10757. {
  10758. return digit < 0 ? (int)0 : number;
  10759. }
  10760. number += --digit<<2;
  10761. if ((digit = c2itable[str[5]]) <= 0)
  10762. {
  10763. return digit < 0 ? (int)0 : number;
  10764. }
  10765. number += --digit>>4;
  10766. // ignore trailing padding
  10767. return number;
  10768. }
  10769. public LSL_Float llGetGMTclock()
  10770. {
  10771. m_host.AddScriptLPS(1);
  10772. return DateTime.UtcNow.TimeOfDay.TotalSeconds;
  10773. }
  10774. public LSL_String llGetHTTPHeader(LSL_Key request_id, string header)
  10775. {
  10776. m_host.AddScriptLPS(1);
  10777. if (m_UrlModule != null)
  10778. return m_UrlModule.GetHttpHeader(new UUID(request_id), header);
  10779. return String.Empty;
  10780. }
  10781. public LSL_String llGetSimulatorHostname()
  10782. {
  10783. m_host.AddScriptLPS(1);
  10784. IUrlModule UrlModule = World.RequestModuleInterface<IUrlModule>();
  10785. return UrlModule.ExternalHostNameForLSL;
  10786. }
  10787. // <summary>
  10788. // Scan the string supplied in 'src' and
  10789. // tokenize it based upon two sets of
  10790. // tokenizers provided in two lists,
  10791. // separators and spacers.
  10792. // </summary>
  10793. //
  10794. // <remarks>
  10795. // Separators demarcate tokens and are
  10796. // elided as they are encountered. Spacers
  10797. // also demarcate tokens, but are themselves
  10798. // retained as tokens.
  10799. //
  10800. // Both separators and spacers may be arbitrarily
  10801. // long strings. i.e. ":::".
  10802. //
  10803. // The function returns an ordered list
  10804. // representing the tokens found in the supplied
  10805. // sources string. If two successive tokenizers
  10806. // are encountered, then a null-string entry is
  10807. // added to the list.
  10808. //
  10809. // It is a precondition that the source and
  10810. // toekizer lisst are non-null. If they are null,
  10811. // then a null pointer exception will be thrown
  10812. // while their lengths are being determined.
  10813. //
  10814. // A small amount of working memoryis required
  10815. // of approximately 8*#tokenizers + 8*srcstrlen.
  10816. //
  10817. // There are many ways in which this function
  10818. // can be implemented, this implementation is
  10819. // fairly naive and assumes that when the
  10820. // function is invooked with a short source
  10821. // string and/or short lists of tokenizers, then
  10822. // performance will not be an issue.
  10823. //
  10824. // In order to minimize the perofrmance
  10825. // effects of long strings, or large numbers
  10826. // of tokeizers, the function skips as far as
  10827. // possible whenever a toekenizer is found,
  10828. // and eliminates redundant tokenizers as soon
  10829. // as is possible.
  10830. //
  10831. // The implementation tries to minimize temporary
  10832. // garbage generation.
  10833. // </remarks>
  10834. public LSL_List llParseStringKeepNulls(string src, LSL_List separators, LSL_List spacers)
  10835. {
  10836. return ParseString2List(src, separators, spacers, true);
  10837. }
  10838. private LSL_List ParseString2List(string src, LSL_List separators, LSL_List spacers, bool keepNulls)
  10839. {
  10840. int srclen = src.Length;
  10841. int seplen = separators.Length;
  10842. object[] separray = separators.Data;
  10843. int spclen = spacers.Length;
  10844. object[] spcarray = spacers.Data;
  10845. int dellen = 0;
  10846. string[] delarray = new string[seplen+spclen];
  10847. int outlen = 0;
  10848. string[] outarray = new string[srclen*2+1];
  10849. int i, j;
  10850. string d;
  10851. m_host.AddScriptLPS(1);
  10852. /*
  10853. * Convert separator and spacer lists to C# strings.
  10854. * Also filter out null strings so we don't hang.
  10855. */
  10856. for (i = 0; i < seplen; i ++)
  10857. {
  10858. d = separray[i].ToString();
  10859. if (d.Length > 0)
  10860. {
  10861. delarray[dellen++] = d;
  10862. }
  10863. }
  10864. seplen = dellen;
  10865. for (i = 0; i < spclen; i ++)
  10866. {
  10867. d = spcarray[i].ToString();
  10868. if (d.Length > 0)
  10869. {
  10870. delarray[dellen++] = d;
  10871. }
  10872. }
  10873. /*
  10874. * Scan through source string from beginning to end.
  10875. */
  10876. for (i = 0;;)
  10877. {
  10878. /*
  10879. * Find earliest delimeter in src starting at i (if any).
  10880. */
  10881. int earliestDel = -1;
  10882. int earliestSrc = srclen;
  10883. string earliestStr = null;
  10884. for (j = 0; j < dellen; j ++)
  10885. {
  10886. d = delarray[j];
  10887. if (d != null)
  10888. {
  10889. int index = src.IndexOf(d, i);
  10890. if (index < 0)
  10891. {
  10892. delarray[j] = null; // delim nowhere in src, don't check it anymore
  10893. }
  10894. else if (index < earliestSrc)
  10895. {
  10896. earliestSrc = index; // where delimeter starts in source string
  10897. earliestDel = j; // where delimeter is in delarray[]
  10898. earliestStr = d; // the delimeter string from delarray[]
  10899. if (index == i) break; // can't do any better than found at beg of string
  10900. }
  10901. }
  10902. }
  10903. /*
  10904. * Output source string starting at i through start of earliest delimeter.
  10905. */
  10906. if (keepNulls || (earliestSrc > i))
  10907. {
  10908. outarray[outlen++] = src.Substring(i, earliestSrc - i);
  10909. }
  10910. /*
  10911. * If no delimeter found at or after i, we're done scanning.
  10912. */
  10913. if (earliestDel < 0) break;
  10914. /*
  10915. * If delimeter was a spacer, output the spacer.
  10916. */
  10917. if (earliestDel >= seplen)
  10918. {
  10919. outarray[outlen++] = earliestStr;
  10920. }
  10921. /*
  10922. * Look at rest of src string following delimeter.
  10923. */
  10924. i = earliestSrc + earliestStr.Length;
  10925. }
  10926. /*
  10927. * Make up an exact-sized output array suitable for an LSL_List object.
  10928. */
  10929. object[] outlist = new object[outlen];
  10930. for (i = 0; i < outlen; i ++)
  10931. {
  10932. outlist[i] = new LSL_String(outarray[i]);
  10933. }
  10934. return new LSL_List(outlist);
  10935. }
  10936. public LSL_Integer llGetObjectPermMask(int mask)
  10937. {
  10938. m_host.AddScriptLPS(1);
  10939. int permmask = 0;
  10940. if (mask == ScriptBaseClass.MASK_BASE)//0
  10941. {
  10942. permmask = (int)m_host.BaseMask;
  10943. }
  10944. else if (mask == ScriptBaseClass.MASK_OWNER)//1
  10945. {
  10946. permmask = (int)m_host.OwnerMask;
  10947. }
  10948. else if (mask == ScriptBaseClass.MASK_GROUP)//2
  10949. {
  10950. permmask = (int)m_host.GroupMask;
  10951. }
  10952. else if (mask == ScriptBaseClass.MASK_EVERYONE)//3
  10953. {
  10954. permmask = (int)m_host.EveryoneMask;
  10955. }
  10956. else if (mask == ScriptBaseClass.MASK_NEXT)//4
  10957. {
  10958. permmask = (int)m_host.NextOwnerMask;
  10959. }
  10960. return permmask;
  10961. }
  10962. public void llSetObjectPermMask(int mask, int value)
  10963. {
  10964. m_host.AddScriptLPS(1);
  10965. if (m_ScriptEngine.Config.GetBoolean("AllowGodFunctions", false))
  10966. {
  10967. if (World.Permissions.IsAdministrator(m_host.OwnerID))
  10968. {
  10969. if (mask == ScriptBaseClass.MASK_BASE)//0
  10970. {
  10971. m_host.BaseMask = (uint)value;
  10972. }
  10973. else if (mask == ScriptBaseClass.MASK_OWNER)//1
  10974. {
  10975. m_host.OwnerMask = (uint)value;
  10976. }
  10977. else if (mask == ScriptBaseClass.MASK_GROUP)//2
  10978. {
  10979. m_host.GroupMask = (uint)value;
  10980. }
  10981. else if (mask == ScriptBaseClass.MASK_EVERYONE)//3
  10982. {
  10983. m_host.EveryoneMask = (uint)value;
  10984. }
  10985. else if (mask == ScriptBaseClass.MASK_NEXT)//4
  10986. {
  10987. m_host.NextOwnerMask = (uint)value;
  10988. }
  10989. }
  10990. }
  10991. }
  10992. public LSL_Integer llGetInventoryPermMask(string itemName, int mask)
  10993. {
  10994. m_host.AddScriptLPS(1);
  10995. TaskInventoryItem item = m_host.Inventory.GetInventoryItem(itemName);
  10996. if (item == null)
  10997. return -1;
  10998. switch (mask)
  10999. {
  11000. case 0:
  11001. return (int)item.BasePermissions;
  11002. case 1:
  11003. return (int)item.CurrentPermissions;
  11004. case 2:
  11005. return (int)item.GroupPermissions;
  11006. case 3:
  11007. return (int)item.EveryonePermissions;
  11008. case 4:
  11009. return (int)item.NextPermissions;
  11010. }
  11011. return -1;
  11012. }
  11013. public void llSetInventoryPermMask(string itemName, int mask, int value)
  11014. {
  11015. m_host.AddScriptLPS(1);
  11016. if (m_ScriptEngine.Config.GetBoolean("AllowGodFunctions", false))
  11017. {
  11018. if (World.Permissions.IsAdministrator(m_host.OwnerID))
  11019. {
  11020. TaskInventoryItem item = m_host.Inventory.GetInventoryItem(itemName);
  11021. if (item != null)
  11022. {
  11023. switch (mask)
  11024. {
  11025. case 0:
  11026. item.BasePermissions = (uint)value;
  11027. break;
  11028. case 1:
  11029. item.CurrentPermissions = (uint)value;
  11030. break;
  11031. case 2:
  11032. item.GroupPermissions = (uint)value;
  11033. break;
  11034. case 3:
  11035. item.EveryonePermissions = (uint)value;
  11036. break;
  11037. case 4:
  11038. item.NextPermissions = (uint)value;
  11039. break;
  11040. }
  11041. }
  11042. }
  11043. }
  11044. }
  11045. public LSL_Key llGetInventoryCreator(string itemName)
  11046. {
  11047. m_host.AddScriptLPS(1);
  11048. TaskInventoryItem item = m_host.Inventory.GetInventoryItem(itemName);
  11049. if (item == null)
  11050. {
  11051. Error("llGetInventoryCreator", "Can't find item '" + item + "'");
  11052. return String.Empty;
  11053. }
  11054. return item.CreatorID.ToString();
  11055. }
  11056. public void llOwnerSay(string msg)
  11057. {
  11058. m_host.AddScriptLPS(1);
  11059. World.SimChatBroadcast(Utils.StringToBytes(msg), ChatTypeEnum.Owner, 0,
  11060. m_host.AbsolutePosition, m_host.Name, m_host.UUID, false);
  11061. // IWorldComm wComm = m_ScriptEngine.World.RequestModuleInterface<IWorldComm>();
  11062. // wComm.DeliverMessage(ChatTypeEnum.Owner, 0, m_host.Name, m_host.UUID, msg);
  11063. }
  11064. public LSL_Key llRequestSecureURL()
  11065. {
  11066. m_host.AddScriptLPS(1);
  11067. if (m_UrlModule != null)
  11068. return m_UrlModule.RequestSecureURL(m_ScriptEngine.ScriptModule, m_host, m_item.ItemID, null).ToString();
  11069. return UUID.Zero.ToString();
  11070. }
  11071. public LSL_Key llRequestSimulatorData(string simulator, int data)
  11072. {
  11073. IOSSL_Api ossl = (IOSSL_Api)m_ScriptEngine.GetApi(m_item.ItemID, "OSSL");
  11074. try
  11075. {
  11076. m_host.AddScriptLPS(1);
  11077. string reply = String.Empty;
  11078. GridRegion info;
  11079. if (World.RegionInfo.RegionName == simulator)
  11080. info = new GridRegion(World.RegionInfo);
  11081. else
  11082. info = World.GridService.GetRegionByName(m_ScriptEngine.World.RegionInfo.ScopeID, simulator);
  11083. switch (data)
  11084. {
  11085. case ScriptBaseClass.DATA_SIM_POS:
  11086. if (info == null)
  11087. {
  11088. ScriptSleep(m_sleepMsOnRequestSimulatorData);
  11089. return UUID.Zero.ToString();
  11090. }
  11091. bool isHypergridRegion = false;
  11092. if (World.RegionInfo.RegionName != simulator && info.RegionSecret != "")
  11093. {
  11094. // Hypergrid is currently placing real destination region co-ords into RegionSecret.
  11095. // But other code can also use this field for a genuine RegionSecret! Therefore, if
  11096. // anything is present we need to disambiguate.
  11097. //
  11098. // FIXME: Hypergrid should be storing this data in a different field.
  11099. RegionFlags regionFlags
  11100. = (RegionFlags)m_ScriptEngine.World.GridService.GetRegionFlags(
  11101. info.ScopeID, info.RegionID);
  11102. isHypergridRegion = (regionFlags & RegionFlags.Hyperlink) != 0;
  11103. }
  11104. if (isHypergridRegion)
  11105. {
  11106. uint rx = 0, ry = 0;
  11107. Utils.LongToUInts(Convert.ToUInt64(info.RegionSecret), out rx, out ry);
  11108. reply = new LSL_Vector(
  11109. rx,
  11110. ry,
  11111. 0).ToString();
  11112. }
  11113. else
  11114. {
  11115. // Local grid co-oridnates
  11116. reply = new LSL_Vector(
  11117. info.RegionLocX,
  11118. info.RegionLocY,
  11119. 0).ToString();
  11120. }
  11121. break;
  11122. case ScriptBaseClass.DATA_SIM_STATUS:
  11123. if (info != null)
  11124. reply = "up"; // Duh!
  11125. else
  11126. reply = "unknown";
  11127. break;
  11128. case ScriptBaseClass.DATA_SIM_RATING:
  11129. if (info == null)
  11130. {
  11131. ScriptSleep(m_sleepMsOnRequestSimulatorData);
  11132. return UUID.Zero.ToString();
  11133. }
  11134. int access = info.Maturity;
  11135. if (access == 0)
  11136. reply = "PG";
  11137. else if (access == 1)
  11138. reply = "MATURE";
  11139. else if (access == 2)
  11140. reply = "ADULT";
  11141. else
  11142. reply = "UNKNOWN";
  11143. break;
  11144. case ScriptBaseClass.DATA_SIM_RELEASE:
  11145. if (ossl != null)
  11146. ossl.CheckThreatLevel(ThreatLevel.High, "llRequestSimulatorData");
  11147. reply = "OpenSim";
  11148. break;
  11149. default:
  11150. ScriptSleep(m_sleepMsOnRequestSimulatorData);
  11151. return UUID.Zero.ToString(); // Raise no event
  11152. }
  11153. UUID rq = UUID.Random();
  11154. UUID tid = AsyncCommands.
  11155. DataserverPlugin.RegisterRequest(m_host.LocalId, m_item.ItemID, rq.ToString());
  11156. AsyncCommands.
  11157. DataserverPlugin.DataserverReply(rq.ToString(), reply);
  11158. ScriptSleep(m_sleepMsOnRequestSimulatorData);
  11159. return tid.ToString();
  11160. }
  11161. catch(Exception)
  11162. {
  11163. //m_log.Error("[LSL_API]: llRequestSimulatorData" + e.ToString());
  11164. return UUID.Zero.ToString();
  11165. }
  11166. }
  11167. public LSL_Key llRequestURL()
  11168. {
  11169. m_host.AddScriptLPS(1);
  11170. if (m_UrlModule != null)
  11171. return m_UrlModule.RequestURL(m_ScriptEngine.ScriptModule, m_host, m_item.ItemID, null).ToString();
  11172. return UUID.Zero.ToString();
  11173. }
  11174. public void llForceMouselook(int mouselook)
  11175. {
  11176. m_host.AddScriptLPS(1);
  11177. m_host.SetForceMouselook(mouselook != 0);
  11178. }
  11179. public LSL_Float llGetObjectMass(LSL_Key id)
  11180. {
  11181. m_host.AddScriptLPS(1);
  11182. UUID key = new UUID();
  11183. if (!UUID.TryParse(id, out key))
  11184. return 0;
  11185. // return total object mass
  11186. SceneObjectPart part = World.GetSceneObjectPart(key);
  11187. if (part != null)
  11188. return part.ParentGroup.GetMass();
  11189. // the object is null so the key is for an avatar
  11190. ScenePresence avatar = World.GetScenePresence(key);
  11191. if (avatar != null)
  11192. {
  11193. if (avatar.IsChildAgent)
  11194. {
  11195. // reference http://www.lslwiki.net/lslwiki/wakka.php?wakka=llGetObjectMass
  11196. // child agents have a mass of 1.0
  11197. return 1;
  11198. }
  11199. else
  11200. {
  11201. return avatar.GetMass();
  11202. }
  11203. }
  11204. return 0;
  11205. }
  11206. /// <summary>
  11207. /// llListReplaceList removes the sub-list defined by the inclusive indices
  11208. /// start and end and inserts the src list in its place. The inclusive
  11209. /// nature of the indices means that at least one element must be deleted
  11210. /// if the indices are within the bounds of the existing list. I.e. 2,2
  11211. /// will remove the element at index 2 and replace it with the source
  11212. /// list. Both indices may be negative, with the usual interpretation. An
  11213. /// interesting case is where end is lower than start. As these indices
  11214. /// bound the list to be removed, then 0->end, and start->lim are removed
  11215. /// and the source list is added as a suffix.
  11216. /// </summary>
  11217. public LSL_List llListReplaceList(LSL_List dest, LSL_List src, int start, int end)
  11218. {
  11219. LSL_List pref;
  11220. m_host.AddScriptLPS(1);
  11221. // Note that although we have normalized, both
  11222. // indices could still be negative.
  11223. if (start < 0)
  11224. {
  11225. start = start+dest.Length;
  11226. }
  11227. if (end < 0)
  11228. {
  11229. end = end+dest.Length;
  11230. }
  11231. // The comventional case, remove a sequence starting with
  11232. // start and ending with end. And then insert the source
  11233. // list.
  11234. if (start <= end)
  11235. {
  11236. // If greater than zero, then there is going to be a
  11237. // surviving prefix. Otherwise the inclusive nature
  11238. // of the indices mean that we're going to add the
  11239. // source list as a prefix.
  11240. if (start > 0)
  11241. {
  11242. pref = dest.GetSublist(0,start-1);
  11243. // Only add a suffix if there is something
  11244. // beyond the end index (it's inclusive too).
  11245. if (end + 1 < dest.Length)
  11246. {
  11247. return pref + src + dest.GetSublist(end + 1, -1);
  11248. }
  11249. else
  11250. {
  11251. return pref + src;
  11252. }
  11253. }
  11254. // If start is less than or equal to zero, then
  11255. // the new list is simply a prefix. We still need to
  11256. // figure out any necessary surgery to the destination
  11257. // based upon end. Note that if end exceeds the upper
  11258. // bound in this case, the entire destination list
  11259. // is removed.
  11260. else if (start == 0)
  11261. {
  11262. if (end + 1 < dest.Length)
  11263. return src + dest.GetSublist(end + 1, -1);
  11264. else
  11265. return src;
  11266. }
  11267. else // Start < 0
  11268. {
  11269. if (end + 1 < dest.Length)
  11270. return dest.GetSublist(end + 1, -1);
  11271. else
  11272. return new LSL_List();
  11273. }
  11274. }
  11275. // Finally, if start > end, we strip away a prefix and
  11276. // a suffix, to leave the list that sits <between> ens
  11277. // and start, and then tag on the src list. AT least
  11278. // that's my interpretation. We can get sublist to do
  11279. // this for us. Note that one, or both of the indices
  11280. // might have been negative.
  11281. else
  11282. {
  11283. return dest.GetSublist(end + 1, start - 1) + src;
  11284. }
  11285. }
  11286. public void llLoadURL(string avatar_id, string message, string url)
  11287. {
  11288. m_host.AddScriptLPS(1);
  11289. IDialogModule dm = World.RequestModuleInterface<IDialogModule>();
  11290. if (null != dm)
  11291. dm.SendUrlToUser(
  11292. new UUID(avatar_id), m_host.Name, m_host.UUID, m_host.OwnerID, false, message, url);
  11293. ScriptSleep(m_sleepMsOnLoadURL);
  11294. }
  11295. public void llParcelMediaCommandList(LSL_List commandList)
  11296. {
  11297. // TODO: Not implemented yet (missing in libomv?):
  11298. // 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)
  11299. m_host.AddScriptLPS(1);
  11300. // according to the docs, this command only works if script owner and land owner are the same
  11301. // lets add estate owners and gods, too, and use the generic permission check.
  11302. ILandObject landObject = World.LandChannel.GetLandObject(m_host.AbsolutePosition);
  11303. if (!World.Permissions.CanEditParcelProperties(m_host.OwnerID, landObject, GroupPowers.ChangeMedia, false)) return;
  11304. bool update = false; // send a ParcelMediaUpdate (and possibly change the land's media URL)?
  11305. byte loop = 0;
  11306. LandData landData = landObject.LandData;
  11307. string url = landData.MediaURL;
  11308. string texture = landData.MediaID.ToString();
  11309. bool autoAlign = landData.MediaAutoScale != 0;
  11310. string mediaType = ""; // TODO these have to be added as soon as LandData supports it
  11311. string description = "";
  11312. int width = 0;
  11313. int height = 0;
  11314. ParcelMediaCommandEnum? commandToSend = null;
  11315. float time = 0.0f; // default is from start
  11316. uint cmndFlags = 0;
  11317. ScenePresence presence = null;
  11318. int cmd;
  11319. for (int i = 0; i < commandList.Data.Length; i++)
  11320. {
  11321. if(commandList.Data[i] is LSL_Integer)
  11322. cmd = (LSL_Integer)commandList.Data[i];
  11323. else
  11324. cmd = (int)commandList.Data[i];
  11325. ParcelMediaCommandEnum command = (ParcelMediaCommandEnum)cmd;
  11326. switch (command)
  11327. {
  11328. case ParcelMediaCommandEnum.Agent:
  11329. // we send only to one agent
  11330. if ((i + 1) < commandList.Length)
  11331. {
  11332. if (commandList.Data[i + 1] is LSL_String)
  11333. {
  11334. UUID agentID;
  11335. if (UUID.TryParse((LSL_String)commandList.Data[i + 1], out agentID))
  11336. {
  11337. presence = World.GetScenePresence(agentID);
  11338. }
  11339. }
  11340. else Error("llParcelMediaCommandList", "The argument of PARCEL_MEDIA_COMMAND_AGENT must be a key");
  11341. ++i;
  11342. }
  11343. break;
  11344. case ParcelMediaCommandEnum.Loop:
  11345. loop = 1;
  11346. cmndFlags |= (1 << ScriptBaseClass.PARCEL_MEDIA_COMMAND_LOOP);
  11347. commandToSend = command;
  11348. update = true; //need to send the media update packet to set looping
  11349. break;
  11350. case ParcelMediaCommandEnum.Play:
  11351. loop = 0;
  11352. cmndFlags |= (1 << ScriptBaseClass.PARCEL_MEDIA_COMMAND_PLAY);
  11353. commandToSend = command;
  11354. update = true; //need to send the media update packet to make sure it doesn't loop
  11355. break;
  11356. case ParcelMediaCommandEnum.Pause:
  11357. cmndFlags |= (1 << ScriptBaseClass.PARCEL_MEDIA_COMMAND_PAUSE);
  11358. commandToSend = command;
  11359. break;
  11360. case ParcelMediaCommandEnum.Stop:
  11361. cmndFlags |= (1 << ScriptBaseClass.PARCEL_MEDIA_COMMAND_STOP);
  11362. commandToSend = command;
  11363. break;
  11364. case ParcelMediaCommandEnum.Unload:
  11365. cmndFlags |= (1 << ScriptBaseClass.PARCEL_MEDIA_COMMAND_UNLOAD);
  11366. commandToSend = command;
  11367. break;
  11368. case ParcelMediaCommandEnum.Url:
  11369. if ((i + 1) < commandList.Length)
  11370. {
  11371. if (commandList.Data[i + 1] is LSL_String)
  11372. {
  11373. url = (LSL_String)commandList.Data[i + 1];
  11374. update = true;
  11375. }
  11376. else Error("llParcelMediaCommandList", "The argument of PARCEL_MEDIA_COMMAND_URL must be a string");
  11377. ++i;
  11378. }
  11379. break;
  11380. case ParcelMediaCommandEnum.Texture:
  11381. if ((i + 1) < commandList.Length)
  11382. {
  11383. if (commandList.Data[i + 1] is LSL_String)
  11384. {
  11385. texture = (LSL_String)commandList.Data[i + 1];
  11386. update = true;
  11387. }
  11388. else Error("llParcelMediaCommandList", "The argument of PARCEL_MEDIA_COMMAND_TEXTURE must be a string or a key");
  11389. ++i;
  11390. }
  11391. break;
  11392. case ParcelMediaCommandEnum.Time:
  11393. if ((i + 1) < commandList.Length)
  11394. {
  11395. if (commandList.Data[i + 1] is LSL_Float)
  11396. {
  11397. time = (float)(LSL_Float)commandList.Data[i + 1];
  11398. cmndFlags |= (1 << ScriptBaseClass.PARCEL_MEDIA_COMMAND_TIME);
  11399. }
  11400. else Error("llParcelMediaCommandList", "The argument of PARCEL_MEDIA_COMMAND_TIME must be a float");
  11401. ++i;
  11402. }
  11403. break;
  11404. case ParcelMediaCommandEnum.AutoAlign:
  11405. if ((i + 1) < commandList.Length)
  11406. {
  11407. if (commandList.Data[i + 1] is LSL_Integer)
  11408. {
  11409. autoAlign = (LSL_Integer)commandList.Data[i + 1];
  11410. update = true;
  11411. }
  11412. else Error("llParcelMediaCommandList", "The argument of PARCEL_MEDIA_COMMAND_AUTO_ALIGN must be an integer");
  11413. ++i;
  11414. }
  11415. break;
  11416. case ParcelMediaCommandEnum.Type:
  11417. if ((i + 1) < commandList.Length)
  11418. {
  11419. if (commandList.Data[i + 1] is LSL_String)
  11420. {
  11421. mediaType = (LSL_String)commandList.Data[i + 1];
  11422. update = true;
  11423. }
  11424. else Error("llParcelMediaCommandList", "The argument of PARCEL_MEDIA_COMMAND_TYPE must be a string");
  11425. ++i;
  11426. }
  11427. break;
  11428. case ParcelMediaCommandEnum.Desc:
  11429. if ((i + 1) < commandList.Length)
  11430. {
  11431. if (commandList.Data[i + 1] is LSL_String)
  11432. {
  11433. description = (LSL_String)commandList.Data[i + 1];
  11434. update = true;
  11435. }
  11436. else Error("llParcelMediaCommandList", "The argument of PARCEL_MEDIA_COMMAND_DESC must be a string");
  11437. ++i;
  11438. }
  11439. break;
  11440. case ParcelMediaCommandEnum.Size:
  11441. if ((i + 2) < commandList.Length)
  11442. {
  11443. if (commandList.Data[i + 1] is LSL_Integer)
  11444. {
  11445. if (commandList.Data[i + 2] is LSL_Integer)
  11446. {
  11447. width = (LSL_Integer)commandList.Data[i + 1];
  11448. height = (LSL_Integer)commandList.Data[i + 2];
  11449. update = true;
  11450. }
  11451. else Error("llParcelMediaCommandList", "The second argument of PARCEL_MEDIA_COMMAND_SIZE must be an integer");
  11452. }
  11453. else Error("llParcelMediaCommandList", "The first argument of PARCEL_MEDIA_COMMAND_SIZE must be an integer");
  11454. i += 2;
  11455. }
  11456. break;
  11457. default:
  11458. NotImplemented("llParcelMediaCommandList", "Parameter not supported yet: " + Enum.Parse(typeof(ParcelMediaCommandEnum), commandList.Data[i].ToString()).ToString());
  11459. break;
  11460. }//end switch
  11461. }//end for
  11462. // if we didn't get a presence, we send to all and change the url
  11463. // if we did get a presence, we only send to the agent specified, and *don't change the land settings*!
  11464. // did something important change or do we only start/stop/pause?
  11465. if (update)
  11466. {
  11467. if (presence == null)
  11468. {
  11469. // we send to all
  11470. landData.MediaID = new UUID(texture);
  11471. landData.MediaAutoScale = autoAlign ? (byte)1 : (byte)0;
  11472. landData.MediaWidth = width;
  11473. landData.MediaHeight = height;
  11474. landData.MediaType = mediaType;
  11475. // do that one last, it will cause a ParcelPropertiesUpdate
  11476. landObject.SetMediaUrl(url);
  11477. // now send to all (non-child) agents in the parcel
  11478. World.ForEachRootScenePresence(delegate(ScenePresence sp)
  11479. {
  11480. if (sp.currentParcelUUID == landData.GlobalID)
  11481. {
  11482. sp.ControllingClient.SendParcelMediaUpdate(landData.MediaURL,
  11483. landData.MediaID,
  11484. landData.MediaAutoScale,
  11485. mediaType,
  11486. description,
  11487. width, height,
  11488. loop);
  11489. }
  11490. });
  11491. }
  11492. else if (!presence.IsChildAgent)
  11493. {
  11494. // we only send to one (root) agent
  11495. presence.ControllingClient.SendParcelMediaUpdate(url,
  11496. new UUID(texture),
  11497. autoAlign ? (byte)1 : (byte)0,
  11498. mediaType,
  11499. description,
  11500. width, height,
  11501. loop);
  11502. }
  11503. }
  11504. if (commandToSend != null)
  11505. {
  11506. // the commandList contained a start/stop/... command, too
  11507. if (presence == null)
  11508. {
  11509. // send to all (non-child) agents in the parcel
  11510. World.ForEachRootScenePresence(delegate(ScenePresence sp)
  11511. {
  11512. if (sp.currentParcelUUID == landData.GlobalID)
  11513. {
  11514. sp.ControllingClient.SendParcelMediaCommand(cmndFlags,
  11515. commandToSend.Value, time);
  11516. }
  11517. });
  11518. }
  11519. else if (!presence.IsChildAgent)
  11520. {
  11521. presence.ControllingClient.SendParcelMediaCommand(cmndFlags,
  11522. commandToSend.Value, time);
  11523. }
  11524. }
  11525. ScriptSleep(m_sleepMsOnParcelMediaCommandList);
  11526. }
  11527. public LSL_List llParcelMediaQuery(LSL_List aList)
  11528. {
  11529. m_host.AddScriptLPS(1);
  11530. LSL_List list = new LSL_List();
  11531. Vector3 pos = m_host.AbsolutePosition;
  11532. ILandObject landObject = World.LandChannel.GetLandObject(pos);
  11533. if(landObject == null)
  11534. return list;
  11535. if (!World.Permissions.CanEditParcelProperties(m_host.OwnerID, landObject, GroupPowers.ChangeMedia, false))
  11536. return list;
  11537. LandData land = landObject.LandData;
  11538. if(land == null)
  11539. return list;
  11540. //TO DO: make the implementation for the missing commands
  11541. //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)
  11542. for (int i = 0; i < aList.Data.Length; i++)
  11543. {
  11544. if (aList.Data[i] != null)
  11545. {
  11546. switch ((ParcelMediaCommandEnum) Convert.ToInt32(aList.Data[i].ToString()))
  11547. {
  11548. case ParcelMediaCommandEnum.Url:
  11549. list.Add(new LSL_String(land.MediaURL));
  11550. break;
  11551. case ParcelMediaCommandEnum.Desc:
  11552. list.Add(new LSL_String(land.MediaDescription));
  11553. break;
  11554. case ParcelMediaCommandEnum.Texture:
  11555. list.Add(new LSL_String(land.MediaID.ToString()));
  11556. break;
  11557. case ParcelMediaCommandEnum.Type:
  11558. list.Add(new LSL_String(land.MediaType));
  11559. break;
  11560. case ParcelMediaCommandEnum.Size:
  11561. list.Add(new LSL_String(land.MediaWidth));
  11562. list.Add(new LSL_String(land.MediaHeight));
  11563. break;
  11564. default:
  11565. ParcelMediaCommandEnum mediaCommandEnum = ParcelMediaCommandEnum.Url;
  11566. NotImplemented("llParcelMediaQuery", "Parameter not supported yet: " + Enum.Parse(mediaCommandEnum.GetType() , aList.Data[i].ToString()).ToString());
  11567. break;
  11568. }
  11569. }
  11570. }
  11571. ScriptSleep(m_sleepMsOnParcelMediaQuery);
  11572. return list;
  11573. }
  11574. public LSL_Integer llModPow(int a, int b, int c)
  11575. {
  11576. m_host.AddScriptLPS(1);
  11577. Int64 tmp = 0;
  11578. Math.DivRem(Convert.ToInt64(Math.Pow(a, b)), c, out tmp);
  11579. ScriptSleep(m_sleepMsOnModPow);
  11580. return Convert.ToInt32(tmp);
  11581. }
  11582. public LSL_Integer llGetInventoryType(string name)
  11583. {
  11584. m_host.AddScriptLPS(1);
  11585. TaskInventoryItem item = m_host.Inventory.GetInventoryItem(name);
  11586. if (item == null)
  11587. return -1;
  11588. return item.Type;
  11589. }
  11590. public void llSetPayPrice(int price, LSL_List quick_pay_buttons)
  11591. {
  11592. m_host.AddScriptLPS(1);
  11593. if (quick_pay_buttons.Data.Length < 4)
  11594. {
  11595. int x;
  11596. for (x=quick_pay_buttons.Data.Length; x<= 4; x++)
  11597. {
  11598. quick_pay_buttons.Add(ScriptBaseClass.PAY_HIDE);
  11599. }
  11600. }
  11601. int[] nPrice = new int[5];
  11602. nPrice[0] = price;
  11603. nPrice[1] = quick_pay_buttons.GetLSLIntegerItem(0);
  11604. nPrice[2] = quick_pay_buttons.GetLSLIntegerItem(1);
  11605. nPrice[3] = quick_pay_buttons.GetLSLIntegerItem(2);
  11606. nPrice[4] = quick_pay_buttons.GetLSLIntegerItem(3);
  11607. m_host.ParentGroup.RootPart.PayPrice = nPrice;
  11608. m_host.ParentGroup.HasGroupChanged = true;
  11609. }
  11610. public LSL_Vector llGetCameraPos()
  11611. {
  11612. m_host.AddScriptLPS(1);
  11613. if (m_item.PermsGranter == UUID.Zero)
  11614. return Vector3.Zero;
  11615. if ((m_item.PermsMask & ScriptBaseClass.PERMISSION_TRACK_CAMERA) == 0)
  11616. {
  11617. Error("llGetCameraPos", "No permissions to track the camera");
  11618. return Vector3.Zero;
  11619. }
  11620. // ScenePresence presence = World.GetScenePresence(m_host.OwnerID);
  11621. ScenePresence presence = World.GetScenePresence(m_item.PermsGranter);
  11622. if (presence != null)
  11623. {
  11624. LSL_Vector pos = new LSL_Vector(presence.CameraPosition);
  11625. return pos;
  11626. }
  11627. return Vector3.Zero;
  11628. }
  11629. public LSL_Rotation llGetCameraRot()
  11630. {
  11631. m_host.AddScriptLPS(1);
  11632. if (m_item.PermsGranter == UUID.Zero)
  11633. return Quaternion.Identity;
  11634. if ((m_item.PermsMask & ScriptBaseClass.PERMISSION_TRACK_CAMERA) == 0)
  11635. {
  11636. Error("llGetCameraRot", "No permissions to track the camera");
  11637. return Quaternion.Identity;
  11638. }
  11639. // ScenePresence presence = World.GetScenePresence(m_host.OwnerID);
  11640. ScenePresence presence = World.GetScenePresence(m_item.PermsGranter);
  11641. if (presence != null)
  11642. {
  11643. return new LSL_Rotation(presence.CameraRotation);
  11644. }
  11645. return Quaternion.Identity;
  11646. }
  11647. public void llSetPrimURL(string url)
  11648. {
  11649. m_host.AddScriptLPS(1);
  11650. Deprecated("llSetPrimURL", "Use llSetPrimMediaParams instead");
  11651. ScriptSleep(m_sleepMsOnSetPrimURL);
  11652. }
  11653. public void llRefreshPrimURL()
  11654. {
  11655. m_host.AddScriptLPS(1);
  11656. Deprecated("llRefreshPrimURL");
  11657. ScriptSleep(m_sleepMsOnRefreshPrimURL);
  11658. }
  11659. public LSL_String llEscapeURL(string url)
  11660. {
  11661. m_host.AddScriptLPS(1);
  11662. try
  11663. {
  11664. return Uri.EscapeDataString(url);
  11665. }
  11666. catch (Exception ex)
  11667. {
  11668. return "llEscapeURL: " + ex.ToString();
  11669. }
  11670. }
  11671. public LSL_String llUnescapeURL(string url)
  11672. {
  11673. m_host.AddScriptLPS(1);
  11674. try
  11675. {
  11676. return Uri.UnescapeDataString(url);
  11677. }
  11678. catch (Exception ex)
  11679. {
  11680. return "llUnescapeURL: " + ex.ToString();
  11681. }
  11682. }
  11683. public void llMapDestination(string simname, LSL_Vector pos, LSL_Vector lookAt)
  11684. {
  11685. m_host.AddScriptLPS(1);
  11686. DetectParams detectedParams = m_ScriptEngine.GetDetectParams(m_item.ItemID, 0);
  11687. if (detectedParams == null)
  11688. {
  11689. if (m_host.ParentGroup.IsAttachment == true)
  11690. {
  11691. detectedParams = new DetectParams();
  11692. detectedParams.Key = m_host.OwnerID;
  11693. }
  11694. else
  11695. {
  11696. return;
  11697. }
  11698. }
  11699. ScenePresence avatar = World.GetScenePresence(detectedParams.Key);
  11700. if (avatar != null)
  11701. {
  11702. avatar.ControllingClient.SendScriptTeleportRequest(m_host.Name,
  11703. simname, pos, lookAt);
  11704. }
  11705. ScriptSleep(m_sleepMsOnMapDestination);
  11706. }
  11707. public void llAddToLandBanList(LSL_Key avatar, double hours)
  11708. {
  11709. m_host.AddScriptLPS(1);
  11710. UUID key;
  11711. ILandObject land = World.LandChannel.GetLandObject(m_host.AbsolutePosition);
  11712. if (World.Permissions.CanEditParcelProperties(m_host.OwnerID, land, GroupPowers.LandManageBanned, false))
  11713. {
  11714. int expires = 0;
  11715. if (hours != 0)
  11716. expires = Util.UnixTimeSinceEpoch() + (int)(3600.0 * hours);
  11717. if (UUID.TryParse(avatar, out key))
  11718. {
  11719. int idx = land.LandData.ParcelAccessList.FindIndex(
  11720. delegate(LandAccessEntry e)
  11721. {
  11722. if (e.AgentID == key && e.Flags == AccessList.Ban)
  11723. return true;
  11724. return false;
  11725. });
  11726. if (idx != -1 && (land.LandData.ParcelAccessList[idx].Expires == 0 || (expires != 0 && expires < land.LandData.ParcelAccessList[idx].Expires)))
  11727. return;
  11728. if (idx != -1)
  11729. land.LandData.ParcelAccessList.RemoveAt(idx);
  11730. LandAccessEntry entry = new LandAccessEntry();
  11731. entry.AgentID = key;
  11732. entry.Flags = AccessList.Ban;
  11733. entry.Expires = expires;
  11734. land.LandData.ParcelAccessList.Add(entry);
  11735. World.EventManager.TriggerLandObjectUpdated((uint)land.LandData.LocalID, land);
  11736. }
  11737. }
  11738. ScriptSleep(m_sleepMsOnAddToLandBanList);
  11739. }
  11740. public void llRemoveFromLandPassList(string avatar)
  11741. {
  11742. m_host.AddScriptLPS(1);
  11743. UUID key;
  11744. ILandObject land = World.LandChannel.GetLandObject(m_host.AbsolutePosition);
  11745. if (World.Permissions.CanEditParcelProperties(m_host.OwnerID, land, GroupPowers.LandManagePasses, false))
  11746. {
  11747. if (UUID.TryParse(avatar, out key))
  11748. {
  11749. int idx = land.LandData.ParcelAccessList.FindIndex(
  11750. delegate(LandAccessEntry e)
  11751. {
  11752. if (e.AgentID == key && e.Flags == AccessList.Access)
  11753. return true;
  11754. return false;
  11755. });
  11756. if (idx != -1)
  11757. {
  11758. land.LandData.ParcelAccessList.RemoveAt(idx);
  11759. World.EventManager.TriggerLandObjectUpdated((uint)land.LandData.LocalID, land);
  11760. }
  11761. }
  11762. }
  11763. ScriptSleep(m_sleepMsOnRemoveFromLandPassList);
  11764. }
  11765. public void llRemoveFromLandBanList(string avatar)
  11766. {
  11767. m_host.AddScriptLPS(1);
  11768. UUID key;
  11769. ILandObject land = World.LandChannel.GetLandObject(m_host.AbsolutePosition);
  11770. if (World.Permissions.CanEditParcelProperties(m_host.OwnerID, land, GroupPowers.LandManageBanned, false))
  11771. {
  11772. if (UUID.TryParse(avatar, out key))
  11773. {
  11774. int idx = land.LandData.ParcelAccessList.FindIndex(
  11775. delegate(LandAccessEntry e)
  11776. {
  11777. if (e.AgentID == key && e.Flags == AccessList.Ban)
  11778. return true;
  11779. return false;
  11780. });
  11781. if (idx != -1)
  11782. {
  11783. land.LandData.ParcelAccessList.RemoveAt(idx);
  11784. World.EventManager.TriggerLandObjectUpdated((uint)land.LandData.LocalID, land);
  11785. }
  11786. }
  11787. }
  11788. ScriptSleep(m_sleepMsOnRemoveFromLandBanList);
  11789. }
  11790. public void llSetCameraParams(LSL_List rules)
  11791. {
  11792. m_host.AddScriptLPS(1);
  11793. // the object we are in
  11794. UUID objectID = m_host.ParentUUID;
  11795. if (objectID == UUID.Zero)
  11796. return;
  11797. // we need the permission first, to know which avatar we want to set the camera for
  11798. UUID agentID = m_item.PermsGranter;
  11799. if (agentID == UUID.Zero)
  11800. return;
  11801. if ((m_item.PermsMask & ScriptBaseClass.PERMISSION_CONTROL_CAMERA) == 0)
  11802. return;
  11803. ScenePresence presence = World.GetScenePresence(agentID);
  11804. // we are not interested in child-agents
  11805. if (presence.IsChildAgent) return;
  11806. SortedDictionary<int, float> parameters = new SortedDictionary<int, float>();
  11807. object[] data = rules.Data;
  11808. for (int i = 0; i < data.Length; ++i)
  11809. {
  11810. int type;
  11811. try
  11812. {
  11813. type = Convert.ToInt32(data[i++].ToString());
  11814. }
  11815. catch
  11816. {
  11817. Error("llSetCameraParams", string.Format("Invalid camera param type {0}", data[i - 1]));
  11818. return;
  11819. }
  11820. if (i >= data.Length) break; // odd number of entries => ignore the last
  11821. // some special cases: Vector parameters are split into 3 float parameters (with type+1, type+2, type+3)
  11822. switch (type)
  11823. {
  11824. case ScriptBaseClass.CAMERA_FOCUS:
  11825. case ScriptBaseClass.CAMERA_FOCUS_OFFSET:
  11826. case ScriptBaseClass.CAMERA_POSITION:
  11827. LSL_Vector v = (LSL_Vector)data[i];
  11828. try
  11829. {
  11830. parameters.Add(type + 1, (float)v.x);
  11831. }
  11832. catch
  11833. {
  11834. switch(type)
  11835. {
  11836. case ScriptBaseClass.CAMERA_FOCUS:
  11837. Error("llSetCameraParams", "CAMERA_FOCUS: Parameter x is invalid");
  11838. return;
  11839. case ScriptBaseClass.CAMERA_FOCUS_OFFSET:
  11840. Error("llSetCameraParams", "CAMERA_FOCUS_OFFSET: Parameter x is invalid");
  11841. return;
  11842. case ScriptBaseClass.CAMERA_POSITION:
  11843. Error("llSetCameraParams", "CAMERA_POSITION: Parameter x is invalid");
  11844. return;
  11845. }
  11846. }
  11847. try
  11848. {
  11849. parameters.Add(type + 2, (float)v.y);
  11850. }
  11851. catch
  11852. {
  11853. switch(type)
  11854. {
  11855. case ScriptBaseClass.CAMERA_FOCUS:
  11856. Error("llSetCameraParams", "CAMERA_FOCUS: Parameter y is invalid");
  11857. return;
  11858. case ScriptBaseClass.CAMERA_FOCUS_OFFSET:
  11859. Error("llSetCameraParams", "CAMERA_FOCUS_OFFSET: Parameter y is invalid");
  11860. return;
  11861. case ScriptBaseClass.CAMERA_POSITION:
  11862. Error("llSetCameraParams", "CAMERA_POSITION: Parameter y is invalid");
  11863. return;
  11864. }
  11865. }
  11866. try
  11867. {
  11868. parameters.Add(type + 3, (float)v.z);
  11869. }
  11870. catch
  11871. {
  11872. switch(type)
  11873. {
  11874. case ScriptBaseClass.CAMERA_FOCUS:
  11875. Error("llSetCameraParams", "CAMERA_FOCUS: Parameter z is invalid");
  11876. return;
  11877. case ScriptBaseClass.CAMERA_FOCUS_OFFSET:
  11878. Error("llSetCameraParams", "CAMERA_FOCUS_OFFSET: Parameter z is invalid");
  11879. return;
  11880. case ScriptBaseClass.CAMERA_POSITION:
  11881. Error("llSetCameraParams", "CAMERA_POSITION: Parameter z is invalid");
  11882. return;
  11883. }
  11884. }
  11885. break;
  11886. default:
  11887. // TODO: clean that up as soon as the implicit casts are in
  11888. if (data[i] is LSL_Float)
  11889. parameters.Add(type, (float)((LSL_Float)data[i]).value);
  11890. else if (data[i] is LSL_Integer)
  11891. parameters.Add(type, (float)((LSL_Integer)data[i]).value);
  11892. else
  11893. {
  11894. try
  11895. {
  11896. parameters.Add(type, Convert.ToSingle(data[i]));
  11897. }
  11898. catch
  11899. {
  11900. Error("llSetCameraParams", string.Format("{0}: Parameter is invalid", type));
  11901. }
  11902. }
  11903. break;
  11904. }
  11905. }
  11906. if (parameters.Count > 0) presence.ControllingClient.SendSetFollowCamProperties(objectID, parameters);
  11907. }
  11908. public void llClearCameraParams()
  11909. {
  11910. m_host.AddScriptLPS(1);
  11911. // the object we are in
  11912. UUID objectID = m_host.ParentUUID;
  11913. if (objectID == UUID.Zero)
  11914. return;
  11915. // we need the permission first, to know which avatar we want to clear the camera for
  11916. UUID agentID = m_item.PermsGranter;
  11917. if (agentID == UUID.Zero)
  11918. return;
  11919. if ((m_item.PermsMask & ScriptBaseClass.PERMISSION_CONTROL_CAMERA) == 0)
  11920. return;
  11921. ScenePresence presence = World.GetScenePresence(agentID);
  11922. // we are not interested in child-agents
  11923. if (presence.IsChildAgent)
  11924. return;
  11925. presence.ControllingClient.SendClearFollowCamProperties(objectID);
  11926. }
  11927. public LSL_Float llListStatistics(int operation, LSL_List src)
  11928. {
  11929. m_host.AddScriptLPS(1);
  11930. switch (operation)
  11931. {
  11932. case ScriptBaseClass.LIST_STAT_RANGE:
  11933. return src.Range();
  11934. case ScriptBaseClass.LIST_STAT_MIN:
  11935. return src.Min();
  11936. case ScriptBaseClass.LIST_STAT_MAX:
  11937. return src.Max();
  11938. case ScriptBaseClass.LIST_STAT_MEAN:
  11939. return src.Mean();
  11940. case ScriptBaseClass.LIST_STAT_MEDIAN:
  11941. return LSL_List.ToDoubleList(src).Median();
  11942. case ScriptBaseClass.LIST_STAT_NUM_COUNT:
  11943. return src.NumericLength();
  11944. case ScriptBaseClass.LIST_STAT_STD_DEV:
  11945. return src.StdDev();
  11946. case ScriptBaseClass.LIST_STAT_SUM:
  11947. return src.Sum();
  11948. case ScriptBaseClass.LIST_STAT_SUM_SQUARES:
  11949. return src.SumSqrs();
  11950. case ScriptBaseClass.LIST_STAT_GEOMETRIC_MEAN:
  11951. return src.GeometricMean();
  11952. case ScriptBaseClass.LIST_STAT_HARMONIC_MEAN:
  11953. return src.HarmonicMean();
  11954. default:
  11955. return 0.0;
  11956. }
  11957. }
  11958. public LSL_Integer llGetUnixTime()
  11959. {
  11960. m_host.AddScriptLPS(1);
  11961. return Util.UnixTimeSinceEpoch();
  11962. }
  11963. public LSL_Integer llGetParcelFlags(LSL_Vector pos)
  11964. {
  11965. m_host.AddScriptLPS(1);
  11966. return (int)World.LandChannel.GetLandObject((float)pos.x, (float)pos.y).LandData.Flags;
  11967. }
  11968. public LSL_Integer llGetRegionFlags()
  11969. {
  11970. m_host.AddScriptLPS(1);
  11971. IEstateModule estate = World.RequestModuleInterface<IEstateModule>();
  11972. if (estate == null)
  11973. return 67108864;
  11974. return (int)estate.GetRegionFlags();
  11975. }
  11976. public LSL_String llXorBase64StringsCorrect(string str1, string str2)
  11977. {
  11978. m_host.AddScriptLPS(1);
  11979. if (str1 == String.Empty)
  11980. return String.Empty;
  11981. if (str2 == String.Empty)
  11982. return str1;
  11983. int len = str2.Length;
  11984. if ((len % 4) != 0) // LL is EVIL!!!!
  11985. {
  11986. while (str2.EndsWith("="))
  11987. str2 = str2.Substring(0, str2.Length - 1);
  11988. len = str2.Length;
  11989. int mod = len % 4;
  11990. if (mod == 1)
  11991. str2 = str2.Substring(0, str2.Length - 1);
  11992. else if (mod == 2)
  11993. str2 += "==";
  11994. else if (mod == 3)
  11995. str2 += "=";
  11996. }
  11997. byte[] data1;
  11998. byte[] data2;
  11999. try
  12000. {
  12001. data1 = Convert.FromBase64String(str1);
  12002. data2 = Convert.FromBase64String(str2);
  12003. }
  12004. catch (Exception)
  12005. {
  12006. return new LSL_String(String.Empty);
  12007. }
  12008. byte[] d2 = new Byte[data1.Length];
  12009. int pos = 0;
  12010. if (data1.Length <= data2.Length)
  12011. {
  12012. Array.Copy(data2, 0, d2, 0, data1.Length);
  12013. }
  12014. else
  12015. {
  12016. while (pos < data1.Length)
  12017. {
  12018. len = data1.Length - pos;
  12019. if (len > data2.Length)
  12020. len = data2.Length;
  12021. Array.Copy(data2, 0, d2, pos, len);
  12022. pos += len;
  12023. }
  12024. }
  12025. for (pos = 0 ; pos < data1.Length ; pos++ )
  12026. data1[pos] ^= d2[pos];
  12027. return Convert.ToBase64String(data1);
  12028. }
  12029. public LSL_Key llHTTPRequest(string url, LSL_List parameters, string body)
  12030. {
  12031. // Partial implementation: support for parameter flags needed
  12032. // see http://wiki.secondlife.com/wiki/LlHTTPRequest
  12033. // parameter flags support are implemented in ScriptsHttpRequests.cs
  12034. // in StartHttpRequest
  12035. m_host.AddScriptLPS(1);
  12036. IHttpRequestModule httpScriptMod =
  12037. m_ScriptEngine.World.RequestModuleInterface<IHttpRequestModule>();
  12038. List<string> param = new List<string>();
  12039. bool ok;
  12040. Int32 flag;
  12041. int nCustomHeaders = 0;
  12042. for (int i = 0; i < parameters.Data.Length; i += 2)
  12043. {
  12044. ok = Int32.TryParse(parameters.Data[i].ToString(), out flag);
  12045. if (!ok || flag < 0 ||
  12046. flag > (int)HttpRequestConstants.HTTP_PRAGMA_NO_CACHE)
  12047. {
  12048. Error("llHTTPRequest", "Parameter " + i.ToString() + " is an invalid flag");
  12049. }
  12050. param.Add(parameters.Data[i].ToString()); //Add parameter flag
  12051. if (flag != (int)HttpRequestConstants.HTTP_CUSTOM_HEADER)
  12052. {
  12053. param.Add(parameters.Data[i+1].ToString()); //Add parameter value
  12054. }
  12055. else
  12056. {
  12057. //Parameters are in pairs and custom header takes
  12058. //arguments in pairs so adjust for header marker.
  12059. ++i;
  12060. //Maximum of 8 headers are allowed based on the
  12061. //Second Life documentation for llHTTPRequest.
  12062. for (int count = 1; count <= 8; ++count)
  12063. {
  12064. if(nCustomHeaders >= 8)
  12065. {
  12066. Error("llHTTPRequest", "Max number of custom headers is 8, excess ignored");
  12067. break;
  12068. }
  12069. //Enough parameters remaining for (another) header?
  12070. if (parameters.Data.Length - i < 2)
  12071. {
  12072. //There must be at least one name/value pair for custom header
  12073. if (count == 1)
  12074. Error("llHTTPRequest", "Missing name/value for custom header at parameter " + i.ToString());
  12075. break;
  12076. }
  12077. if (HttpStandardHeaders.Contains(parameters.Data[i].ToString(), StringComparer.OrdinalIgnoreCase))
  12078. Error("llHTTPRequest", "Name is invalid as a custom header at parameter " + i.ToString());
  12079. param.Add(parameters.Data[i].ToString());
  12080. param.Add(parameters.Data[i+1].ToString());
  12081. nCustomHeaders++;
  12082. //Have we reached the end of the list of headers?
  12083. //End is marked by a string with a single digit.
  12084. if (i + 2 >= parameters.Data.Length ||
  12085. Char.IsDigit(parameters.Data[i + 2].ToString()[0]))
  12086. {
  12087. break;
  12088. }
  12089. i += 2;
  12090. }
  12091. }
  12092. }
  12093. Vector3 position = m_host.AbsolutePosition;
  12094. Vector3 velocity = m_host.Velocity;
  12095. Quaternion rotation = m_host.RotationOffset;
  12096. string ownerName = String.Empty;
  12097. ScenePresence scenePresence = World.GetScenePresence(m_host.OwnerID);
  12098. if (scenePresence == null)
  12099. ownerName = resolveName(m_host.OwnerID);
  12100. else
  12101. ownerName = scenePresence.Name;
  12102. RegionInfo regionInfo = World.RegionInfo;
  12103. Dictionary<string, string> httpHeaders = new Dictionary<string, string>();
  12104. string shard = "OpenSim";
  12105. IConfigSource config = m_ScriptEngine.ConfigSource;
  12106. if (config.Configs["Network"] != null)
  12107. {
  12108. shard = config.Configs["Network"].GetString("shard", shard);
  12109. }
  12110. httpHeaders["X-SecondLife-Shard"] = shard;
  12111. httpHeaders["X-SecondLife-Object-Name"] = m_host.Name;
  12112. httpHeaders["X-SecondLife-Object-Key"] = m_host.UUID.ToString();
  12113. httpHeaders["X-SecondLife-Region"] = string.Format("{0} ({1}, {2})", regionInfo.RegionName, regionInfo.RegionLocX, regionInfo.RegionLocY);
  12114. httpHeaders["X-SecondLife-Local-Position"] = string.Format("({0:0.000000}, {1:0.000000}, {2:0.000000})", position.X, position.Y, position.Z);
  12115. httpHeaders["X-SecondLife-Local-Velocity"] = string.Format("({0:0.000000}, {1:0.000000}, {2:0.000000})", velocity.X, velocity.Y, velocity.Z);
  12116. 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);
  12117. httpHeaders["X-SecondLife-Owner-Name"] = ownerName;
  12118. httpHeaders["X-SecondLife-Owner-Key"] = m_host.OwnerID.ToString();
  12119. string userAgent = config.Configs["Network"].GetString("user_agent", null);
  12120. if (userAgent != null)
  12121. httpHeaders["User-Agent"] = userAgent;
  12122. // See if the URL contains any header hacks
  12123. string[] urlParts = url.Split(new char[] {'\n'});
  12124. if (urlParts.Length > 1)
  12125. {
  12126. // Iterate the passed headers and parse them
  12127. for (int i = 1 ; i < urlParts.Length ; i++ )
  12128. {
  12129. // The rest of those would be added to the body in SL.
  12130. // Let's not do that.
  12131. if (urlParts[i] == String.Empty)
  12132. break;
  12133. // See if this could be a valid header
  12134. string[] headerParts = urlParts[i].Split(new char[] {':'}, 2);
  12135. if (headerParts.Length != 2)
  12136. continue;
  12137. string headerName = headerParts[0].Trim();
  12138. string headerValue = headerParts[1].Trim();
  12139. // Filter out headers that could be used to abuse
  12140. // another system or cloak the request
  12141. if (headerName.ToLower() == "x-secondlife-shard" ||
  12142. headerName.ToLower() == "x-secondlife-object-name" ||
  12143. headerName.ToLower() == "x-secondlife-object-key" ||
  12144. headerName.ToLower() == "x-secondlife-region" ||
  12145. headerName.ToLower() == "x-secondlife-local-position" ||
  12146. headerName.ToLower() == "x-secondlife-local-velocity" ||
  12147. headerName.ToLower() == "x-secondlife-local-rotation" ||
  12148. headerName.ToLower() == "x-secondlife-owner-name" ||
  12149. headerName.ToLower() == "x-secondlife-owner-key" ||
  12150. headerName.ToLower() == "connection" ||
  12151. headerName.ToLower() == "content-length" ||
  12152. headerName.ToLower() == "from" ||
  12153. headerName.ToLower() == "host" ||
  12154. headerName.ToLower() == "proxy-authorization" ||
  12155. headerName.ToLower() == "referer" ||
  12156. headerName.ToLower() == "trailer" ||
  12157. headerName.ToLower() == "transfer-encoding" ||
  12158. headerName.ToLower() == "via" ||
  12159. headerName.ToLower() == "authorization")
  12160. continue;
  12161. httpHeaders[headerName] = headerValue;
  12162. }
  12163. // Finally, strip any protocol specifier from the URL
  12164. url = urlParts[0].Trim();
  12165. int idx = url.IndexOf(" HTTP/");
  12166. if (idx != -1)
  12167. url = url.Substring(0, idx);
  12168. }
  12169. string authregex = @"^(https?:\/\/)(\w+):(\w+)@(.*)$";
  12170. Regex r = new Regex(authregex);
  12171. int[] gnums = r.GetGroupNumbers();
  12172. Match m = r.Match(url);
  12173. if (m.Success)
  12174. {
  12175. for (int i = 1; i < gnums.Length; i++)
  12176. {
  12177. //System.Text.RegularExpressions.Group g = m.Groups[gnums[i]];
  12178. //CaptureCollection cc = g.Captures;
  12179. }
  12180. if (m.Groups.Count == 5)
  12181. {
  12182. httpHeaders["Authorization"] = String.Format("Basic {0}", Convert.ToBase64String(System.Text.ASCIIEncoding.ASCII.GetBytes(m.Groups[2].ToString() + ":" + m.Groups[3].ToString())));
  12183. url = m.Groups[1].ToString() + m.Groups[4].ToString();
  12184. }
  12185. }
  12186. HttpInitialRequestStatus status;
  12187. UUID reqID
  12188. = httpScriptMod.StartHttpRequest(m_host.LocalId, m_item.ItemID, url, param, httpHeaders, body, out status);
  12189. if (status == HttpInitialRequestStatus.DISALLOWED_BY_FILTER)
  12190. Error("llHttpRequest", string.Format("Request to {0} disallowed by filter", url));
  12191. if (reqID != UUID.Zero)
  12192. return reqID.ToString();
  12193. else
  12194. return null;
  12195. }
  12196. public void llHTTPResponse(LSL_Key id, int status, string body)
  12197. {
  12198. // Partial implementation: support for parameter flags needed
  12199. // see http://wiki.secondlife.com/wiki/llHTTPResponse
  12200. m_host.AddScriptLPS(1);
  12201. if (m_UrlModule != null)
  12202. m_UrlModule.HttpResponse(new UUID(id), status,body);
  12203. }
  12204. public void llResetLandBanList()
  12205. {
  12206. m_host.AddScriptLPS(1);
  12207. LandData land = World.LandChannel.GetLandObject(m_host.AbsolutePosition).LandData;
  12208. if (land.OwnerID == m_host.OwnerID)
  12209. {
  12210. foreach (LandAccessEntry entry in land.ParcelAccessList)
  12211. {
  12212. if (entry.Flags == AccessList.Ban)
  12213. {
  12214. land.ParcelAccessList.Remove(entry);
  12215. }
  12216. }
  12217. }
  12218. ScriptSleep(m_sleepMsOnResetLandBanList);
  12219. }
  12220. public void llResetLandPassList()
  12221. {
  12222. m_host.AddScriptLPS(1);
  12223. LandData land = World.LandChannel.GetLandObject(m_host.AbsolutePosition).LandData;
  12224. if (land.OwnerID == m_host.OwnerID)
  12225. {
  12226. foreach (LandAccessEntry entry in land.ParcelAccessList)
  12227. {
  12228. if (entry.Flags == AccessList.Access)
  12229. {
  12230. land.ParcelAccessList.Remove(entry);
  12231. }
  12232. }
  12233. }
  12234. ScriptSleep(m_sleepMsOnResetLandPassList);
  12235. }
  12236. public LSL_Integer llGetParcelPrimCount(LSL_Vector pos, int category, int sim_wide)
  12237. {
  12238. m_host.AddScriptLPS(1);
  12239. ILandObject lo = World.LandChannel.GetLandObject((float)pos.x, (float)pos.y);
  12240. if (lo == null)
  12241. return 0;
  12242. IPrimCounts pc = lo.PrimCounts;
  12243. if (sim_wide != ScriptBaseClass.FALSE)
  12244. {
  12245. if (category == ScriptBaseClass.PARCEL_COUNT_TOTAL)
  12246. {
  12247. return pc.Simulator;
  12248. }
  12249. else
  12250. {
  12251. // counts not implemented yet
  12252. return 0;
  12253. }
  12254. }
  12255. else
  12256. {
  12257. if (category == ScriptBaseClass.PARCEL_COUNT_TOTAL)
  12258. return pc.Total;
  12259. else if (category == ScriptBaseClass.PARCEL_COUNT_OWNER)
  12260. return pc.Owner;
  12261. else if (category == ScriptBaseClass.PARCEL_COUNT_GROUP)
  12262. return pc.Group;
  12263. else if (category == ScriptBaseClass.PARCEL_COUNT_OTHER)
  12264. return pc.Others;
  12265. else if (category == ScriptBaseClass.PARCEL_COUNT_SELECTED)
  12266. return pc.Selected;
  12267. else if (category == ScriptBaseClass.PARCEL_COUNT_TEMP)
  12268. return 0; // counts not implemented yet
  12269. }
  12270. return 0;
  12271. }
  12272. public LSL_List llGetParcelPrimOwners(LSL_Vector pos)
  12273. {
  12274. m_host.AddScriptLPS(1);
  12275. LandObject land = (LandObject)World.LandChannel.GetLandObject((float)pos.x, (float)pos.y);
  12276. LSL_List ret = new LSL_List();
  12277. if (land != null)
  12278. {
  12279. foreach (KeyValuePair<UUID, int> detectedParams in land.GetLandObjectOwners())
  12280. {
  12281. ret.Add(new LSL_String(detectedParams.Key.ToString()));
  12282. ret.Add(new LSL_Integer(detectedParams.Value));
  12283. }
  12284. }
  12285. ScriptSleep(m_sleepMsOnGetParcelPrimOwners);
  12286. return ret;
  12287. }
  12288. public LSL_Integer llGetObjectPrimCount(LSL_Key object_id)
  12289. {
  12290. m_host.AddScriptLPS(1);
  12291. UUID id;
  12292. if(!UUID.TryParse(object_id, out id))
  12293. return 0;
  12294. SceneObjectPart part = World.GetSceneObjectPart(id);
  12295. if (part == null)
  12296. return 0;
  12297. return part.ParentGroup.PrimCount;
  12298. }
  12299. public LSL_Integer llGetParcelMaxPrims(LSL_Vector pos, int sim_wide)
  12300. {
  12301. m_host.AddScriptLPS(1);
  12302. ILandObject lo = World.LandChannel.GetLandObject((float)pos.x, (float)pos.y);
  12303. if (lo == null)
  12304. return 0;
  12305. if (sim_wide != 0)
  12306. return lo.GetSimulatorMaxPrimCount();
  12307. else
  12308. return lo.GetParcelMaxPrimCount();
  12309. }
  12310. public LSL_List llGetParcelDetails(LSL_Vector pos, LSL_List param)
  12311. {
  12312. m_host.AddScriptLPS(1);
  12313. LandData land = World.GetLandData(pos);
  12314. if (land == null)
  12315. {
  12316. return new LSL_List(0);
  12317. }
  12318. LSL_List ret = new LSL_List();
  12319. foreach (object o in param.Data)
  12320. {
  12321. switch (o.ToString())
  12322. {
  12323. case "0":
  12324. ret.Add(new LSL_String(land.Name));
  12325. break;
  12326. case "1":
  12327. ret.Add(new LSL_String(land.Description));
  12328. break;
  12329. case "2":
  12330. ret.Add(new LSL_Key(land.OwnerID.ToString()));
  12331. break;
  12332. case "3":
  12333. ret.Add(new LSL_Key(land.GroupID.ToString()));
  12334. break;
  12335. case "4":
  12336. ret.Add(new LSL_Integer(land.Area));
  12337. break;
  12338. case "5":
  12339. ret.Add(new LSL_Key(land.GlobalID.ToString()));
  12340. break;
  12341. default:
  12342. ret.Add(new LSL_Integer(0));
  12343. break;
  12344. }
  12345. }
  12346. return ret;
  12347. }
  12348. public LSL_String llStringTrim(LSL_String src, LSL_Integer type)
  12349. {
  12350. m_host.AddScriptLPS(1);
  12351. if (type == (int)ScriptBaseClass.STRING_TRIM_HEAD) { return ((string)src).TrimStart(); }
  12352. if (type == (int)ScriptBaseClass.STRING_TRIM_TAIL) { return ((string)src).TrimEnd(); }
  12353. if (type == (int)ScriptBaseClass.STRING_TRIM) { return ((string)src).Trim(); }
  12354. return src;
  12355. }
  12356. public LSL_List llGetObjectDetails(LSL_Key id, LSL_List args)
  12357. {
  12358. m_host.AddScriptLPS(1);
  12359. LSL_List ret = new LSL_List();
  12360. UUID key = new UUID();
  12361. if (!UUID.TryParse(id, out key))
  12362. return ret;
  12363. ScenePresence av = World.GetScenePresence(key);
  12364. if (av != null)
  12365. {
  12366. foreach (object o in args.Data)
  12367. {
  12368. switch (int.Parse(o.ToString()))
  12369. {
  12370. case ScriptBaseClass.OBJECT_NAME:
  12371. ret.Add(new LSL_String(av.Firstname + " " + av.Lastname));
  12372. break;
  12373. case ScriptBaseClass.OBJECT_DESC:
  12374. ret.Add(new LSL_String(""));
  12375. break;
  12376. case ScriptBaseClass.OBJECT_POS:
  12377. Vector3 avpos;
  12378. if (av.ParentID != 0 && av.ParentPart != null &&
  12379. av.ParentPart.ParentGroup != null && av.ParentPart.ParentGroup.RootPart != null )
  12380. {
  12381. avpos = av.OffsetPosition;
  12382. if(!av.LegacySitOffsets)
  12383. {
  12384. Vector3 sitOffset = (Zrot(av.Rotation)) * (av.Appearance.AvatarHeight * 0.02638f *2.0f);
  12385. avpos -= sitOffset;
  12386. }
  12387. SceneObjectPart sitRoot = av.ParentPart.ParentGroup.RootPart;
  12388. avpos = sitRoot.GetWorldPosition() + avpos * sitRoot.GetWorldRotation();
  12389. }
  12390. else
  12391. avpos = av.AbsolutePosition;
  12392. ret.Add(new LSL_Vector((double)avpos.X, (double)avpos.Y, (double)avpos.Z));
  12393. break;
  12394. case ScriptBaseClass.OBJECT_ROT:
  12395. Quaternion avrot = av.GetWorldRotation();
  12396. ret.Add(new LSL_Rotation(avrot));
  12397. break;
  12398. case ScriptBaseClass.OBJECT_VELOCITY:
  12399. Vector3 avvel = av.GetWorldVelocity();
  12400. ret.Add(new LSL_Vector((double)avvel.X, (double)avvel.Y, (double)avvel.Z));
  12401. break;
  12402. case ScriptBaseClass.OBJECT_OWNER:
  12403. ret.Add(new LSL_Key((string)id));
  12404. break;
  12405. case ScriptBaseClass.OBJECT_GROUP:
  12406. ret.Add(new LSL_String(UUID.Zero.ToString()));
  12407. break;
  12408. case ScriptBaseClass.OBJECT_CREATOR:
  12409. ret.Add(new LSL_Key(UUID.Zero.ToString()));
  12410. break;
  12411. // For the following 8 see the Object version below
  12412. case ScriptBaseClass.OBJECT_RUNNING_SCRIPT_COUNT:
  12413. ret.Add(new LSL_Integer(av.RunningScriptCount()));
  12414. break;
  12415. case ScriptBaseClass.OBJECT_TOTAL_SCRIPT_COUNT:
  12416. ret.Add(new LSL_Integer(av.ScriptCount()));
  12417. break;
  12418. case ScriptBaseClass.OBJECT_SCRIPT_MEMORY:
  12419. ret.Add(new LSL_Integer(av.RunningScriptCount() * 16384));
  12420. break;
  12421. case ScriptBaseClass.OBJECT_SCRIPT_TIME:
  12422. ret.Add(new LSL_Float(av.ScriptExecutionTime() / 1000.0f));
  12423. break;
  12424. case ScriptBaseClass.OBJECT_PRIM_EQUIVALENCE:
  12425. ret.Add(new LSL_Integer(1));
  12426. break;
  12427. case ScriptBaseClass.OBJECT_SERVER_COST:
  12428. ret.Add(new LSL_Float(0));
  12429. break;
  12430. case ScriptBaseClass.OBJECT_STREAMING_COST:
  12431. ret.Add(new LSL_Float(0));
  12432. break;
  12433. case ScriptBaseClass.OBJECT_PHYSICS_COST:
  12434. ret.Add(new LSL_Float(0));
  12435. break;
  12436. case ScriptBaseClass.OBJECT_CHARACTER_TIME: // Pathfinding
  12437. ret.Add(new LSL_Float(0));
  12438. break;
  12439. case ScriptBaseClass.OBJECT_ROOT:
  12440. SceneObjectPart p = av.ParentPart;
  12441. if (p != null)
  12442. {
  12443. ret.Add(new LSL_String(p.ParentGroup.RootPart.UUID.ToString()));
  12444. }
  12445. else
  12446. {
  12447. ret.Add(new LSL_Key((string)id));
  12448. }
  12449. break;
  12450. case ScriptBaseClass.OBJECT_ATTACHED_POINT:
  12451. ret.Add(new LSL_Integer(0));
  12452. break;
  12453. case ScriptBaseClass.OBJECT_PATHFINDING_TYPE: // Pathfinding
  12454. ret.Add(new LSL_Integer(ScriptBaseClass.OPT_AVATAR));
  12455. break;
  12456. case ScriptBaseClass.OBJECT_PHYSICS:
  12457. ret.Add(new LSL_Integer(0));
  12458. break;
  12459. case ScriptBaseClass.OBJECT_PHANTOM:
  12460. ret.Add(new LSL_Integer(0));
  12461. break;
  12462. case ScriptBaseClass.OBJECT_TEMP_ON_REZ:
  12463. ret.Add(new LSL_Integer(0));
  12464. break;
  12465. case ScriptBaseClass.OBJECT_RENDER_WEIGHT:
  12466. ret.Add(new LSL_Integer(-1));
  12467. break;
  12468. case ScriptBaseClass.OBJECT_HOVER_HEIGHT:
  12469. ret.Add(new LSL_Float(0));
  12470. break;
  12471. case ScriptBaseClass.OBJECT_BODY_SHAPE_TYPE:
  12472. LSL_Float shapeType;
  12473. if (av.Appearance.VisualParams[(int)AvatarAppearance.VPElement.SHAPE_MALE] != 0)
  12474. shapeType = new LSL_Float(1);
  12475. else
  12476. shapeType = new LSL_Float(0);
  12477. ret.Add(shapeType);
  12478. break;
  12479. case ScriptBaseClass.OBJECT_LAST_OWNER_ID:
  12480. ret.Add(new LSL_Key(ScriptBaseClass.NULL_KEY));
  12481. break;
  12482. case ScriptBaseClass.OBJECT_CLICK_ACTION:
  12483. ret.Add(new LSL_Integer(0));
  12484. break;
  12485. case ScriptBaseClass.OBJECT_OMEGA:
  12486. ret.Add(new LSL_Vector(Vector3.Zero));
  12487. break;
  12488. case ScriptBaseClass.OBJECT_PRIM_COUNT:
  12489. List<SceneObjectGroup> Attachments = av.GetAttachments();
  12490. int count = 0;
  12491. try
  12492. {
  12493. foreach (SceneObjectGroup Attachment in Attachments)
  12494. count += Attachment.PrimCount;
  12495. } catch { };
  12496. ret.Add(new LSL_Integer(count));
  12497. break;
  12498. case ScriptBaseClass.OBJECT_TOTAL_INVENTORY_COUNT:
  12499. List<SceneObjectGroup> invAttachments = av.GetAttachments();
  12500. int invcount = 0;
  12501. try
  12502. {
  12503. foreach (SceneObjectGroup Attachment in invAttachments)
  12504. {
  12505. SceneObjectPart[] parts = Attachment.Parts;
  12506. int nparts = parts.Count();
  12507. for(int i = 0; i < nparts; i++)
  12508. invcount += parts[i].Inventory.Count;
  12509. }
  12510. } catch { };
  12511. ret.Add(new LSL_Integer(invcount));
  12512. break;
  12513. case ScriptBaseClass.OBJECT_REZZER_KEY:
  12514. ret.Add(new LSL_Key((string)id));
  12515. break;
  12516. case ScriptBaseClass.OBJECT_GROUP_TAG:
  12517. ret.Add(new LSL_String(av.Grouptitle));
  12518. break;
  12519. case ScriptBaseClass.OBJECT_TEMP_ATTACHED:
  12520. ret.Add(new LSL_Integer(0));
  12521. break;
  12522. default:
  12523. // Invalid or unhandled constant.
  12524. ret.Add(new LSL_Integer(ScriptBaseClass.OBJECT_UNKNOWN_DETAIL));
  12525. break;
  12526. }
  12527. }
  12528. return ret;
  12529. }
  12530. SceneObjectPart obj = World.GetSceneObjectPart(key);
  12531. if (obj != null)
  12532. {
  12533. foreach (object o in args.Data)
  12534. {
  12535. switch (int.Parse(o.ToString()))
  12536. {
  12537. case ScriptBaseClass.OBJECT_NAME:
  12538. ret.Add(new LSL_String(obj.Name));
  12539. break;
  12540. case ScriptBaseClass.OBJECT_DESC:
  12541. ret.Add(new LSL_String(obj.Description));
  12542. break;
  12543. case ScriptBaseClass.OBJECT_POS:
  12544. Vector3 opos = obj.AbsolutePosition;
  12545. ret.Add(new LSL_Vector(opos.X, opos.Y, opos.Z));
  12546. break;
  12547. case ScriptBaseClass.OBJECT_ROT:
  12548. Quaternion rot = Quaternion.Identity;
  12549. if (obj.ParentGroup.IsAttachment)
  12550. {
  12551. ScenePresence sp = World.GetScenePresence(obj.ParentGroup.AttachedAvatar);
  12552. if (sp != null)
  12553. rot = sp.GetWorldRotation();
  12554. }
  12555. else
  12556. {
  12557. if (obj.ParentGroup.RootPart == obj)
  12558. rot = obj.ParentGroup.GroupRotation;
  12559. else
  12560. rot = obj.GetWorldRotation();
  12561. }
  12562. LSL_Rotation objrot = new LSL_Rotation(rot);
  12563. ret.Add(objrot);
  12564. break;
  12565. case ScriptBaseClass.OBJECT_VELOCITY:
  12566. Vector3 vel = Vector3.Zero;
  12567. if (obj.ParentGroup.IsAttachment)
  12568. {
  12569. ScenePresence sp = World.GetScenePresence(obj.ParentGroup.AttachedAvatar);
  12570. if (sp != null)
  12571. vel = sp.GetWorldVelocity();
  12572. }
  12573. else
  12574. {
  12575. vel = obj.Velocity;
  12576. }
  12577. ret.Add(vel);
  12578. break;
  12579. case ScriptBaseClass.OBJECT_OWNER:
  12580. ret.Add(new LSL_String(obj.OwnerID.ToString()));
  12581. break;
  12582. case ScriptBaseClass.OBJECT_GROUP:
  12583. ret.Add(new LSL_String(obj.GroupID.ToString()));
  12584. break;
  12585. case ScriptBaseClass.OBJECT_CREATOR:
  12586. ret.Add(new LSL_String(obj.CreatorID.ToString()));
  12587. break;
  12588. case ScriptBaseClass.OBJECT_RUNNING_SCRIPT_COUNT:
  12589. ret.Add(new LSL_Integer(obj.ParentGroup.RunningScriptCount()));
  12590. break;
  12591. case ScriptBaseClass.OBJECT_TOTAL_SCRIPT_COUNT:
  12592. ret.Add(new LSL_Integer(obj.ParentGroup.ScriptCount()));
  12593. break;
  12594. case ScriptBaseClass.OBJECT_SCRIPT_MEMORY:
  12595. // The value returned in SL for mono scripts is 65536 * number of active scripts
  12596. // and 16384 * number of active scripts for LSO. since llGetFreememory
  12597. // is coded to give the LSO value use it here
  12598. ret.Add(new LSL_Integer(obj.ParentGroup.RunningScriptCount() * 16384));
  12599. break;
  12600. case ScriptBaseClass.OBJECT_SCRIPT_TIME:
  12601. // Average cpu time in seconds per simulator frame expended on all scripts in the object
  12602. ret.Add(new LSL_Float(obj.ParentGroup.ScriptExecutionTime() / 1000.0f));
  12603. break;
  12604. case ScriptBaseClass.OBJECT_PRIM_EQUIVALENCE:
  12605. // according to the SL wiki A prim or linkset will have prim
  12606. // equivalent of the number of prims in a linkset if it does not
  12607. // contain a mesh anywhere in the link set or is not a normal prim
  12608. // The value returned in SL for normal prims is prim count
  12609. ret.Add(new LSL_Integer(obj.ParentGroup.PrimCount));
  12610. break;
  12611. // costs below may need to be diferent for root parts, need to check
  12612. case ScriptBaseClass.OBJECT_SERVER_COST:
  12613. // The linden calculation is here
  12614. // http://wiki.secondlife.com/wiki/Mesh/Mesh_Server_Weight
  12615. // The value returned in SL for normal prims looks like the prim count
  12616. ret.Add(new LSL_Float(0));
  12617. break;
  12618. case ScriptBaseClass.OBJECT_STREAMING_COST:
  12619. // The value returned in SL for normal prims is prim count * 0.06
  12620. ret.Add(new LSL_Float(obj.StreamingCost));
  12621. break;
  12622. case ScriptBaseClass.OBJECT_PHYSICS_COST:
  12623. // The value returned in SL for normal prims is prim count
  12624. ret.Add(new LSL_Float(obj.PhysicsCost));
  12625. break;
  12626. case ScriptBaseClass.OBJECT_CHARACTER_TIME: // Pathfinding
  12627. ret.Add(new LSL_Float(0));
  12628. break;
  12629. case ScriptBaseClass.OBJECT_ROOT:
  12630. ret.Add(new LSL_String(obj.ParentGroup.RootPart.UUID.ToString()));
  12631. break;
  12632. case ScriptBaseClass.OBJECT_ATTACHED_POINT:
  12633. ret.Add(new LSL_Integer(obj.ParentGroup.AttachmentPoint));
  12634. break;
  12635. case ScriptBaseClass.OBJECT_PATHFINDING_TYPE:
  12636. byte pcode = obj.Shape.PCode;
  12637. if (obj.ParentGroup.AttachmentPoint != 0
  12638. || pcode == (byte)PCode.Grass
  12639. || pcode == (byte)PCode.Tree
  12640. || pcode == (byte)PCode.NewTree)
  12641. {
  12642. ret.Add(new LSL_Integer(ScriptBaseClass.OPT_OTHER));
  12643. }
  12644. else
  12645. {
  12646. ret.Add(new LSL_Integer(ScriptBaseClass.OPT_LEGACY_LINKSET));
  12647. }
  12648. break;
  12649. case ScriptBaseClass.OBJECT_PHYSICS:
  12650. if (obj.ParentGroup.AttachmentPoint != 0)
  12651. {
  12652. ret.Add(new LSL_Integer(0)); // Always false if attached
  12653. }
  12654. else
  12655. {
  12656. ret.Add(new LSL_Integer(obj.ParentGroup.UsesPhysics ? 1 : 0));
  12657. }
  12658. break;
  12659. case ScriptBaseClass.OBJECT_PHANTOM:
  12660. if (obj.ParentGroup.AttachmentPoint != 0)
  12661. {
  12662. ret.Add(new LSL_Integer(0)); // Always false if attached
  12663. }
  12664. else
  12665. {
  12666. ret.Add(new LSL_Integer(obj.ParentGroup.IsPhantom ? 1 : 0));
  12667. }
  12668. break;
  12669. case ScriptBaseClass.OBJECT_TEMP_ON_REZ:
  12670. ret.Add(new LSL_Integer(obj.ParentGroup.IsTemporary ? 1 : 0));
  12671. break;
  12672. case ScriptBaseClass.OBJECT_RENDER_WEIGHT:
  12673. ret.Add(new LSL_Integer(0));
  12674. break;
  12675. case ScriptBaseClass.OBJECT_HOVER_HEIGHT:
  12676. ret.Add(new LSL_Float(0));
  12677. break;
  12678. case ScriptBaseClass.OBJECT_BODY_SHAPE_TYPE:
  12679. ret.Add(new LSL_Float(-1));
  12680. break;
  12681. case ScriptBaseClass.OBJECT_LAST_OWNER_ID:
  12682. ret.Add(new LSL_Key(obj.ParentGroup.LastOwnerID.ToString()));
  12683. break;
  12684. case ScriptBaseClass.OBJECT_CLICK_ACTION:
  12685. ret.Add(new LSL_Integer(obj.ClickAction));
  12686. break;
  12687. case ScriptBaseClass.OBJECT_OMEGA:
  12688. ret.Add(new LSL_Vector(obj.AngularVelocity));
  12689. break;
  12690. case ScriptBaseClass.OBJECT_PRIM_COUNT:
  12691. ret.Add(new LSL_Integer(obj.ParentGroup.PrimCount));
  12692. break;
  12693. case ScriptBaseClass.OBJECT_TOTAL_INVENTORY_COUNT:
  12694. SceneObjectPart[] parts = obj.ParentGroup.Parts;
  12695. int nparts = parts.Count();
  12696. int count = 0;
  12697. for(int i = 0; i < nparts; i++)
  12698. count += parts[i].Inventory.Count;
  12699. ret.Add(new LSL_Integer(count));
  12700. break;
  12701. case ScriptBaseClass.OBJECT_REZZER_KEY:
  12702. ret.Add(new LSL_Key(obj.ParentGroup.RezzerID.ToString()));
  12703. break;
  12704. case ScriptBaseClass.OBJECT_GROUP_TAG:
  12705. ret.Add(new LSL_String(String.Empty));
  12706. break;
  12707. case ScriptBaseClass.OBJECT_TEMP_ATTACHED:
  12708. if (obj.ParentGroup.AttachmentPoint != 0 && obj.ParentGroup.FromItemID == UUID.Zero)
  12709. {
  12710. ret.Add(new LSL_Integer(1));
  12711. }
  12712. else
  12713. {
  12714. ret.Add(new LSL_Integer(0));
  12715. }
  12716. break;
  12717. default:
  12718. // Invalid or unhandled constant.
  12719. ret.Add(new LSL_Integer(ScriptBaseClass.OBJECT_UNKNOWN_DETAIL));
  12720. break;
  12721. }
  12722. }
  12723. }
  12724. return ret;
  12725. }
  12726. internal UUID GetScriptByName(string name)
  12727. {
  12728. TaskInventoryItem item = m_host.Inventory.GetInventoryItem(name);
  12729. if (item == null || item.Type != 10)
  12730. return UUID.Zero;
  12731. return item.ItemID;
  12732. }
  12733. /// <summary>
  12734. /// Reports the script error in the viewer's Script Warning/Error dialog and shouts it on the debug channel.
  12735. /// </summary>
  12736. /// <param name="command">The name of the command that generated the error.</param>
  12737. /// <param name="message">The error message to report to the user.</param>
  12738. internal void Error(string command, string message)
  12739. {
  12740. string text = command + ": " + message;
  12741. if (text.Length > 1023)
  12742. {
  12743. text = text.Substring(0, 1023);
  12744. }
  12745. World.SimChat(Utils.StringToBytes(text), ChatTypeEnum.DebugChannel, ScriptBaseClass.DEBUG_CHANNEL,
  12746. m_host.ParentGroup.RootPart.AbsolutePosition, m_host.Name, m_host.UUID, false);
  12747. IWorldComm wComm = m_ScriptEngine.World.RequestModuleInterface<IWorldComm>();
  12748. if (wComm != null)
  12749. {
  12750. wComm.DeliverMessage(ChatTypeEnum.Shout, ScriptBaseClass.DEBUG_CHANNEL, m_host.Name, m_host.UUID, text);
  12751. }
  12752. }
  12753. /// <summary>
  12754. /// Reports that the command is not implemented as a script error.
  12755. /// </summary>
  12756. /// <param name="command">The name of the command that is not implemented.</param>
  12757. /// <param name="message">Additional information to report to the user. (Optional)</param>
  12758. internal void NotImplemented(string command, string message = "")
  12759. {
  12760. if (throwErrorOnNotImplemented)
  12761. {
  12762. if (message != "")
  12763. {
  12764. message = " - " + message;
  12765. }
  12766. throw new NotImplementedException("Command not implemented: " + command + message);
  12767. }
  12768. else
  12769. {
  12770. string text = "Command not implemented";
  12771. if (message != "")
  12772. {
  12773. text = text + " - " + message;
  12774. }
  12775. Error(command, text);
  12776. }
  12777. }
  12778. /// <summary>
  12779. /// Reports that the command is deprecated as a script error.
  12780. /// </summary>
  12781. /// <param name="command">The name of the command that is deprecated.</param>
  12782. /// <param name="message">Additional information to report to the user. (Optional)</param>
  12783. internal void Deprecated(string command, string message = "")
  12784. {
  12785. string text = "Command deprecated";
  12786. if (message != "")
  12787. {
  12788. text = text + " - " + message;
  12789. }
  12790. Error(command, text);
  12791. }
  12792. public delegate void AssetRequestCallback(UUID assetID, AssetBase asset);
  12793. protected void WithNotecard(UUID assetID, AssetRequestCallback cb)
  12794. {
  12795. World.AssetService.Get(assetID.ToString(), this,
  12796. delegate(string i, object sender, AssetBase a)
  12797. {
  12798. UUID uuid = UUID.Zero;
  12799. UUID.TryParse(i, out uuid);
  12800. cb(uuid, a);
  12801. });
  12802. }
  12803. public LSL_Key llGetNumberOfNotecardLines(string name)
  12804. {
  12805. m_host.AddScriptLPS(1);
  12806. UUID assetID = UUID.Zero;
  12807. if (!UUID.TryParse(name, out assetID))
  12808. {
  12809. TaskInventoryItem item = m_host.Inventory.GetInventoryItem(name);
  12810. if (item != null && item.Type == 7)
  12811. assetID = item.AssetID;
  12812. }
  12813. if (assetID == UUID.Zero)
  12814. {
  12815. // => complain loudly, as specified by the LSL docs
  12816. Error("llGetNumberOfNotecardLines", "Can't find notecard '" + name + "'");
  12817. return UUID.Zero.ToString();
  12818. }
  12819. string reqIdentifier = UUID.Random().ToString();
  12820. // was: UUID tid = tid = AsyncCommands.
  12821. UUID tid = AsyncCommands.DataserverPlugin.RegisterRequest(m_host.LocalId, m_item.ItemID, reqIdentifier);
  12822. if (NotecardCache.IsCached(assetID))
  12823. {
  12824. AsyncCommands.DataserverPlugin.DataserverReply(reqIdentifier, NotecardCache.GetLines(assetID).ToString());
  12825. ScriptSleep(m_sleepMsOnGetNumberOfNotecardLines);
  12826. return tid.ToString();
  12827. }
  12828. WithNotecard(assetID, delegate (UUID id, AssetBase a)
  12829. {
  12830. if (a == null || a.Type != 7)
  12831. {
  12832. Error("llGetNumberOfNotecardLines", "Can't find notecard '" + name + "'");
  12833. return;
  12834. }
  12835. NotecardCache.Cache(id, a.Data);
  12836. AsyncCommands.DataserverPlugin.DataserverReply(reqIdentifier, NotecardCache.GetLines(id).ToString());
  12837. });
  12838. ScriptSleep(m_sleepMsOnGetNumberOfNotecardLines);
  12839. return tid.ToString();
  12840. }
  12841. public LSL_Key llGetNotecardLine(string name, int line)
  12842. {
  12843. m_host.AddScriptLPS(1);
  12844. UUID assetID = UUID.Zero;
  12845. if (!UUID.TryParse(name, out assetID))
  12846. {
  12847. TaskInventoryItem item = m_host.Inventory.GetInventoryItem(name);
  12848. if (item != null && item.Type == 7)
  12849. assetID = item.AssetID;
  12850. }
  12851. if (assetID == UUID.Zero)
  12852. {
  12853. // => complain loudly, as specified by the LSL docs
  12854. Error("llGetNotecardLine", "Can't find notecard '" + name + "'");
  12855. return UUID.Zero.ToString();
  12856. }
  12857. string reqIdentifier = UUID.Random().ToString();
  12858. // was: UUID tid = tid = AsyncCommands.
  12859. UUID tid = AsyncCommands.DataserverPlugin.RegisterRequest(m_host.LocalId, m_item.ItemID, reqIdentifier);
  12860. if (NotecardCache.IsCached(assetID))
  12861. {
  12862. AsyncCommands.DataserverPlugin.DataserverReply(
  12863. reqIdentifier, NotecardCache.GetLine(assetID, line, m_notecardLineReadCharsMax));
  12864. ScriptSleep(m_sleepMsOnGetNotecardLine);
  12865. return tid.ToString();
  12866. }
  12867. WithNotecard(assetID, delegate (UUID id, AssetBase a)
  12868. {
  12869. if (a == null || a.Type != 7)
  12870. {
  12871. Error("llGetNotecardLine", "Can't find notecard '" + name + "'");
  12872. return;
  12873. }
  12874. //string data = Encoding.UTF8.GetString(a.Data);
  12875. //m_log.Debug(data);
  12876. NotecardCache.Cache(id, a.Data);
  12877. AsyncCommands.DataserverPlugin.DataserverReply(
  12878. reqIdentifier, NotecardCache.GetLine(assetID, line, m_notecardLineReadCharsMax));
  12879. });
  12880. ScriptSleep(m_sleepMsOnGetNotecardLine);
  12881. return tid.ToString();
  12882. }
  12883. public void SetPrimitiveParamsEx(LSL_Key prim, LSL_List rules, string originFunc)
  12884. {
  12885. UUID id;
  12886. if (!UUID.TryParse(prim, out id))
  12887. return;
  12888. SceneObjectPart obj = World.GetSceneObjectPart(id);
  12889. if (obj == null || obj.OwnerID != m_host.OwnerID)
  12890. return;
  12891. uint rulesParsed = 0;
  12892. LSL_List remaining = SetPrimParams(obj, rules, originFunc, ref rulesParsed);
  12893. while (remaining.Length > 2)
  12894. {
  12895. int linknumber;
  12896. try
  12897. {
  12898. linknumber = remaining.GetLSLIntegerItem(0);
  12899. }
  12900. catch (InvalidCastException)
  12901. {
  12902. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_LINK_TARGET parameter must be integer", rulesParsed));
  12903. return;
  12904. }
  12905. List<ISceneEntity> entities = GetLinkEntities(obj, linknumber);
  12906. if (entities.Count == 0)
  12907. break;
  12908. rules = remaining.GetSublist(1, -1);
  12909. foreach (ISceneEntity entity in entities)
  12910. {
  12911. if (entity is SceneObjectPart)
  12912. remaining = SetPrimParams((SceneObjectPart)entity, rules, originFunc, ref rulesParsed);
  12913. else
  12914. remaining = SetAgentParams((ScenePresence)entity, rules, originFunc, ref rulesParsed);
  12915. }
  12916. }
  12917. }
  12918. public LSL_List GetPrimitiveParamsEx(LSL_Key prim, LSL_List rules)
  12919. {
  12920. LSL_List result = new LSL_List();
  12921. UUID id;
  12922. if (!UUID.TryParse(prim, out id))
  12923. return result;
  12924. SceneObjectPart obj = World.GetSceneObjectPart(id);
  12925. if (obj == null || obj.OwnerID != m_host.OwnerID)
  12926. return result;
  12927. LSL_List remaining = GetPrimParams(obj, rules, ref result);
  12928. while (remaining.Length > 1)
  12929. {
  12930. int linknumber;
  12931. try
  12932. {
  12933. linknumber = remaining.GetLSLIntegerItem(0);
  12934. }
  12935. catch (InvalidCastException)
  12936. {
  12937. Error("", string.Format("Error PRIM_LINK_TARGET: parameter must be integer"));
  12938. return result;
  12939. }
  12940. List<ISceneEntity> entities = GetLinkEntities(obj, linknumber);
  12941. if (entities.Count == 0)
  12942. break;
  12943. rules = remaining.GetSublist(1, -1);
  12944. foreach (ISceneEntity entity in entities)
  12945. {
  12946. if (entity is SceneObjectPart)
  12947. remaining = GetPrimParams((SceneObjectPart)entity, rules, ref result);
  12948. else
  12949. remaining = GetPrimParams((ScenePresence)entity, rules, ref result);
  12950. }
  12951. }
  12952. return result;
  12953. }
  12954. public void print(string str)
  12955. {
  12956. // yes, this is a real LSL function. See: http://wiki.secondlife.com/wiki/Print
  12957. IOSSL_Api ossl = (IOSSL_Api)m_ScriptEngine.GetApi(m_item.ItemID, "OSSL");
  12958. if (ossl != null)
  12959. {
  12960. ossl.CheckThreatLevel(ThreatLevel.High, "print");
  12961. m_log.Info("LSL print():" + str);
  12962. }
  12963. }
  12964. public LSL_Integer llGetLinkNumberOfSides(LSL_Integer link)
  12965. {
  12966. List<SceneObjectPart> parts = GetLinkParts(link);
  12967. if (parts.Count < 1)
  12968. return 0;
  12969. return GetNumberOfSides(parts[0]);
  12970. }
  12971. private string Name2Username(string name)
  12972. {
  12973. string[] parts = name.Split(new char[] {' '});
  12974. if (parts.Length < 2)
  12975. return name.ToLower();
  12976. if (parts[1] == "Resident")
  12977. return parts[0].ToLower();
  12978. return name.Replace(" ", ".").ToLower();
  12979. }
  12980. public LSL_String llGetUsername(string id)
  12981. {
  12982. return Name2Username(llKey2Name(id));
  12983. }
  12984. public LSL_Key llRequestUsername(string id)
  12985. {
  12986. UUID rq = UUID.Random();
  12987. AsyncCommands.DataserverPlugin.RegisterRequest(m_host.LocalId, m_item.ItemID, rq.ToString());
  12988. AsyncCommands.DataserverPlugin.DataserverReply(rq.ToString(), Name2Username(llKey2Name(id)));
  12989. return rq.ToString();
  12990. }
  12991. public LSL_String llGetDisplayName(string id)
  12992. {
  12993. return llKey2Name(id);
  12994. }
  12995. public LSL_Key llRequestDisplayName(string id)
  12996. {
  12997. UUID rq = UUID.Random();
  12998. AsyncCommands.DataserverPlugin.RegisterRequest(m_host.LocalId, m_item.ItemID, rq.ToString());
  12999. AsyncCommands.DataserverPlugin.DataserverReply(rq.ToString(), llKey2Name(id));
  13000. return rq.ToString();
  13001. }
  13002. /*
  13003. private void SayShoutTimerElapsed(Object sender, ElapsedEventArgs args)
  13004. {
  13005. m_SayShoutCount = 0;
  13006. }
  13007. */
  13008. private struct Tri
  13009. {
  13010. public Vector3 p1;
  13011. public Vector3 p2;
  13012. public Vector3 p3;
  13013. }
  13014. private bool InBoundingBox(ScenePresence avatar, Vector3 point)
  13015. {
  13016. float height = avatar.Appearance.AvatarHeight;
  13017. Vector3 b1 = avatar.AbsolutePosition + new Vector3(-0.22f, -0.22f, -height/2);
  13018. Vector3 b2 = avatar.AbsolutePosition + new Vector3(0.22f, 0.22f, height/2);
  13019. if (point.X > b1.X && point.X < b2.X &&
  13020. point.Y > b1.Y && point.Y < b2.Y &&
  13021. point.Z > b1.Z && point.Z < b2.Z)
  13022. return true;
  13023. return false;
  13024. }
  13025. private ContactResult[] AvatarIntersection(Vector3 rayStart, Vector3 rayEnd, bool skipPhys)
  13026. {
  13027. List<ContactResult> contacts = new List<ContactResult>();
  13028. Vector3 ab = rayEnd - rayStart;
  13029. float ablen = ab.Length();
  13030. World.ForEachScenePresence(delegate(ScenePresence sp)
  13031. {
  13032. if(skipPhys && sp.PhysicsActor != null)
  13033. return;
  13034. Vector3 ac = sp.AbsolutePosition - rayStart;
  13035. double d = Math.Abs(Vector3.Mag(Vector3.Cross(ab, ac)) / ablen);
  13036. if (d > 1.5)
  13037. return;
  13038. double d2 = Vector3.Dot(Vector3.Negate(ab), ac);
  13039. if (d2 > 0)
  13040. return;
  13041. double dp = Math.Sqrt(Vector3.Mag(ac) * Vector3.Mag(ac) - d * d);
  13042. Vector3 p = rayStart + Vector3.Divide(Vector3.Multiply(ab, (float)dp), (float)Vector3.Mag(ab));
  13043. if (!InBoundingBox(sp, p))
  13044. return;
  13045. ContactResult result = new ContactResult ();
  13046. result.ConsumerID = sp.LocalId;
  13047. result.Depth = Vector3.Distance(rayStart, p);
  13048. result.Normal = Vector3.Zero;
  13049. result.Pos = p;
  13050. contacts.Add(result);
  13051. });
  13052. return contacts.ToArray();
  13053. }
  13054. private ContactResult[] ObjectIntersection(Vector3 rayStart, Vector3 rayEnd, bool includePhysical, bool includeNonPhysical, bool includePhantom)
  13055. {
  13056. Ray ray = new Ray(rayStart, Vector3.Normalize(rayEnd - rayStart));
  13057. List<ContactResult> contacts = new List<ContactResult>();
  13058. Vector3 ab = rayEnd - rayStart;
  13059. World.ForEachSOG(delegate(SceneObjectGroup group)
  13060. {
  13061. if (m_host.ParentGroup == group)
  13062. return;
  13063. if (group.IsAttachment)
  13064. return;
  13065. if (group.RootPart.PhysActor == null)
  13066. {
  13067. if (!includePhantom)
  13068. return;
  13069. }
  13070. else
  13071. {
  13072. if (group.RootPart.PhysActor.IsPhysical)
  13073. {
  13074. if (!includePhysical)
  13075. return;
  13076. }
  13077. else
  13078. {
  13079. if (!includeNonPhysical)
  13080. return;
  13081. }
  13082. }
  13083. // Find the radius ouside of which we don't even need to hit test
  13084. float minX;
  13085. float maxX;
  13086. float minY;
  13087. float maxY;
  13088. float minZ;
  13089. float maxZ;
  13090. float radius = 0.0f;
  13091. group.GetAxisAlignedBoundingBoxRaw(out minX, out maxX, out minY, out maxY, out minZ, out maxZ);
  13092. if (Math.Abs(minX) > radius)
  13093. radius = Math.Abs(minX);
  13094. if (Math.Abs(minY) > radius)
  13095. radius = Math.Abs(minY);
  13096. if (Math.Abs(minZ) > radius)
  13097. radius = Math.Abs(minZ);
  13098. if (Math.Abs(maxX) > radius)
  13099. radius = Math.Abs(maxX);
  13100. if (Math.Abs(maxY) > radius)
  13101. radius = Math.Abs(maxY);
  13102. if (Math.Abs(maxZ) > radius)
  13103. radius = Math.Abs(maxZ);
  13104. radius = radius*1.413f;
  13105. Vector3 ac = group.AbsolutePosition - rayStart;
  13106. // Vector3 bc = group.AbsolutePosition - rayEnd;
  13107. double d = Math.Abs(Vector3.Mag(Vector3.Cross(ab, ac)) / Vector3.Distance(rayStart, rayEnd));
  13108. // Too far off ray, don't bother
  13109. if (d > radius)
  13110. return;
  13111. // Behind ray, drop
  13112. double d2 = Vector3.Dot(Vector3.Negate(ab), ac);
  13113. if (d2 > 0)
  13114. return;
  13115. ray = new Ray(rayStart, Vector3.Normalize(rayEnd - rayStart));
  13116. EntityIntersection intersection = group.TestIntersection(ray, true, false);
  13117. // Miss.
  13118. if (!intersection.HitTF)
  13119. return;
  13120. Vector3 b1 = group.AbsolutePosition + new Vector3(minX, minY, minZ);
  13121. Vector3 b2 = group.AbsolutePosition + new Vector3(maxX, maxY, maxZ);
  13122. //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);
  13123. if (!(intersection.ipoint.X >= b1.X && intersection.ipoint.X <= b2.X &&
  13124. intersection.ipoint.Y >= b1.Y && intersection.ipoint.Y <= b2.Y &&
  13125. intersection.ipoint.Z >= b1.Z && intersection.ipoint.Z <= b2.Z))
  13126. return;
  13127. ContactResult result = new ContactResult ();
  13128. result.ConsumerID = group.LocalId;
  13129. // result.Depth = intersection.distance;
  13130. result.Normal = intersection.normal;
  13131. result.Pos = intersection.ipoint;
  13132. result.Depth = Vector3.Mag(rayStart - result.Pos);
  13133. contacts.Add(result);
  13134. });
  13135. return contacts.ToArray();
  13136. }
  13137. private ContactResult? GroundIntersection(Vector3 rayStart, Vector3 rayEnd)
  13138. {
  13139. double[,] heightfield = World.Heightmap.GetDoubles();
  13140. List<ContactResult> contacts = new List<ContactResult>();
  13141. double min = 2048.0;
  13142. double max = 0.0;
  13143. // Find the min and max of the heightfield
  13144. for (int x = 0 ; x < World.Heightmap.Width ; x++)
  13145. {
  13146. for (int y = 0 ; y < World.Heightmap.Height ; y++)
  13147. {
  13148. if (heightfield[x, y] > max)
  13149. max = heightfield[x, y];
  13150. if (heightfield[x, y] < min)
  13151. min = heightfield[x, y];
  13152. }
  13153. }
  13154. // A ray extends past rayEnd, but doesn't go back before
  13155. // rayStart. If the start is above the highest point of the ground
  13156. // and the ray goes up, we can't hit the ground. Ever.
  13157. if (rayStart.Z > max && rayEnd.Z >= rayStart.Z)
  13158. return null;
  13159. // Same for going down
  13160. if (rayStart.Z < min && rayEnd.Z <= rayStart.Z)
  13161. return null;
  13162. List<Tri> trilist = new List<Tri>();
  13163. // Create our triangle list
  13164. for (int x = 1 ; x < World.Heightmap.Width ; x++)
  13165. {
  13166. for (int y = 1 ; y < World.Heightmap.Height ; y++)
  13167. {
  13168. Tri t1 = new Tri();
  13169. Tri t2 = new Tri();
  13170. Vector3 p1 = new Vector3(x-1, y-1, (float)heightfield[x-1, y-1]);
  13171. Vector3 p2 = new Vector3(x, y-1, (float)heightfield[x, y-1]);
  13172. Vector3 p3 = new Vector3(x, y, (float)heightfield[x, y]);
  13173. Vector3 p4 = new Vector3(x-1, y, (float)heightfield[x-1, y]);
  13174. t1.p1 = p1;
  13175. t1.p2 = p2;
  13176. t1.p3 = p3;
  13177. t2.p1 = p3;
  13178. t2.p2 = p4;
  13179. t2.p3 = p1;
  13180. trilist.Add(t1);
  13181. trilist.Add(t2);
  13182. }
  13183. }
  13184. // Ray direction
  13185. Vector3 rayDirection = rayEnd - rayStart;
  13186. foreach (Tri t in trilist)
  13187. {
  13188. // Compute triangle plane normal and edges
  13189. Vector3 u = t.p2 - t.p1;
  13190. Vector3 v = t.p3 - t.p1;
  13191. Vector3 n = Vector3.Cross(u, v);
  13192. if (n == Vector3.Zero)
  13193. continue;
  13194. Vector3 w0 = rayStart - t.p1;
  13195. double a = -Vector3.Dot(n, w0);
  13196. double b = Vector3.Dot(n, rayDirection);
  13197. // Not intersecting the plane, or in plane (same thing)
  13198. // Ignoring this MAY cause the ground to not be detected
  13199. // sometimes
  13200. if (Math.Abs(b) < 0.000001)
  13201. continue;
  13202. double r = a / b;
  13203. // ray points away from plane
  13204. if (r < 0.0)
  13205. continue;
  13206. Vector3 ip = rayStart + Vector3.Multiply(rayDirection, (float)r);
  13207. float uu = Vector3.Dot(u, u);
  13208. float uv = Vector3.Dot(u, v);
  13209. float vv = Vector3.Dot(v, v);
  13210. Vector3 w = ip - t.p1;
  13211. float wu = Vector3.Dot(w, u);
  13212. float wv = Vector3.Dot(w, v);
  13213. float d = uv * uv - uu * vv;
  13214. float cs = (uv * wv - vv * wu) / d;
  13215. if (cs < 0 || cs > 1.0)
  13216. continue;
  13217. float ct = (uv * wu - uu * wv) / d;
  13218. if (ct < 0 || (cs + ct) > 1.0)
  13219. continue;
  13220. // Add contact point
  13221. ContactResult result = new ContactResult ();
  13222. result.ConsumerID = 0;
  13223. result.Depth = Vector3.Distance(rayStart, ip);
  13224. result.Normal = n;
  13225. result.Pos = ip;
  13226. contacts.Add(result);
  13227. }
  13228. if (contacts.Count == 0)
  13229. return null;
  13230. contacts.Sort(delegate(ContactResult a, ContactResult b)
  13231. {
  13232. return (int)(a.Depth - b.Depth);
  13233. });
  13234. return contacts[0];
  13235. }
  13236. /*
  13237. // not done:
  13238. private ContactResult[] testRay2NonPhysicalPhantom(Vector3 rayStart, Vector3 raydir, float raylenght)
  13239. {
  13240. ContactResult[] contacts = null;
  13241. World.ForEachSOG(delegate(SceneObjectGroup group)
  13242. {
  13243. if (m_host.ParentGroup == group)
  13244. return;
  13245. if (group.IsAttachment)
  13246. return;
  13247. if(group.RootPart.PhysActor != null)
  13248. return;
  13249. contacts = group.RayCastGroupPartsOBBNonPhysicalPhantom(rayStart, raydir, raylenght);
  13250. });
  13251. return contacts;
  13252. }
  13253. */
  13254. public LSL_List llCastRay(LSL_Vector start, LSL_Vector end, LSL_List options)
  13255. {
  13256. // Use llCastRay V3 if configured
  13257. if (m_useCastRayV3)
  13258. return llCastRayV3(start, end, options);
  13259. LSL_List list = new LSL_List();
  13260. m_host.AddScriptLPS(1);
  13261. Vector3 rayStart = start;
  13262. Vector3 rayEnd = end;
  13263. Vector3 dir = rayEnd - rayStart;
  13264. float dist = dir.Length();
  13265. int count = 1;
  13266. bool detectPhantom = false;
  13267. int dataFlags = 0;
  13268. int rejectTypes = 0;
  13269. for (int i = 0; i < options.Length; i += 2)
  13270. {
  13271. if (options.GetLSLIntegerItem(i) == ScriptBaseClass.RC_MAX_HITS)
  13272. count = options.GetLSLIntegerItem(i + 1);
  13273. else if (options.GetLSLIntegerItem(i) == ScriptBaseClass.RC_DETECT_PHANTOM)
  13274. detectPhantom = (options.GetLSLIntegerItem(i + 1) > 0);
  13275. else if (options.GetLSLIntegerItem(i) == ScriptBaseClass.RC_DATA_FLAGS)
  13276. dataFlags = options.GetLSLIntegerItem(i + 1);
  13277. else if (options.GetLSLIntegerItem(i) == ScriptBaseClass.RC_REJECT_TYPES)
  13278. rejectTypes = options.GetLSLIntegerItem(i + 1);
  13279. }
  13280. if (count > 16)
  13281. count = 16;
  13282. List<ContactResult> results = new List<ContactResult>();
  13283. bool checkTerrain = !((rejectTypes & ScriptBaseClass.RC_REJECT_LAND) == ScriptBaseClass.RC_REJECT_LAND);
  13284. bool checkAgents = !((rejectTypes & ScriptBaseClass.RC_REJECT_AGENTS) == ScriptBaseClass.RC_REJECT_AGENTS);
  13285. bool checkNonPhysical = !((rejectTypes & ScriptBaseClass.RC_REJECT_NONPHYSICAL) == ScriptBaseClass.RC_REJECT_NONPHYSICAL);
  13286. bool checkPhysical = !((rejectTypes & ScriptBaseClass.RC_REJECT_PHYSICAL) == ScriptBaseClass.RC_REJECT_PHYSICAL);
  13287. bool rejectHost = ((rejectTypes & ScriptBaseClass.RC_REJECT_HOST) != 0);
  13288. bool rejectHostGroup = ((rejectTypes & ScriptBaseClass.RC_REJECT_HOSTGROUP) != 0);
  13289. if (World.SupportsRayCastFiltered())
  13290. {
  13291. if (dist == 0)
  13292. return list;
  13293. RayFilterFlags rayfilter = RayFilterFlags.BackFaceCull;
  13294. if (checkTerrain)
  13295. rayfilter |= RayFilterFlags.land;
  13296. if (checkAgents)
  13297. rayfilter |= RayFilterFlags.agent;
  13298. if (checkPhysical)
  13299. rayfilter |= RayFilterFlags.physical;
  13300. if (checkNonPhysical)
  13301. rayfilter |= RayFilterFlags.nonphysical;
  13302. if (detectPhantom)
  13303. rayfilter |= RayFilterFlags.LSLPhantom;
  13304. Vector3 direction = dir * ( 1/dist);
  13305. if(rayfilter == 0)
  13306. {
  13307. list.Add(new LSL_Integer(0));
  13308. return list;
  13309. }
  13310. // get some more contacts to sort ???
  13311. int physcount = 4 * count;
  13312. if (physcount > 20)
  13313. physcount = 20;
  13314. object physresults;
  13315. physresults = World.RayCastFiltered(rayStart, direction, dist, physcount, rayfilter);
  13316. if (physresults == null)
  13317. {
  13318. // list.Add(new LSL_Integer(-3)); // timeout error
  13319. // return list;
  13320. results = new List<ContactResult>();
  13321. }
  13322. else
  13323. results = (List<ContactResult>)physresults;
  13324. // for now physics doesn't detect sitted avatars so do it outside physics
  13325. if (checkAgents)
  13326. {
  13327. ContactResult[] agentHits = AvatarIntersection(rayStart, rayEnd, true);
  13328. foreach (ContactResult r in agentHits)
  13329. results.Add(r);
  13330. }
  13331. // TODO: Replace this with a better solution. ObjectIntersection can only
  13332. // detect nonphysical phantoms. They are detected by virtue of being
  13333. // nonphysical (e.g. no PhysActor) so will not conflict with detecting
  13334. // physicsl phantoms as done by the physics scene
  13335. // We don't want anything else but phantoms here.
  13336. if (detectPhantom)
  13337. {
  13338. ContactResult[] objectHits = ObjectIntersection(rayStart, rayEnd, false, false, true);
  13339. foreach (ContactResult r in objectHits)
  13340. results.Add(r);
  13341. }
  13342. // Double check this because of current ODE distance problems
  13343. if (checkTerrain && dist > 60)
  13344. {
  13345. bool skipGroundCheck = false;
  13346. foreach (ContactResult c in results)
  13347. {
  13348. if (c.ConsumerID == 0) // Physics gave us a ground collision
  13349. skipGroundCheck = true;
  13350. }
  13351. if (!skipGroundCheck)
  13352. {
  13353. float tmp = dir.X * dir.X + dir.Y * dir.Y;
  13354. if(tmp > 2500)
  13355. {
  13356. ContactResult? groundContact = GroundIntersection(rayStart, rayEnd);
  13357. if (groundContact != null)
  13358. results.Add((ContactResult)groundContact);
  13359. }
  13360. }
  13361. }
  13362. }
  13363. else
  13364. {
  13365. if (checkAgents)
  13366. {
  13367. ContactResult[] agentHits = AvatarIntersection(rayStart, rayEnd, false);
  13368. foreach (ContactResult r in agentHits)
  13369. results.Add(r);
  13370. }
  13371. if (checkPhysical || checkNonPhysical || detectPhantom)
  13372. {
  13373. ContactResult[] objectHits = ObjectIntersection(rayStart, rayEnd, checkPhysical, checkNonPhysical, detectPhantom);
  13374. for (int iter = 0; iter < objectHits.Length; iter++)
  13375. {
  13376. // Redistance the Depth because the Scene RayCaster returns distance from center to make the rezzing code simpler.
  13377. objectHits[iter].Depth = Vector3.Distance(objectHits[iter].Pos, rayStart);
  13378. results.Add(objectHits[iter]);
  13379. }
  13380. }
  13381. if (checkTerrain)
  13382. {
  13383. ContactResult? groundContact = GroundIntersection(rayStart, rayEnd);
  13384. if (groundContact != null)
  13385. results.Add((ContactResult)groundContact);
  13386. }
  13387. }
  13388. results.Sort(delegate(ContactResult a, ContactResult b)
  13389. {
  13390. return a.Depth.CompareTo(b.Depth);
  13391. });
  13392. int values = 0;
  13393. SceneObjectGroup thisgrp = m_host.ParentGroup;
  13394. foreach (ContactResult result in results)
  13395. {
  13396. if (result.Depth > dist)
  13397. continue;
  13398. // physics ray can return colisions with host prim
  13399. if (rejectHost && m_host.LocalId == result.ConsumerID)
  13400. continue;
  13401. UUID itemID = UUID.Zero;
  13402. int linkNum = 0;
  13403. SceneObjectPart part = World.GetSceneObjectPart(result.ConsumerID);
  13404. // It's a prim!
  13405. if (part != null)
  13406. {
  13407. if (rejectHostGroup && part.ParentGroup == thisgrp)
  13408. continue;
  13409. if ((dataFlags & ScriptBaseClass.RC_GET_ROOT_KEY) == ScriptBaseClass.RC_GET_ROOT_KEY)
  13410. itemID = part.ParentGroup.UUID;
  13411. else
  13412. itemID = part.UUID;
  13413. linkNum = part.LinkNum;
  13414. }
  13415. else
  13416. {
  13417. ScenePresence sp = World.GetScenePresence(result.ConsumerID);
  13418. /// It it a boy? a girl?
  13419. if (sp != null)
  13420. itemID = sp.UUID;
  13421. }
  13422. list.Add(new LSL_String(itemID.ToString()));
  13423. list.Add(new LSL_String(result.Pos.ToString()));
  13424. if ((dataFlags & ScriptBaseClass.RC_GET_LINK_NUM) == ScriptBaseClass.RC_GET_LINK_NUM)
  13425. list.Add(new LSL_Integer(linkNum));
  13426. if ((dataFlags & ScriptBaseClass.RC_GET_NORMAL) == ScriptBaseClass.RC_GET_NORMAL)
  13427. list.Add(new LSL_Vector(result.Normal));
  13428. values++;
  13429. if (values >= count)
  13430. break;
  13431. }
  13432. list.Add(new LSL_Integer(values));
  13433. return list;
  13434. }
  13435. /// <summary>
  13436. /// Implementation of llCastRay similar to SL 2015-04-21.
  13437. /// http://wiki.secondlife.com/wiki/LlCastRay
  13438. /// Uses pure geometry, bounding shapes, meshing and no physics
  13439. /// for prims, sculpts, meshes, avatars and terrain.
  13440. /// Implements all flags, reject types and data flags.
  13441. /// Can handle both objects/groups and prims/parts, by config.
  13442. /// May sometimes be inaccurate owing to calculation precision,
  13443. /// meshing detail level and a bug in libopenmetaverse PrimMesher.
  13444. /// </summary>
  13445. public LSL_List llCastRayV3(LSL_Vector start, LSL_Vector end, LSL_List options)
  13446. {
  13447. m_host.AddScriptLPS(1);
  13448. LSL_List result = new LSL_List();
  13449. // Prepare throttle data
  13450. int calledMs = Environment.TickCount;
  13451. Stopwatch stopWatch = new Stopwatch();
  13452. stopWatch.Start();
  13453. UUID regionId = World.RegionInfo.RegionID;
  13454. UUID userId = UUID.Zero;
  13455. int msAvailable = 0;
  13456. // Throttle per owner when attachment or "vehicle" (sat upon)
  13457. if (m_host.ParentGroup.IsAttachment || m_host.ParentGroup.GetSittingAvatarsCount() > 0)
  13458. {
  13459. userId = m_host.OwnerID;
  13460. msAvailable = m_msPerAvatarInCastRay;
  13461. }
  13462. // Throttle per parcel when not attachment or vehicle
  13463. else
  13464. {
  13465. LandData land = World.GetLandData(m_host.GetWorldPosition());
  13466. if (land != null)
  13467. msAvailable = m_msPerRegionInCastRay * land.Area / 65536;
  13468. }
  13469. // Clamp for "oversized" parcels on varregions
  13470. if (msAvailable > m_msMaxInCastRay)
  13471. msAvailable = m_msMaxInCastRay;
  13472. // Check throttle data
  13473. int fromCalledMs = calledMs - m_msThrottleInCastRay;
  13474. lock (m_castRayCalls)
  13475. {
  13476. for (int i = m_castRayCalls.Count - 1; i >= 0; i--)
  13477. {
  13478. // Delete old calls from throttle data
  13479. if (m_castRayCalls[i].CalledMs < fromCalledMs)
  13480. m_castRayCalls.RemoveAt(i);
  13481. // Use current region (in multi-region sims)
  13482. else if (m_castRayCalls[i].RegionId == regionId)
  13483. {
  13484. // Reduce available time with recent calls
  13485. if (m_castRayCalls[i].UserId == userId)
  13486. msAvailable -= m_castRayCalls[i].UsedMs;
  13487. }
  13488. }
  13489. // Return failure if not enough available time
  13490. if (msAvailable < m_msMinInCastRay)
  13491. {
  13492. result.Add(new LSL_Integer(ScriptBaseClass.RCERR_CAST_TIME_EXCEEDED));
  13493. return result;
  13494. }
  13495. }
  13496. // Initialize
  13497. List<RayHit> rayHits = new List<RayHit>();
  13498. float tol = m_floatToleranceInCastRay;
  13499. Vector3 pos1Ray = start;
  13500. Vector3 pos2Ray = end;
  13501. // Get input options
  13502. int rejectTypes = 0;
  13503. int dataFlags = 0;
  13504. int maxHits = 1;
  13505. bool notdetectPhantom = true;
  13506. for (int i = 0; i < options.Length; i += 2)
  13507. {
  13508. if (options.GetLSLIntegerItem(i) == ScriptBaseClass.RC_REJECT_TYPES)
  13509. rejectTypes = options.GetLSLIntegerItem(i + 1);
  13510. else if (options.GetLSLIntegerItem(i) == ScriptBaseClass.RC_DATA_FLAGS)
  13511. dataFlags = options.GetLSLIntegerItem(i + 1);
  13512. else if (options.GetLSLIntegerItem(i) == ScriptBaseClass.RC_MAX_HITS)
  13513. maxHits = options.GetLSLIntegerItem(i + 1);
  13514. else if (options.GetLSLIntegerItem(i) == ScriptBaseClass.RC_DETECT_PHANTOM)
  13515. notdetectPhantom = (options.GetLSLIntegerItem(i + 1) == 0);
  13516. }
  13517. if (maxHits > m_maxHitsInCastRay)
  13518. maxHits = m_maxHitsInCastRay;
  13519. bool rejectAgents = ((rejectTypes & ScriptBaseClass.RC_REJECT_AGENTS) != 0);
  13520. bool rejectPhysical = ((rejectTypes & ScriptBaseClass.RC_REJECT_PHYSICAL) != 0);
  13521. bool rejectNonphysical = ((rejectTypes & ScriptBaseClass.RC_REJECT_NONPHYSICAL) != 0);
  13522. bool rejectLand = ((rejectTypes & ScriptBaseClass.RC_REJECT_LAND) != 0);
  13523. bool getNormal = ((dataFlags & ScriptBaseClass.RC_GET_NORMAL) != 0);
  13524. bool getRootKey = ((dataFlags & ScriptBaseClass.RC_GET_ROOT_KEY) != 0);
  13525. bool getLinkNum = ((dataFlags & ScriptBaseClass.RC_GET_LINK_NUM) != 0);
  13526. // Calculate some basic parameters
  13527. Vector3 vecRay = pos2Ray - pos1Ray;
  13528. float rayLength = vecRay.Length();
  13529. // Try to get a mesher and return failure if none, degenerate ray, or max 0 hits
  13530. IRendering primMesher = null;
  13531. List<string> renderers = RenderingLoader.ListRenderers(Util.ExecutingDirectory());
  13532. if (renderers.Count < 1 || rayLength < tol || m_maxHitsInCastRay < 1)
  13533. {
  13534. result.Add(new LSL_Integer(ScriptBaseClass.RCERR_UNKNOWN));
  13535. return result;
  13536. }
  13537. primMesher = RenderingLoader.LoadRenderer(renderers[0]);
  13538. // Iterate over all objects/groups and prims/parts in region
  13539. World.ForEachSOG(
  13540. delegate(SceneObjectGroup group)
  13541. {
  13542. if(group.IsDeleted || group.RootPart == null)
  13543. return;
  13544. // Check group filters unless part filters are configured
  13545. bool isPhysical = (group.RootPart.PhysActor != null && group.RootPart.PhysActor.IsPhysical);
  13546. bool isNonphysical = !isPhysical;
  13547. bool isPhantom = group.IsPhantom || group.IsVolumeDetect;
  13548. bool isAttachment = group.IsAttachment;
  13549. if (isPhysical && rejectPhysical)
  13550. return;
  13551. if (isNonphysical && rejectNonphysical)
  13552. return;
  13553. if (isPhantom && notdetectPhantom)
  13554. return;
  13555. if (isAttachment && !m_doAttachmentsInCastRay)
  13556. return;
  13557. // Parse object/group if passed filters
  13558. // Iterate over all prims/parts in object/group
  13559. foreach(SceneObjectPart part in group.Parts)
  13560. {
  13561. // ignore PhysicsShapeType.None as physics engines do
  13562. // or we will get into trouble in future
  13563. if(part.PhysicsShapeType == (byte)PhysicsShapeType.None)
  13564. continue;
  13565. isPhysical = (part.PhysActor != null && part.PhysActor.IsPhysical);
  13566. isNonphysical = !isPhysical;
  13567. isPhantom = ((part.Flags & PrimFlags.Phantom) != 0) ||
  13568. (part.VolumeDetectActive);
  13569. if (isPhysical && rejectPhysical)
  13570. continue;
  13571. if (isNonphysical && rejectNonphysical)
  13572. continue;
  13573. if (isPhantom && notdetectPhantom)
  13574. continue;
  13575. // Parse prim/part and project ray if passed filters
  13576. Vector3 scalePart = part.Scale;
  13577. Vector3 posPart = part.GetWorldPosition();
  13578. Quaternion rotPart = part.GetWorldRotation();
  13579. Quaternion rotPartInv = Quaternion.Inverse(rotPart);
  13580. Vector3 pos1RayProj = ((pos1Ray - posPart) * rotPartInv) / scalePart;
  13581. Vector3 pos2RayProj = ((pos2Ray - posPart) * rotPartInv) / scalePart;
  13582. // Filter parts by shape bounding boxes
  13583. Vector3 shapeBoxMax = new Vector3(0.5f, 0.5f, 0.5f);
  13584. if (!part.Shape.SculptEntry)
  13585. shapeBoxMax = shapeBoxMax * (new Vector3(m_primSafetyCoeffX, m_primSafetyCoeffY, m_primSafetyCoeffZ));
  13586. shapeBoxMax = shapeBoxMax + (new Vector3(tol, tol, tol));
  13587. if (RayIntersectsShapeBox(pos1RayProj, pos2RayProj, shapeBoxMax))
  13588. {
  13589. // Prepare data needed to check for ray hits
  13590. RayTrans rayTrans = new RayTrans();
  13591. rayTrans.PartId = part.UUID;
  13592. rayTrans.GroupId = part.ParentGroup.UUID;
  13593. rayTrans.Link = group.PrimCount > 1 ? part.LinkNum : 0;
  13594. rayTrans.ScalePart = scalePart;
  13595. rayTrans.PositionPart = posPart;
  13596. rayTrans.RotationPart = rotPart;
  13597. rayTrans.ShapeNeedsEnds = true;
  13598. rayTrans.Position1Ray = pos1Ray;
  13599. rayTrans.Position1RayProj = pos1RayProj;
  13600. rayTrans.VectorRayProj = pos2RayProj - pos1RayProj;
  13601. // Get detail level depending on type
  13602. int lod = 0;
  13603. // Mesh detail level
  13604. if (part.Shape.SculptEntry && part.Shape.SculptType == (byte)SculptType.Mesh)
  13605. lod = (int)m_meshLodInCastRay;
  13606. // Sculpt detail level
  13607. else if (part.Shape.SculptEntry && part.Shape.SculptType == (byte)SculptType.Mesh)
  13608. lod = (int)m_sculptLodInCastRay;
  13609. // Shape detail level
  13610. else if (!part.Shape.SculptEntry)
  13611. lod = (int)m_primLodInCastRay;
  13612. // Try to get cached mesh if configured
  13613. ulong meshKey = 0;
  13614. FacetedMesh mesh = null;
  13615. if (m_useMeshCacheInCastRay)
  13616. {
  13617. meshKey = part.Shape.GetMeshKey(Vector3.One, (float)(4 << lod));
  13618. lock (m_cachedMeshes)
  13619. {
  13620. m_cachedMeshes.TryGetValue(meshKey, out mesh);
  13621. }
  13622. }
  13623. // Create mesh if no cached mesh
  13624. if (mesh == null)
  13625. {
  13626. // Make an OMV prim to be able to mesh part
  13627. Primitive omvPrim = part.Shape.ToOmvPrimitive(posPart, rotPart);
  13628. byte[] sculptAsset = null;
  13629. if (omvPrim.Sculpt != null)
  13630. sculptAsset = World.AssetService.GetData(omvPrim.Sculpt.SculptTexture.ToString());
  13631. // When part is mesh, get mesh
  13632. if (omvPrim.Sculpt != null && omvPrim.Sculpt.Type == SculptType.Mesh && sculptAsset != null)
  13633. {
  13634. AssetMesh meshAsset = new AssetMesh(omvPrim.Sculpt.SculptTexture, sculptAsset);
  13635. FacetedMesh.TryDecodeFromAsset(omvPrim, meshAsset, m_meshLodInCastRay, out mesh);
  13636. meshAsset = null;
  13637. }
  13638. // When part is sculpt, create mesh
  13639. // Quirk: Generated sculpt mesh is about 2.8% smaller in X and Y than visual sculpt.
  13640. else if (omvPrim.Sculpt != null && omvPrim.Sculpt.Type != SculptType.Mesh && sculptAsset != null)
  13641. {
  13642. IJ2KDecoder imgDecoder = World.RequestModuleInterface<IJ2KDecoder>();
  13643. if (imgDecoder != null)
  13644. {
  13645. Image sculpt = imgDecoder.DecodeToImage(sculptAsset);
  13646. if (sculpt != null)
  13647. {
  13648. mesh = primMesher.GenerateFacetedSculptMesh(omvPrim, (Bitmap)sculpt, m_sculptLodInCastRay);
  13649. sculpt.Dispose();
  13650. }
  13651. }
  13652. }
  13653. // When part is shape, create mesh
  13654. else if (omvPrim.Sculpt == null)
  13655. {
  13656. if (
  13657. omvPrim.PrimData.PathBegin == 0.0 && omvPrim.PrimData.PathEnd == 1.0 &&
  13658. omvPrim.PrimData.PathTaperX == 0.0 && omvPrim.PrimData.PathTaperY == 0.0 &&
  13659. omvPrim.PrimData.PathSkew == 0.0 &&
  13660. omvPrim.PrimData.PathTwist - omvPrim.PrimData.PathTwistBegin == 0.0
  13661. )
  13662. rayTrans.ShapeNeedsEnds = false;
  13663. mesh = primMesher.GenerateFacetedMesh(omvPrim, m_primLodInCastRay);
  13664. }
  13665. // Cache mesh if configured
  13666. if (m_useMeshCacheInCastRay && mesh != null)
  13667. {
  13668. lock(m_cachedMeshes)
  13669. {
  13670. if (!m_cachedMeshes.ContainsKey(meshKey))
  13671. m_cachedMeshes.Add(meshKey, mesh);
  13672. }
  13673. }
  13674. }
  13675. // Check mesh for ray hits
  13676. AddRayInFacetedMesh(mesh, rayTrans, ref rayHits);
  13677. mesh = null;
  13678. }
  13679. }
  13680. }
  13681. );
  13682. // Check avatar filter
  13683. if (!rejectAgents)
  13684. {
  13685. // Iterate over all avatars in region
  13686. World.ForEachRootScenePresence(
  13687. delegate (ScenePresence sp)
  13688. {
  13689. // Get bounding box
  13690. Vector3 lower;
  13691. Vector3 upper;
  13692. BoundingBoxOfScenePresence(sp, out lower, out upper);
  13693. // Parse avatar
  13694. Vector3 scalePart = upper - lower;
  13695. Vector3 posPart = sp.AbsolutePosition;
  13696. Quaternion rotPart = sp.GetWorldRotation();
  13697. Quaternion rotPartInv = Quaternion.Inverse(rotPart);
  13698. posPart = posPart + (lower + upper) * 0.5f * rotPart;
  13699. // Project ray
  13700. Vector3 pos1RayProj = ((pos1Ray - posPart) * rotPartInv) / scalePart;
  13701. Vector3 pos2RayProj = ((pos2Ray - posPart) * rotPartInv) / scalePart;
  13702. // Filter avatars by shape bounding boxes
  13703. Vector3 shapeBoxMax = new Vector3(0.5f + tol, 0.5f + tol, 0.5f + tol);
  13704. if (RayIntersectsShapeBox(pos1RayProj, pos2RayProj, shapeBoxMax))
  13705. {
  13706. // Prepare data needed to check for ray hits
  13707. RayTrans rayTrans = new RayTrans();
  13708. rayTrans.PartId = sp.UUID;
  13709. rayTrans.GroupId = sp.ParentPart != null ? sp.ParentPart.ParentGroup.UUID : sp.UUID;
  13710. rayTrans.Link = sp.ParentPart != null ? UUID2LinkNumber(sp.ParentPart, sp.UUID) : 0;
  13711. rayTrans.ScalePart = scalePart;
  13712. rayTrans.PositionPart = posPart;
  13713. rayTrans.RotationPart = rotPart;
  13714. rayTrans.ShapeNeedsEnds = false;
  13715. rayTrans.Position1Ray = pos1Ray;
  13716. rayTrans.Position1RayProj = pos1RayProj;
  13717. rayTrans.VectorRayProj = pos2RayProj - pos1RayProj;
  13718. // Try to get cached mesh if configured
  13719. PrimitiveBaseShape prim = PrimitiveBaseShape.CreateSphere();
  13720. int lod = (int)m_avatarLodInCastRay;
  13721. ulong meshKey = prim.GetMeshKey(Vector3.One, (float)(4 << lod));
  13722. FacetedMesh mesh = null;
  13723. if (m_useMeshCacheInCastRay)
  13724. {
  13725. lock (m_cachedMeshes)
  13726. {
  13727. m_cachedMeshes.TryGetValue(meshKey, out mesh);
  13728. }
  13729. }
  13730. // Create mesh if no cached mesh
  13731. if (mesh == null)
  13732. {
  13733. // Make OMV prim and create mesh
  13734. prim.Scale = scalePart;
  13735. Primitive omvPrim = prim.ToOmvPrimitive(posPart, rotPart);
  13736. mesh = primMesher.GenerateFacetedMesh(omvPrim, m_avatarLodInCastRay);
  13737. // Cache mesh if configured
  13738. if (m_useMeshCacheInCastRay && mesh != null)
  13739. {
  13740. lock(m_cachedMeshes)
  13741. {
  13742. if (!m_cachedMeshes.ContainsKey(meshKey))
  13743. m_cachedMeshes.Add(meshKey, mesh);
  13744. }
  13745. }
  13746. }
  13747. // Check mesh for ray hits
  13748. AddRayInFacetedMesh(mesh, rayTrans, ref rayHits);
  13749. mesh = null;
  13750. }
  13751. }
  13752. );
  13753. }
  13754. // Check terrain filter
  13755. if (!rejectLand)
  13756. {
  13757. // Parse terrain
  13758. // Mesh terrain and check bounding box
  13759. Vector3 lower;
  13760. Vector3 upper;
  13761. List<Tri> triangles = TrisFromHeightmapUnderRay(pos1Ray, pos2Ray, out lower, out upper);
  13762. lower.Z -= tol;
  13763. upper.Z += tol;
  13764. if ((pos1Ray.Z >= lower.Z || pos2Ray.Z >= lower.Z) && (pos1Ray.Z <= upper.Z || pos2Ray.Z <= upper.Z))
  13765. {
  13766. // Prepare data needed to check for ray hits
  13767. RayTrans rayTrans = new RayTrans();
  13768. rayTrans.PartId = UUID.Zero;
  13769. rayTrans.GroupId = UUID.Zero;
  13770. rayTrans.Link = 0;
  13771. rayTrans.ScalePart = new Vector3 (1.0f, 1.0f, 1.0f);
  13772. rayTrans.PositionPart = Vector3.Zero;
  13773. rayTrans.RotationPart = Quaternion.Identity;
  13774. rayTrans.ShapeNeedsEnds = true;
  13775. rayTrans.Position1Ray = pos1Ray;
  13776. rayTrans.Position1RayProj = pos1Ray;
  13777. rayTrans.VectorRayProj = vecRay;
  13778. // Check mesh
  13779. AddRayInTris(triangles, rayTrans, ref rayHits);
  13780. triangles = null;
  13781. }
  13782. }
  13783. // Sort hits by ascending distance
  13784. rayHits.Sort((s1, s2) => s1.Distance.CompareTo(s2.Distance));
  13785. // Check excess hits per part and group
  13786. for (int t = 0; t < 2; t++)
  13787. {
  13788. int maxHitsPerType = 0;
  13789. UUID id = UUID.Zero;
  13790. if (t == 0)
  13791. maxHitsPerType = m_maxHitsPerPrimInCastRay;
  13792. else
  13793. maxHitsPerType = m_maxHitsPerObjectInCastRay;
  13794. // Handle excess hits only when needed
  13795. if (maxHitsPerType < m_maxHitsInCastRay)
  13796. {
  13797. // Find excess hits
  13798. Hashtable hits = new Hashtable();
  13799. for (int i = rayHits.Count - 1; i >= 0; i--)
  13800. {
  13801. if (t == 0)
  13802. id = rayHits[i].PartId;
  13803. else
  13804. id = rayHits[i].GroupId;
  13805. if (hits.ContainsKey(id))
  13806. hits[id] = (int)hits[id] + 1;
  13807. else
  13808. hits[id] = 1;
  13809. }
  13810. // Remove excess hits
  13811. for (int i = rayHits.Count - 1; i >= 0; i--)
  13812. {
  13813. if (t == 0)
  13814. id = rayHits[i].PartId;
  13815. else
  13816. id = rayHits[i].GroupId;
  13817. int hit = (int)hits[id];
  13818. if (hit > m_maxHitsPerPrimInCastRay)
  13819. {
  13820. rayHits.RemoveAt(i);
  13821. hit--;
  13822. hits[id] = hit;
  13823. }
  13824. }
  13825. }
  13826. }
  13827. // Parse hits into result list according to data flags
  13828. int hitCount = rayHits.Count;
  13829. if (hitCount > maxHits)
  13830. hitCount = maxHits;
  13831. for (int i = 0; i < hitCount; i++)
  13832. {
  13833. RayHit rayHit = rayHits[i];
  13834. if (getRootKey)
  13835. result.Add(new LSL_Key(rayHit.GroupId.ToString()));
  13836. else
  13837. result.Add(new LSL_Key(rayHit.PartId.ToString()));
  13838. result.Add(new LSL_Vector(rayHit.Position));
  13839. if (getLinkNum)
  13840. result.Add(new LSL_Integer(rayHit.Link));
  13841. if (getNormal)
  13842. result.Add(new LSL_Vector(rayHit.Normal));
  13843. }
  13844. result.Add(new LSL_Integer(hitCount));
  13845. // Add to throttle data
  13846. stopWatch.Stop();
  13847. lock (m_castRayCalls)
  13848. {
  13849. CastRayCall castRayCall = new CastRayCall();
  13850. castRayCall.RegionId = regionId;
  13851. castRayCall.UserId = userId;
  13852. castRayCall.CalledMs = calledMs;
  13853. castRayCall.UsedMs = (int)stopWatch.ElapsedMilliseconds;
  13854. m_castRayCalls.Add(castRayCall);
  13855. }
  13856. // Return hits
  13857. return result;
  13858. }
  13859. /// <summary>
  13860. /// Struct for transmitting parameters required for finding llCastRay ray hits.
  13861. /// </summary>
  13862. public struct RayTrans
  13863. {
  13864. public UUID PartId;
  13865. public UUID GroupId;
  13866. public int Link;
  13867. public Vector3 ScalePart;
  13868. public Vector3 PositionPart;
  13869. public Quaternion RotationPart;
  13870. public bool ShapeNeedsEnds;
  13871. public Vector3 Position1Ray;
  13872. public Vector3 Position1RayProj;
  13873. public Vector3 VectorRayProj;
  13874. }
  13875. /// <summary>
  13876. /// Struct for llCastRay ray hits.
  13877. /// </summary>
  13878. public struct RayHit
  13879. {
  13880. public UUID PartId;
  13881. public UUID GroupId;
  13882. public int Link;
  13883. public Vector3 Position;
  13884. public Vector3 Normal;
  13885. public float Distance;
  13886. }
  13887. /// <summary>
  13888. /// Struct for llCastRay throttle data.
  13889. /// </summary>
  13890. public struct CastRayCall
  13891. {
  13892. public UUID RegionId;
  13893. public UUID UserId;
  13894. public int CalledMs;
  13895. public int UsedMs;
  13896. }
  13897. /// <summary>
  13898. /// Helper to check if a ray intersects a shape bounding box.
  13899. /// </summary>
  13900. private bool RayIntersectsShapeBox(Vector3 pos1RayProj, Vector3 pos2RayProj, Vector3 shapeBoxMax)
  13901. {
  13902. // Skip if ray can't intersect bounding box;
  13903. Vector3 rayBoxProjMin = Vector3.Min(pos1RayProj, pos2RayProj);
  13904. Vector3 rayBoxProjMax = Vector3.Max(pos1RayProj, pos2RayProj);
  13905. if (
  13906. rayBoxProjMin.X > shapeBoxMax.X || rayBoxProjMin.Y > shapeBoxMax.Y || rayBoxProjMin.Z > shapeBoxMax.Z ||
  13907. rayBoxProjMax.X < -shapeBoxMax.X || rayBoxProjMax.Y < -shapeBoxMax.Y || rayBoxProjMax.Z < -shapeBoxMax.Z
  13908. )
  13909. return false;
  13910. // Check if ray intersect any bounding box side
  13911. int sign = 0;
  13912. float dist = 0.0f;
  13913. Vector3 posProj = Vector3.Zero;
  13914. Vector3 vecRayProj = pos2RayProj - pos1RayProj;
  13915. // Check both X sides unless ray is parallell to them
  13916. if (Math.Abs(vecRayProj.X) > m_floatToleranceInCastRay)
  13917. {
  13918. for (sign = -1; sign <= 1; sign += 2)
  13919. {
  13920. dist = ((float)sign * shapeBoxMax.X - pos1RayProj.X) / vecRayProj.X;
  13921. posProj = pos1RayProj + vecRayProj * dist;
  13922. if (Math.Abs(posProj.Y) <= shapeBoxMax.Y && Math.Abs(posProj.Z) <= shapeBoxMax.Z)
  13923. return true;
  13924. }
  13925. }
  13926. // Check both Y sides unless ray is parallell to them
  13927. if (Math.Abs(vecRayProj.Y) > m_floatToleranceInCastRay)
  13928. {
  13929. for (sign = -1; sign <= 1; sign += 2)
  13930. {
  13931. dist = ((float)sign * shapeBoxMax.Y - pos1RayProj.Y) / vecRayProj.Y;
  13932. posProj = pos1RayProj + vecRayProj * dist;
  13933. if (Math.Abs(posProj.X) <= shapeBoxMax.X && Math.Abs(posProj.Z) <= shapeBoxMax.Z)
  13934. return true;
  13935. }
  13936. }
  13937. // Check both Z sides unless ray is parallell to them
  13938. if (Math.Abs(vecRayProj.Z) > m_floatToleranceInCastRay)
  13939. {
  13940. for (sign = -1; sign <= 1; sign += 2)
  13941. {
  13942. dist = ((float)sign * shapeBoxMax.Z - pos1RayProj.Z) / vecRayProj.Z;
  13943. posProj = pos1RayProj + vecRayProj * dist;
  13944. if (Math.Abs(posProj.X) <= shapeBoxMax.X && Math.Abs(posProj.Y) <= shapeBoxMax.Y)
  13945. return true;
  13946. }
  13947. }
  13948. // No hits on bounding box so return false
  13949. return false;
  13950. }
  13951. /// <summary>
  13952. /// Helper to parse FacetedMesh for ray hits.
  13953. /// </summary>
  13954. private void AddRayInFacetedMesh(FacetedMesh mesh, RayTrans rayTrans, ref List<RayHit> rayHits)
  13955. {
  13956. if (mesh != null)
  13957. {
  13958. foreach (Face face in mesh.Faces)
  13959. {
  13960. for (int i = 0; i < face.Indices.Count; i += 3)
  13961. {
  13962. Tri triangle = new Tri();
  13963. triangle.p1 = face.Vertices[face.Indices[i]].Position;
  13964. triangle.p2 = face.Vertices[face.Indices[i + 1]].Position;
  13965. triangle.p3 = face.Vertices[face.Indices[i + 2]].Position;
  13966. AddRayInTri(triangle, rayTrans, ref rayHits);
  13967. }
  13968. }
  13969. }
  13970. }
  13971. /// <summary>
  13972. /// Helper to parse Tri (triangle) List for ray hits.
  13973. /// </summary>
  13974. private void AddRayInTris(List<Tri> triangles, RayTrans rayTrans, ref List<RayHit> rayHits)
  13975. {
  13976. foreach (Tri triangle in triangles)
  13977. {
  13978. AddRayInTri(triangle, rayTrans, ref rayHits);
  13979. }
  13980. }
  13981. /// <summary>
  13982. /// Helper to add ray hit in a Tri (triangle).
  13983. /// </summary>
  13984. private void AddRayInTri(Tri triProj, RayTrans rayTrans, ref List<RayHit> rayHits)
  13985. {
  13986. // Check for hit in triangle
  13987. Vector3 posHitProj;
  13988. Vector3 normalProj;
  13989. if (HitRayInTri(triProj, rayTrans.Position1RayProj, rayTrans.VectorRayProj, out posHitProj, out normalProj))
  13990. {
  13991. // Hack to circumvent ghost face bug in PrimMesher by removing hits in (ghost) face plane through shape center
  13992. if (Math.Abs(Vector3.Dot(posHitProj, normalProj)) < m_floatToleranceInCastRay && !rayTrans.ShapeNeedsEnds)
  13993. return;
  13994. // Transform hit and normal to region coordinate system
  13995. Vector3 posHit = rayTrans.PositionPart + (posHitProj * rayTrans.ScalePart) * rayTrans.RotationPart;
  13996. Vector3 normal = Vector3.Normalize((normalProj * rayTrans.ScalePart) * rayTrans.RotationPart);
  13997. // Remove duplicate hits at triangle intersections
  13998. float distance = Vector3.Distance(rayTrans.Position1Ray, posHit);
  13999. for (int i = rayHits.Count - 1; i >= 0; i--)
  14000. {
  14001. if (rayHits[i].PartId != rayTrans.PartId)
  14002. break;
  14003. if (Math.Abs(rayHits[i].Distance - distance) < m_floatTolerance2InCastRay)
  14004. return;
  14005. }
  14006. // Build result data set
  14007. RayHit rayHit = new RayHit();
  14008. rayHit.PartId = rayTrans.PartId;
  14009. rayHit.GroupId = rayTrans.GroupId;
  14010. rayHit.Link = rayTrans.Link;
  14011. rayHit.Position = posHit;
  14012. rayHit.Normal = normal;
  14013. rayHit.Distance = distance;
  14014. rayHits.Add(rayHit);
  14015. }
  14016. }
  14017. /// <summary>
  14018. /// Helper to find ray hit in triangle
  14019. /// </summary>
  14020. bool HitRayInTri(Tri triProj, Vector3 pos1RayProj, Vector3 vecRayProj, out Vector3 posHitProj, out Vector3 normalProj)
  14021. {
  14022. float tol = m_floatToleranceInCastRay;
  14023. posHitProj = Vector3.Zero;
  14024. // Calculate triangle edge vectors
  14025. Vector3 vec1Proj = triProj.p2 - triProj.p1;
  14026. Vector3 vec2Proj = triProj.p3 - triProj.p2;
  14027. Vector3 vec3Proj = triProj.p1 - triProj.p3;
  14028. // Calculate triangle normal
  14029. normalProj = Vector3.Cross(vec1Proj, vec2Proj);
  14030. // Skip if degenerate triangle or ray parallell with triangle plane
  14031. float divisor = Vector3.Dot(vecRayProj, normalProj);
  14032. if (Math.Abs(divisor) < tol)
  14033. return false;
  14034. // Skip if exit and not configured to detect
  14035. if (divisor > tol && !m_detectExitsInCastRay)
  14036. return false;
  14037. // Skip if outside ray ends
  14038. float distanceProj = Vector3.Dot(triProj.p1 - pos1RayProj, normalProj) / divisor;
  14039. if (distanceProj < -tol || distanceProj > 1 + tol)
  14040. return false;
  14041. // Calculate hit position in triangle
  14042. posHitProj = pos1RayProj + vecRayProj * distanceProj;
  14043. // Skip if outside triangle bounding box
  14044. Vector3 triProjMin = Vector3.Min(Vector3.Min(triProj.p1, triProj.p2), triProj.p3);
  14045. Vector3 triProjMax = Vector3.Max(Vector3.Max(triProj.p1, triProj.p2), triProj.p3);
  14046. if (
  14047. posHitProj.X < triProjMin.X - tol || posHitProj.Y < triProjMin.Y - tol || posHitProj.Z < triProjMin.Z - tol ||
  14048. posHitProj.X > triProjMax.X + tol || posHitProj.Y > triProjMax.Y + tol || posHitProj.Z > triProjMax.Z + tol
  14049. )
  14050. return false;
  14051. // Skip if outside triangle
  14052. if (
  14053. Vector3.Dot(Vector3.Cross(vec1Proj, normalProj), posHitProj - triProj.p1) > tol ||
  14054. Vector3.Dot(Vector3.Cross(vec2Proj, normalProj), posHitProj - triProj.p2) > tol ||
  14055. Vector3.Dot(Vector3.Cross(vec3Proj, normalProj), posHitProj - triProj.p3) > tol
  14056. )
  14057. return false;
  14058. // Return hit
  14059. return true;
  14060. }
  14061. /// <summary>
  14062. /// Helper to parse selected parts of HeightMap into a Tri (triangle) List and calculate bounding box.
  14063. /// </summary>
  14064. private List<Tri> TrisFromHeightmapUnderRay(Vector3 posStart, Vector3 posEnd, out Vector3 lower, out Vector3 upper)
  14065. {
  14066. // Get bounding X-Y rectangle of terrain under ray
  14067. lower = Vector3.Min(posStart, posEnd);
  14068. upper = Vector3.Max(posStart, posEnd);
  14069. lower.X = (float)Math.Floor(lower.X);
  14070. lower.Y = (float)Math.Floor(lower.Y);
  14071. float zLower = float.MaxValue;
  14072. upper.X = (float)Math.Ceiling(upper.X);
  14073. upper.Y = (float)Math.Ceiling(upper.Y);
  14074. float zUpper = float.MinValue;
  14075. // Initialize Tri (triangle) List
  14076. List<Tri> triangles = new List<Tri>();
  14077. // Set parsing lane direction to major ray X-Y axis
  14078. Vector3 vec = posEnd - posStart;
  14079. float xAbs = Math.Abs(vec.X);
  14080. float yAbs = Math.Abs(vec.Y);
  14081. bool bigX = true;
  14082. if (yAbs > xAbs)
  14083. {
  14084. bigX = false;
  14085. vec = vec / yAbs;
  14086. }
  14087. else if (xAbs > yAbs || xAbs > 0.0f)
  14088. vec = vec / xAbs;
  14089. else
  14090. vec = new Vector3(1.0f, 1.0f, 0.0f);
  14091. // Simplify by start parsing in lower end of lane
  14092. if ((bigX && vec.X < 0.0f) || (!bigX && vec.Y < 0.0f))
  14093. {
  14094. Vector3 posTemp = posStart;
  14095. posStart = posEnd;
  14096. posEnd = posTemp;
  14097. vec = vec * -1.0f;
  14098. }
  14099. // First 1x1 rectangle under ray
  14100. float xFloorOld = 0.0f;
  14101. float yFloorOld = 0.0f;
  14102. Vector3 pos = posStart;
  14103. float xFloor = (float)Math.Floor(pos.X);
  14104. float yFloor = (float)Math.Floor(pos.Y);
  14105. AddTrisFromHeightmap(xFloor, yFloor, ref triangles, ref zLower, ref zUpper);
  14106. // Parse every remaining 1x1 rectangle under ray
  14107. while (pos != posEnd)
  14108. {
  14109. // Next 1x1 rectangle under ray
  14110. xFloorOld = xFloor;
  14111. yFloorOld = yFloor;
  14112. pos = pos + vec;
  14113. // Clip position to 1x1 rectangle border
  14114. xFloor = (float)Math.Floor(pos.X);
  14115. yFloor = (float)Math.Floor(pos.Y);
  14116. if (bigX && pos.X > xFloor)
  14117. {
  14118. pos.Y -= vec.Y * (pos.X - xFloor);
  14119. pos.X = xFloor;
  14120. }
  14121. else if (!bigX && pos.Y > yFloor)
  14122. {
  14123. pos.X -= vec.X * (pos.Y - yFloor);
  14124. pos.Y = yFloor;
  14125. }
  14126. // Last 1x1 rectangle under ray
  14127. if ((bigX && pos.X >= posEnd.X) || (!bigX && pos.Y >= posEnd.Y))
  14128. {
  14129. pos = posEnd;
  14130. xFloor = (float)Math.Floor(pos.X);
  14131. yFloor = (float)Math.Floor(pos.Y);
  14132. }
  14133. // Add new 1x1 rectangle in lane
  14134. if ((bigX && xFloor != xFloorOld) || (!bigX && yFloor != yFloorOld))
  14135. AddTrisFromHeightmap(xFloor, yFloor, ref triangles, ref zLower, ref zUpper);
  14136. // Add last 1x1 rectangle in old lane at lane shift
  14137. if (bigX && yFloor != yFloorOld)
  14138. AddTrisFromHeightmap(xFloor, yFloorOld, ref triangles, ref zLower, ref zUpper);
  14139. if (!bigX && xFloor != xFloorOld)
  14140. AddTrisFromHeightmap(xFloorOld, yFloor, ref triangles, ref zLower, ref zUpper);
  14141. }
  14142. // Finalize bounding box Z
  14143. lower.Z = zLower;
  14144. upper.Z = zUpper;
  14145. // Done and returning Tri (triangle)List
  14146. return triangles;
  14147. }
  14148. /// <summary>
  14149. /// Helper to add HeightMap squares into Tri (triangle) List and adjust bounding box.
  14150. /// </summary>
  14151. private void AddTrisFromHeightmap(float xPos, float yPos, ref List<Tri> triangles, ref float zLower, ref float zUpper)
  14152. {
  14153. int xInt = (int)xPos;
  14154. int yInt = (int)yPos;
  14155. // Corner 1 of 1x1 rectangle
  14156. int x = Util.Clamp<int>(xInt+1, 0, World.Heightmap.Width - 1);
  14157. int y = Util.Clamp<int>(yInt+1, 0, World.Heightmap.Height - 1);
  14158. Vector3 pos1 = new Vector3(x, y, (float)World.Heightmap[x, y]);
  14159. // Adjust bounding box
  14160. zLower = Math.Min(zLower, pos1.Z);
  14161. zUpper = Math.Max(zUpper, pos1.Z);
  14162. // Corner 2 of 1x1 rectangle
  14163. x = Util.Clamp<int>(xInt, 0, World.Heightmap.Width - 1);
  14164. y = Util.Clamp<int>(yInt+1, 0, World.Heightmap.Height - 1);
  14165. Vector3 pos2 = new Vector3(x, y, (float)World.Heightmap[x, y]);
  14166. // Adjust bounding box
  14167. zLower = Math.Min(zLower, pos2.Z);
  14168. zUpper = Math.Max(zUpper, pos2.Z);
  14169. // Corner 3 of 1x1 rectangle
  14170. x = Util.Clamp<int>(xInt, 0, World.Heightmap.Width - 1);
  14171. y = Util.Clamp<int>(yInt, 0, World.Heightmap.Height - 1);
  14172. Vector3 pos3 = new Vector3(x, y, (float)World.Heightmap[x, y]);
  14173. // Adjust bounding box
  14174. zLower = Math.Min(zLower, pos3.Z);
  14175. zUpper = Math.Max(zUpper, pos3.Z);
  14176. // Corner 4 of 1x1 rectangle
  14177. x = Util.Clamp<int>(xInt+1, 0, World.Heightmap.Width - 1);
  14178. y = Util.Clamp<int>(yInt, 0, World.Heightmap.Height - 1);
  14179. Vector3 pos4 = new Vector3(x, y, (float)World.Heightmap[x, y]);
  14180. // Adjust bounding box
  14181. zLower = Math.Min(zLower, pos4.Z);
  14182. zUpper = Math.Max(zUpper, pos4.Z);
  14183. // Add triangle 1
  14184. Tri triangle1 = new Tri();
  14185. triangle1.p1 = pos1;
  14186. triangle1.p2 = pos2;
  14187. triangle1.p3 = pos3;
  14188. triangles.Add(triangle1);
  14189. // Add triangle 2
  14190. Tri triangle2 = new Tri();
  14191. triangle2.p1 = pos3;
  14192. triangle2.p2 = pos4;
  14193. triangle2.p3 = pos1;
  14194. triangles.Add(triangle2);
  14195. }
  14196. /// <summary>
  14197. /// Helper to get link number for a UUID.
  14198. /// </summary>
  14199. private int UUID2LinkNumber(SceneObjectPart part, UUID id)
  14200. {
  14201. SceneObjectGroup group = part.ParentGroup;
  14202. if (group != null)
  14203. {
  14204. // Parse every link for UUID
  14205. int linkCount = group.PrimCount + group.GetSittingAvatarsCount();
  14206. for (int link = linkCount; link > 0; link--)
  14207. {
  14208. ISceneEntity entity = GetLinkEntity(part, link);
  14209. // Return link number if UUID match
  14210. if (entity != null && entity.UUID == id)
  14211. return link;
  14212. }
  14213. }
  14214. // Return link number 0 if no links or UUID matches
  14215. return 0;
  14216. }
  14217. public LSL_Integer llManageEstateAccess(int action, string avatar)
  14218. {
  14219. m_host.AddScriptLPS(1);
  14220. EstateSettings estate = World.RegionInfo.EstateSettings;
  14221. bool isAccount = false;
  14222. bool isGroup = false;
  14223. if (!estate.IsEstateOwner(m_host.OwnerID) || !estate.IsEstateManagerOrOwner(m_host.OwnerID))
  14224. return 0;
  14225. UUID id = new UUID();
  14226. if (!UUID.TryParse(avatar, out id))
  14227. return 0;
  14228. UserAccount account = World.UserAccountService.GetUserAccount(World.RegionInfo.ScopeID, id);
  14229. isAccount = account != null ? true : false;
  14230. if (!isAccount)
  14231. {
  14232. IGroupsModule groups = World.RequestModuleInterface<IGroupsModule>();
  14233. if (groups != null)
  14234. {
  14235. GroupRecord group = groups.GetGroupRecord(id);
  14236. isGroup = group != null ? true : false;
  14237. if (!isGroup)
  14238. return 0;
  14239. }
  14240. else
  14241. return 0;
  14242. }
  14243. switch (action)
  14244. {
  14245. case ScriptBaseClass.ESTATE_ACCESS_ALLOWED_AGENT_ADD:
  14246. if (!isAccount) return 0;
  14247. if (estate.HasAccess(id)) return 1;
  14248. if (estate.IsBanned(id, World.GetUserFlags(id)))
  14249. estate.RemoveBan(id);
  14250. estate.AddEstateUser(id);
  14251. break;
  14252. case ScriptBaseClass.ESTATE_ACCESS_ALLOWED_AGENT_REMOVE:
  14253. if (!isAccount || !estate.HasAccess(id)) return 0;
  14254. estate.RemoveEstateUser(id);
  14255. break;
  14256. case ScriptBaseClass.ESTATE_ACCESS_ALLOWED_GROUP_ADD:
  14257. if (!isGroup) return 0;
  14258. if (estate.GroupAccess(id)) return 1;
  14259. estate.AddEstateGroup(id);
  14260. break;
  14261. case ScriptBaseClass.ESTATE_ACCESS_ALLOWED_GROUP_REMOVE:
  14262. if (!isGroup || !estate.GroupAccess(id)) return 0;
  14263. estate.RemoveEstateGroup(id);
  14264. break;
  14265. case ScriptBaseClass.ESTATE_ACCESS_BANNED_AGENT_ADD:
  14266. if (!isAccount) return 0;
  14267. if (estate.IsBanned(id, World.GetUserFlags(id))) return 1;
  14268. EstateBan ban = new EstateBan();
  14269. ban.EstateID = estate.EstateID;
  14270. ban.BannedUserID = id;
  14271. estate.AddBan(ban);
  14272. break;
  14273. case ScriptBaseClass.ESTATE_ACCESS_BANNED_AGENT_REMOVE:
  14274. if (!isAccount || !estate.IsBanned(id, World.GetUserFlags(id))) return 0;
  14275. estate.RemoveBan(id);
  14276. break;
  14277. default: return 0;
  14278. }
  14279. return 1;
  14280. }
  14281. public LSL_Integer llGetMemoryLimit()
  14282. {
  14283. m_host.AddScriptLPS(1);
  14284. // The value returned for Mono scripts in SL
  14285. return 65536;
  14286. }
  14287. public LSL_Integer llSetMemoryLimit(LSL_Integer limit)
  14288. {
  14289. m_host.AddScriptLPS(1);
  14290. // Treat as an LSO script
  14291. return ScriptBaseClass.FALSE;
  14292. }
  14293. public LSL_Integer llGetSPMaxMemory()
  14294. {
  14295. m_host.AddScriptLPS(1);
  14296. // The value returned for Mono scripts in SL
  14297. return 65536;
  14298. }
  14299. public virtual LSL_Integer llGetUsedMemory()
  14300. {
  14301. m_host.AddScriptLPS(1);
  14302. // The value returned for Mono scripts in SL
  14303. return 65536;
  14304. }
  14305. public void llScriptProfiler(LSL_Integer flags)
  14306. {
  14307. m_host.AddScriptLPS(1);
  14308. // This does nothing for LSO scripts in SL
  14309. }
  14310. #region Not Implemented
  14311. //
  14312. // Listing the unimplemented lsl functions here, please move
  14313. // them from this region as they are completed
  14314. //
  14315. public void llSetSoundQueueing(int queue)
  14316. {
  14317. m_host.AddScriptLPS(1);
  14318. if (m_SoundModule != null)
  14319. m_SoundModule.SetSoundQueueing(m_host.UUID, queue == ScriptBaseClass.TRUE.value);
  14320. }
  14321. public void llCollisionSprite(string impact_sprite)
  14322. {
  14323. m_host.AddScriptLPS(1);
  14324. // Viewer 2.0 broke this and it's likely LL has no intention
  14325. // of fixing it. Therefore, letting this be a NOP seems appropriate.
  14326. }
  14327. public void llGodLikeRezObject(string inventory, LSL_Vector pos)
  14328. {
  14329. m_host.AddScriptLPS(1);
  14330. if (!World.Permissions.IsGod(m_host.OwnerID))
  14331. NotImplemented("llGodLikeRezObject");
  14332. AssetBase rezAsset = World.AssetService.Get(inventory);
  14333. if (rezAsset == null)
  14334. {
  14335. llSay(0, "Asset not found");
  14336. return;
  14337. }
  14338. SceneObjectGroup group = null;
  14339. try
  14340. {
  14341. string xmlData = Utils.BytesToString(rezAsset.Data);
  14342. group = SceneObjectSerializer.FromOriginalXmlFormat(xmlData);
  14343. }
  14344. catch
  14345. {
  14346. llSay(0, "Asset not found");
  14347. return;
  14348. }
  14349. if (group == null)
  14350. {
  14351. llSay(0, "Asset not found");
  14352. return;
  14353. }
  14354. group.RootPart.AttachedPos = group.AbsolutePosition;
  14355. group.ResetIDs();
  14356. Vector3 llpos = new Vector3((float)pos.x, (float)pos.y, (float)pos.z);
  14357. World.AddNewSceneObject(group, true, llpos, Quaternion.Identity, Vector3.Zero);
  14358. group.CreateScriptInstances(0, true, World.DefaultScriptEngine, 3);
  14359. group.ScheduleGroupForFullUpdate();
  14360. // objects rezzed with this method are die_at_edge by default.
  14361. group.RootPart.SetDieAtEdge(true);
  14362. group.ResumeScripts();
  14363. m_ScriptEngine.PostObjectEvent(m_host.LocalId, new EventParams(
  14364. "object_rez", new Object[] {
  14365. new LSL_String(
  14366. group.RootPart.UUID.ToString()) },
  14367. new DetectParams[0]));
  14368. }
  14369. public LSL_Key llTransferLindenDollars(string destination, int amount)
  14370. {
  14371. UUID txn = UUID.Random();
  14372. Util.FireAndForget(delegate(object x)
  14373. {
  14374. int replycode = 0;
  14375. string replydata = destination + "," + amount.ToString();
  14376. try
  14377. {
  14378. if (amount <= 0)
  14379. {
  14380. replydata = "INVALID_AMOUNT";
  14381. return;
  14382. }
  14383. TaskInventoryItem item = m_item;
  14384. if (item == null)
  14385. {
  14386. replydata = "SERVICE_ERROR";
  14387. return;
  14388. }
  14389. if (m_host.OwnerID == m_host.GroupID)
  14390. {
  14391. replydata = "GROUP_OWNED";
  14392. return;
  14393. }
  14394. m_host.AddScriptLPS(1);
  14395. if (item.PermsGranter == UUID.Zero)
  14396. {
  14397. replydata = "MISSING_PERMISSION_DEBIT";
  14398. return;
  14399. }
  14400. if ((item.PermsMask & ScriptBaseClass.PERMISSION_DEBIT) == 0)
  14401. {
  14402. replydata = "MISSING_PERMISSION_DEBIT";
  14403. return;
  14404. }
  14405. UUID toID = new UUID();
  14406. if (!UUID.TryParse(destination, out toID))
  14407. {
  14408. replydata = "INVALID_AGENT";
  14409. return;
  14410. }
  14411. UserAccount account = World.UserAccountService.GetUserAccount(World.RegionInfo.ScopeID, toID);
  14412. if (account == null)
  14413. {
  14414. replydata = "LINDENDOLLAR_ENTITYDOESNOTEXIST";
  14415. return;
  14416. }
  14417. IMoneyModule money = World.RequestModuleInterface<IMoneyModule>();
  14418. if (money == null)
  14419. {
  14420. replydata = "TRANSFERS_DISABLED";
  14421. return;
  14422. }
  14423. string reason;
  14424. bool result = money.ObjectGiveMoney( m_host.ParentGroup.RootPart.UUID, m_host.ParentGroup.RootPart.OwnerID, toID, amount, txn, out reason);
  14425. if (result)
  14426. {
  14427. replycode = 1;
  14428. return;
  14429. }
  14430. replydata = reason;
  14431. }
  14432. finally
  14433. {
  14434. m_ScriptEngine.PostScriptEvent(m_item.ItemID, new EventParams(
  14435. "transaction_result", new Object[] {
  14436. new LSL_String(txn.ToString()),
  14437. new LSL_Integer(replycode),
  14438. new LSL_String(replydata) },
  14439. new DetectParams[0]));
  14440. }
  14441. }, null, "LSL_Api.llTransferLindenDollars");
  14442. return txn.ToString();
  14443. }
  14444. #endregion
  14445. protected LSL_List SetPrimParams(ScenePresence av, LSL_List rules, string originFunc, ref uint rulesParsed)
  14446. {
  14447. //This is a special version of SetPrimParams to deal with avatars which are sitting on the linkset.
  14448. int idx = 0;
  14449. int idxStart = 0;
  14450. bool positionChanged = false;
  14451. try
  14452. {
  14453. while (idx < rules.Length)
  14454. {
  14455. ++rulesParsed;
  14456. int code = rules.GetLSLIntegerItem(idx++);
  14457. int remain = rules.Length - idx;
  14458. idxStart = idx;
  14459. switch (code)
  14460. {
  14461. case (int)ScriptBaseClass.PRIM_POSITION:
  14462. case (int)ScriptBaseClass.PRIM_POS_LOCAL:
  14463. {
  14464. if (remain < 1)
  14465. return new LSL_List();
  14466. LSL_Vector v;
  14467. v = rules.GetVector3Item(idx++);
  14468. if(!av.LegacySitOffsets)
  14469. {
  14470. LSL_Vector sitOffset = (llRot2Up(new LSL_Rotation(av.Rotation.X, av.Rotation.Y, av.Rotation.Z, av.Rotation.W)) * av.Appearance.AvatarHeight * 0.02638f);
  14471. v = v + 2 * sitOffset;
  14472. }
  14473. av.OffsetPosition = new Vector3((float)v.x, (float)v.y, (float)v.z);
  14474. positionChanged = true;
  14475. }
  14476. break;
  14477. case (int)ScriptBaseClass.PRIM_ROTATION:
  14478. {
  14479. if (remain < 1)
  14480. return new LSL_List();
  14481. Quaternion r;
  14482. r = rules.GetQuaternionItem(idx++);
  14483. av.Rotation = m_host.GetWorldRotation() * r;
  14484. positionChanged = true;
  14485. }
  14486. break;
  14487. case (int)ScriptBaseClass.PRIM_ROT_LOCAL:
  14488. {
  14489. if (remain < 1)
  14490. return new LSL_List();
  14491. LSL_Rotation r;
  14492. r = rules.GetQuaternionItem(idx++);
  14493. av.Rotation = r;
  14494. positionChanged = true;
  14495. }
  14496. break;
  14497. // parse rest doing nothing but number of parameters error check
  14498. case (int)ScriptBaseClass.PRIM_SIZE:
  14499. case (int)ScriptBaseClass.PRIM_MATERIAL:
  14500. case (int)ScriptBaseClass.PRIM_PHANTOM:
  14501. case (int)ScriptBaseClass.PRIM_PHYSICS:
  14502. case (int)ScriptBaseClass.PRIM_PHYSICS_SHAPE_TYPE:
  14503. case (int)ScriptBaseClass.PRIM_TEMP_ON_REZ:
  14504. case (int)ScriptBaseClass.PRIM_NAME:
  14505. case (int)ScriptBaseClass.PRIM_DESC:
  14506. if (remain < 1)
  14507. return new LSL_List();
  14508. idx++;
  14509. break;
  14510. case (int)ScriptBaseClass.PRIM_GLOW:
  14511. case (int)ScriptBaseClass.PRIM_FULLBRIGHT:
  14512. case (int)ScriptBaseClass.PRIM_TEXGEN:
  14513. if (remain < 2)
  14514. return new LSL_List();
  14515. idx += 2;
  14516. break;
  14517. case (int)ScriptBaseClass.PRIM_TYPE:
  14518. if (remain < 3)
  14519. return new LSL_List();
  14520. code = (int)rules.GetLSLIntegerItem(idx++);
  14521. remain = rules.Length - idx;
  14522. switch (code)
  14523. {
  14524. case (int)ScriptBaseClass.PRIM_TYPE_BOX:
  14525. case (int)ScriptBaseClass.PRIM_TYPE_CYLINDER:
  14526. case (int)ScriptBaseClass.PRIM_TYPE_PRISM:
  14527. if (remain < 6)
  14528. return new LSL_List();
  14529. idx += 6;
  14530. break;
  14531. case (int)ScriptBaseClass.PRIM_TYPE_SPHERE:
  14532. if (remain < 5)
  14533. return new LSL_List();
  14534. idx += 5;
  14535. break;
  14536. case (int)ScriptBaseClass.PRIM_TYPE_TORUS:
  14537. case (int)ScriptBaseClass.PRIM_TYPE_TUBE:
  14538. case (int)ScriptBaseClass.PRIM_TYPE_RING:
  14539. if (remain < 11)
  14540. return new LSL_List();
  14541. idx += 11;
  14542. break;
  14543. case (int)ScriptBaseClass.PRIM_TYPE_SCULPT:
  14544. if (remain < 2)
  14545. return new LSL_List();
  14546. idx += 2;
  14547. break;
  14548. }
  14549. break;
  14550. case (int)ScriptBaseClass.PRIM_COLOR:
  14551. case (int)ScriptBaseClass.PRIM_TEXT:
  14552. case (int)ScriptBaseClass.PRIM_BUMP_SHINY:
  14553. case (int)ScriptBaseClass.PRIM_OMEGA:
  14554. case (int)ScriptBaseClass.PRIM_SIT_TARGET:
  14555. if (remain < 3)
  14556. return new LSL_List();
  14557. idx += 3;
  14558. break;
  14559. case (int)ScriptBaseClass.PRIM_TEXTURE:
  14560. case (int)ScriptBaseClass.PRIM_POINT_LIGHT:
  14561. case (int)ScriptBaseClass.PRIM_PHYSICS_MATERIAL:
  14562. if (remain < 5)
  14563. return new LSL_List();
  14564. idx += 5;
  14565. break;
  14566. case (int)ScriptBaseClass.PRIM_FLEXIBLE:
  14567. if (remain < 7)
  14568. return new LSL_List();
  14569. idx += 7;
  14570. break;
  14571. case (int)ScriptBaseClass.PRIM_LINK_TARGET:
  14572. if (remain < 3) // setting to 3 on the basis that parsing any usage of PRIM_LINK_TARGET that has nothing following it is pointless.
  14573. return new LSL_List();
  14574. return rules.GetSublist(idx, -1);
  14575. }
  14576. }
  14577. }
  14578. catch (InvalidCastException e)
  14579. {
  14580. Error(originFunc,string.Format(
  14581. " error running rule #{0}: arg #{1} {2}",
  14582. rulesParsed, idx - idxStart, e.Message));
  14583. }
  14584. finally
  14585. {
  14586. if (positionChanged)
  14587. av.SendTerseUpdateToAllClients();
  14588. }
  14589. return new LSL_List();
  14590. }
  14591. public LSL_List GetPrimParams(ScenePresence avatar, LSL_List rules, ref LSL_List res)
  14592. {
  14593. // avatars case
  14594. // replies as SL wiki
  14595. // SceneObjectPart sitPart = avatar.ParentPart; // most likelly it will be needed
  14596. SceneObjectPart sitPart = World.GetSceneObjectPart(avatar.ParentID); // maybe better do this expensive search for it in case it's gone??
  14597. int idx = 0;
  14598. while (idx < rules.Length)
  14599. {
  14600. int code = (int)rules.GetLSLIntegerItem(idx++);
  14601. int remain = rules.Length - idx;
  14602. switch (code)
  14603. {
  14604. case (int)ScriptBaseClass.PRIM_MATERIAL:
  14605. res.Add(new LSL_Integer((int)SOPMaterialData.SopMaterial.Flesh));
  14606. break;
  14607. case (int)ScriptBaseClass.PRIM_PHYSICS:
  14608. res.Add(new LSL_Integer(0));
  14609. break;
  14610. case (int)ScriptBaseClass.PRIM_TEMP_ON_REZ:
  14611. res.Add(new LSL_Integer(0));
  14612. break;
  14613. case (int)ScriptBaseClass.PRIM_PHANTOM:
  14614. res.Add(new LSL_Integer(0));
  14615. break;
  14616. case (int)ScriptBaseClass.PRIM_POSITION:
  14617. Vector3 pos;
  14618. if (sitPart.ParentGroup.RootPart != null)
  14619. {
  14620. pos = avatar.OffsetPosition;
  14621. if(!avatar.LegacySitOffsets)
  14622. {
  14623. Vector3 sitOffset = (Zrot(avatar.Rotation)) * (avatar.Appearance.AvatarHeight * 0.02638f *2.0f);
  14624. pos -= sitOffset;
  14625. }
  14626. SceneObjectPart sitroot = sitPart.ParentGroup.RootPart;
  14627. pos = sitroot.AbsolutePosition + pos * sitroot.GetWorldRotation();
  14628. }
  14629. else
  14630. pos = avatar.AbsolutePosition;
  14631. res.Add(new LSL_Vector(pos.X,pos.Y,pos.Z));
  14632. break;
  14633. case (int)ScriptBaseClass.PRIM_SIZE:
  14634. Vector3 s = avatar.Appearance.AvatarSize;
  14635. res.Add(new LSL_Vector(s.X, s.Y, s.Z));
  14636. break;
  14637. case (int)ScriptBaseClass.PRIM_ROTATION:
  14638. res.Add(new LSL_Rotation(avatar.GetWorldRotation()));
  14639. break;
  14640. case (int)ScriptBaseClass.PRIM_TYPE:
  14641. res.Add(new LSL_Integer(ScriptBaseClass.PRIM_TYPE_BOX));
  14642. res.Add(new LSL_Integer(ScriptBaseClass.PRIM_HOLE_DEFAULT));
  14643. res.Add(new LSL_Vector(0f,1.0f,0f));
  14644. res.Add(new LSL_Float(0.0f));
  14645. res.Add(new LSL_Vector(0, 0, 0));
  14646. res.Add(new LSL_Vector(1.0f,1.0f,0f));
  14647. res.Add(new LSL_Vector(0, 0, 0));
  14648. break;
  14649. case (int)ScriptBaseClass.PRIM_TEXTURE:
  14650. if (remain < 1)
  14651. return new LSL_List();
  14652. int face = (int)rules.GetLSLIntegerItem(idx++);
  14653. if (face == ScriptBaseClass.ALL_SIDES)
  14654. {
  14655. for (face = 0; face < 21; face++)
  14656. {
  14657. res.Add(new LSL_String(""));
  14658. res.Add(new LSL_Vector(0,0,0));
  14659. res.Add(new LSL_Vector(0,0,0));
  14660. res.Add(new LSL_Float(0.0));
  14661. }
  14662. }
  14663. else
  14664. {
  14665. if (face >= 0 && face < 21)
  14666. {
  14667. res.Add(new LSL_String(""));
  14668. res.Add(new LSL_Vector(0,0,0));
  14669. res.Add(new LSL_Vector(0,0,0));
  14670. res.Add(new LSL_Float(0.0));
  14671. }
  14672. }
  14673. break;
  14674. case (int)ScriptBaseClass.PRIM_COLOR:
  14675. if (remain < 1)
  14676. return new LSL_List();
  14677. face = (int)rules.GetLSLIntegerItem(idx++);
  14678. if (face == ScriptBaseClass.ALL_SIDES)
  14679. {
  14680. for (face = 0; face < 21; face++)
  14681. {
  14682. res.Add(new LSL_Vector(0,0,0));
  14683. res.Add(new LSL_Float(0));
  14684. }
  14685. }
  14686. else
  14687. {
  14688. res.Add(new LSL_Vector(0,0,0));
  14689. res.Add(new LSL_Float(0));
  14690. }
  14691. break;
  14692. case (int)ScriptBaseClass.PRIM_BUMP_SHINY:
  14693. if (remain < 1)
  14694. return new LSL_List();
  14695. face = (int)rules.GetLSLIntegerItem(idx++);
  14696. if (face == ScriptBaseClass.ALL_SIDES)
  14697. {
  14698. for (face = 0; face < 21; face++)
  14699. {
  14700. res.Add(new LSL_Integer(ScriptBaseClass.PRIM_SHINY_NONE));
  14701. res.Add(new LSL_Integer(ScriptBaseClass.PRIM_BUMP_NONE));
  14702. }
  14703. }
  14704. else
  14705. {
  14706. res.Add(new LSL_Integer(ScriptBaseClass.PRIM_SHINY_NONE));
  14707. res.Add(new LSL_Integer(ScriptBaseClass.PRIM_BUMP_NONE));
  14708. }
  14709. break;
  14710. case (int)ScriptBaseClass.PRIM_FULLBRIGHT:
  14711. if (remain < 1)
  14712. return new LSL_List();
  14713. face = (int)rules.GetLSLIntegerItem(idx++);
  14714. if (face == ScriptBaseClass.ALL_SIDES)
  14715. {
  14716. for (face = 0; face < 21; face++)
  14717. {
  14718. res.Add(new LSL_Integer(ScriptBaseClass.FALSE));
  14719. }
  14720. }
  14721. else
  14722. {
  14723. res.Add(new LSL_Integer(ScriptBaseClass.FALSE));
  14724. }
  14725. break;
  14726. case (int)ScriptBaseClass.PRIM_FLEXIBLE:
  14727. res.Add(new LSL_Integer(0));
  14728. res.Add(new LSL_Integer(0));// softness
  14729. res.Add(new LSL_Float(0.0f)); // gravity
  14730. res.Add(new LSL_Float(0.0f)); // friction
  14731. res.Add(new LSL_Float(0.0f)); // wind
  14732. res.Add(new LSL_Float(0.0f)); // tension
  14733. res.Add(new LSL_Vector(0f,0f,0f));
  14734. break;
  14735. case (int)ScriptBaseClass.PRIM_TEXGEN:
  14736. // (PRIM_TEXGEN_DEFAULT, PRIM_TEXGEN_PLANAR)
  14737. if (remain < 1)
  14738. return new LSL_List();
  14739. face = (int)rules.GetLSLIntegerItem(idx++);
  14740. if (face == ScriptBaseClass.ALL_SIDES)
  14741. {
  14742. for (face = 0; face < 21; face++)
  14743. {
  14744. res.Add(new LSL_Integer(ScriptBaseClass.PRIM_TEXGEN_DEFAULT));
  14745. }
  14746. }
  14747. else
  14748. {
  14749. res.Add(new LSL_Integer(ScriptBaseClass.PRIM_TEXGEN_DEFAULT));
  14750. }
  14751. break;
  14752. case (int)ScriptBaseClass.PRIM_POINT_LIGHT:
  14753. res.Add(new LSL_Integer(0));
  14754. res.Add(new LSL_Vector(0f,0f,0f));
  14755. res.Add(new LSL_Float(0f)); // intensity
  14756. res.Add(new LSL_Float(0f)); // radius
  14757. res.Add(new LSL_Float(0f)); // falloff
  14758. break;
  14759. case (int)ScriptBaseClass.PRIM_GLOW:
  14760. if (remain < 1)
  14761. return new LSL_List();
  14762. face = (int)rules.GetLSLIntegerItem(idx++);
  14763. if (face == ScriptBaseClass.ALL_SIDES)
  14764. {
  14765. for (face = 0; face < 21; face++)
  14766. {
  14767. res.Add(new LSL_Float(0f));
  14768. }
  14769. }
  14770. else
  14771. {
  14772. res.Add(new LSL_Float(0f));
  14773. }
  14774. break;
  14775. case (int)ScriptBaseClass.PRIM_TEXT:
  14776. res.Add(new LSL_String(""));
  14777. res.Add(new LSL_Vector(0f,0f,0f));
  14778. res.Add(new LSL_Float(1.0f));
  14779. break;
  14780. case (int)ScriptBaseClass.PRIM_NAME:
  14781. res.Add(new LSL_String(avatar.Name));
  14782. break;
  14783. case (int)ScriptBaseClass.PRIM_DESC:
  14784. res.Add(new LSL_String(""));
  14785. break;
  14786. case (int)ScriptBaseClass.PRIM_ROT_LOCAL:
  14787. Quaternion lrot = avatar.Rotation;
  14788. res.Add(new LSL_Rotation(lrot.X, lrot.Y, lrot.Z, lrot.W));
  14789. break;
  14790. case (int)ScriptBaseClass.PRIM_POS_LOCAL:
  14791. Vector3 lpos = avatar.OffsetPosition;
  14792. if(!avatar.LegacySitOffsets)
  14793. {
  14794. Vector3 lsitOffset = (Zrot(avatar.Rotation)) * (avatar.Appearance.AvatarHeight * 0.02638f * 2.0f);
  14795. lpos -= lsitOffset;
  14796. }
  14797. res.Add(new LSL_Vector(lpos.X,lpos.Y,lpos.Z));
  14798. break;
  14799. case (int)ScriptBaseClass.PRIM_LINK_TARGET:
  14800. if (remain < 3) // setting to 3 on the basis that parsing any usage of PRIM_LINK_TARGET that has nothing following it is pointless.
  14801. return new LSL_List();
  14802. return rules.GetSublist(idx, -1);
  14803. }
  14804. }
  14805. return new LSL_List();
  14806. }
  14807. public void llSetAnimationOverride(LSL_String animState, LSL_String anim)
  14808. {
  14809. string state = String.Empty;
  14810. foreach (KeyValuePair<string, string> kvp in MovementAnimationsForLSL)
  14811. {
  14812. if (kvp.Value.ToLower() == ((string)animState).ToLower())
  14813. {
  14814. state = kvp.Key;
  14815. break;
  14816. }
  14817. }
  14818. if (state == String.Empty)
  14819. {
  14820. llShout(ScriptBaseClass.DEBUG_CHANNEL, "Invalid animation state " + animState);
  14821. return;
  14822. }
  14823. if (m_item.PermsGranter == UUID.Zero)
  14824. {
  14825. llShout(ScriptBaseClass.DEBUG_CHANNEL, "No permission to override animations");
  14826. return;
  14827. }
  14828. if ((m_item.PermsMask & ScriptBaseClass.PERMISSION_OVERRIDE_ANIMATIONS) == 0)
  14829. {
  14830. llShout(ScriptBaseClass.DEBUG_CHANNEL, "No permission to override animations");
  14831. return;
  14832. }
  14833. ScenePresence presence = World.GetScenePresence(m_item.PermsGranter);
  14834. if (presence == null)
  14835. return;
  14836. UUID animID;
  14837. animID = ScriptUtils.GetAssetIdFromItemName(m_host, anim, (int)AssetType.Animation);
  14838. if (animID == UUID.Zero)
  14839. {
  14840. String animupper = ((string)anim).ToUpperInvariant();
  14841. DefaultAvatarAnimations.AnimsUUID.TryGetValue(animupper, out animID);
  14842. }
  14843. if (animID == UUID.Zero)
  14844. {
  14845. llShout(ScriptBaseClass.DEBUG_CHANNEL, "Animation not found");
  14846. return;
  14847. }
  14848. presence.SetAnimationOverride(state, animID);
  14849. }
  14850. public void llResetAnimationOverride(LSL_String animState)
  14851. {
  14852. ScenePresence presence = World.GetScenePresence(m_item.PermsGranter);
  14853. if (presence == null)
  14854. return;
  14855. if (m_item.PermsGranter == UUID.Zero)
  14856. {
  14857. llShout(ScriptBaseClass.DEBUG_CHANNEL, "No permission to override animations");
  14858. return;
  14859. }
  14860. if ((m_item.PermsMask & ScriptBaseClass.PERMISSION_OVERRIDE_ANIMATIONS) == 0)
  14861. {
  14862. llShout(ScriptBaseClass.DEBUG_CHANNEL, "No permission to override animations");
  14863. return;
  14864. }
  14865. if (animState == "ALL")
  14866. {
  14867. presence.SetAnimationOverride("ALL", UUID.Zero);
  14868. return;
  14869. }
  14870. string state = String.Empty;
  14871. foreach (KeyValuePair<string, string> kvp in MovementAnimationsForLSL)
  14872. {
  14873. if (kvp.Value.ToLower() == ((string)animState).ToLower())
  14874. {
  14875. state = kvp.Key;
  14876. break;
  14877. }
  14878. }
  14879. if (state == String.Empty)
  14880. {
  14881. return;
  14882. }
  14883. presence.SetAnimationOverride(state, UUID.Zero);
  14884. }
  14885. public LSL_String llGetAnimationOverride(LSL_String animState)
  14886. {
  14887. ScenePresence presence = World.GetScenePresence(m_item.PermsGranter);
  14888. if (presence == null)
  14889. return String.Empty;
  14890. if (m_item.PermsGranter == UUID.Zero)
  14891. {
  14892. llShout(ScriptBaseClass.DEBUG_CHANNEL, "No permission to override animations");
  14893. return String.Empty;
  14894. }
  14895. if ((m_item.PermsMask & (ScriptBaseClass.PERMISSION_OVERRIDE_ANIMATIONS | ScriptBaseClass.PERMISSION_TRIGGER_ANIMATION)) == 0)
  14896. {
  14897. llShout(ScriptBaseClass.DEBUG_CHANNEL, "No permission to override animations");
  14898. return String.Empty;
  14899. }
  14900. string state = String.Empty;
  14901. foreach (KeyValuePair<string, string> kvp in MovementAnimationsForLSL)
  14902. {
  14903. if (kvp.Value.ToLower() == ((string)animState).ToLower())
  14904. {
  14905. state = kvp.Key;
  14906. break;
  14907. }
  14908. }
  14909. if (state == String.Empty)
  14910. {
  14911. return String.Empty;
  14912. }
  14913. UUID animID = presence.GetAnimationOverride(state);
  14914. if (animID == UUID.Zero)
  14915. return animState;
  14916. foreach (KeyValuePair<string, UUID> kvp in DefaultAvatarAnimations.AnimsUUID)
  14917. {
  14918. if (kvp.Value == animID)
  14919. return kvp.Key.ToLower();
  14920. }
  14921. foreach (TaskInventoryItem item in m_host.Inventory.GetInventoryItems())
  14922. {
  14923. if (item.AssetID == animID)
  14924. return item.Name;
  14925. }
  14926. return String.Empty;
  14927. }
  14928. public LSL_List llJson2List(LSL_String json)
  14929. {
  14930. if(String.IsNullOrEmpty(json))
  14931. return new LSL_List();
  14932. if(json == "[]")
  14933. return new LSL_List();
  14934. if(json == "{}")
  14935. return new LSL_List();
  14936. char first = ((string)json)[0];
  14937. if(first != '[' && first !='{')
  14938. {
  14939. // we already have a single element
  14940. LSL_List l = new LSL_List();
  14941. l.Add(json);
  14942. return l;
  14943. }
  14944. LitJson.JsonData jsdata;
  14945. try
  14946. {
  14947. jsdata = LitJson.JsonMapper.ToObject(json);
  14948. }
  14949. catch (Exception e)
  14950. {
  14951. string m = e.Message; // debug point
  14952. return json;
  14953. }
  14954. try
  14955. {
  14956. return JsonParseTop(jsdata);
  14957. }
  14958. catch (Exception e)
  14959. {
  14960. string m = e.Message; // debug point
  14961. return (LSL_String)ScriptBaseClass.JSON_INVALID;
  14962. }
  14963. }
  14964. private LSL_List JsonParseTop(LitJson.JsonData elem)
  14965. {
  14966. LSL_List retl = new LSL_List();
  14967. if(elem == null)
  14968. retl.Add((LSL_String)ScriptBaseClass.JSON_NULL);
  14969. LitJson.JsonType elemType = elem.GetJsonType();
  14970. switch (elemType)
  14971. {
  14972. case LitJson.JsonType.Int:
  14973. retl.Add(new LSL_Integer((int)elem));
  14974. return retl;
  14975. case LitJson.JsonType.Boolean:
  14976. retl.Add((LSL_String)((bool)elem ? ScriptBaseClass.JSON_TRUE : ScriptBaseClass.JSON_FALSE));
  14977. return retl;
  14978. case LitJson.JsonType.Double:
  14979. retl.Add(new LSL_Float((double)elem));
  14980. return retl;
  14981. case LitJson.JsonType.None:
  14982. retl.Add((LSL_String)ScriptBaseClass.JSON_NULL);
  14983. return retl;
  14984. case LitJson.JsonType.String:
  14985. retl.Add(new LSL_String((string)elem));
  14986. return retl;
  14987. case LitJson.JsonType.Array:
  14988. foreach (LitJson.JsonData subelem in elem)
  14989. retl.Add(JsonParseTopNodes(subelem));
  14990. return retl;
  14991. case LitJson.JsonType.Object:
  14992. IDictionaryEnumerator e = ((IOrderedDictionary)elem).GetEnumerator();
  14993. while (e.MoveNext())
  14994. {
  14995. retl.Add(new LSL_String((string)e.Key));
  14996. retl.Add(JsonParseTopNodes((LitJson.JsonData)e.Value));
  14997. }
  14998. return retl;
  14999. default:
  15000. throw new Exception(ScriptBaseClass.JSON_INVALID);
  15001. }
  15002. }
  15003. private object JsonParseTopNodes(LitJson.JsonData elem)
  15004. {
  15005. if(elem == null)
  15006. return ((LSL_String)ScriptBaseClass.JSON_NULL);
  15007. LitJson.JsonType elemType = elem.GetJsonType();
  15008. switch (elemType)
  15009. {
  15010. case LitJson.JsonType.Int:
  15011. return (new LSL_Integer((int)elem));
  15012. case LitJson.JsonType.Boolean:
  15013. return ((bool)elem ? (LSL_String)ScriptBaseClass.JSON_TRUE : (LSL_String)ScriptBaseClass.JSON_FALSE);
  15014. case LitJson.JsonType.Double:
  15015. return (new LSL_Float((double)elem));
  15016. case LitJson.JsonType.None:
  15017. return ((LSL_String)ScriptBaseClass.JSON_NULL);
  15018. case LitJson.JsonType.String:
  15019. return (new LSL_String((string)elem));
  15020. case LitJson.JsonType.Array:
  15021. case LitJson.JsonType.Object:
  15022. string s = LitJson.JsonMapper.ToJson(elem);
  15023. return (LSL_String)s;
  15024. default:
  15025. throw new Exception(ScriptBaseClass.JSON_INVALID);
  15026. }
  15027. }
  15028. public LSL_String llList2Json(LSL_String type, LSL_List values)
  15029. {
  15030. try
  15031. {
  15032. StringBuilder sb = new StringBuilder();
  15033. if (type == ScriptBaseClass.JSON_ARRAY)
  15034. {
  15035. sb.Append("[");
  15036. int i= 0;
  15037. foreach (object o in values.Data)
  15038. {
  15039. sb.Append(ListToJson(o));
  15040. if((i++) < values.Data.Length - 1)
  15041. sb.Append(",");
  15042. }
  15043. sb.Append("]");
  15044. return (LSL_String)sb.ToString();;
  15045. }
  15046. else if (type == ScriptBaseClass.JSON_OBJECT)
  15047. {
  15048. sb.Append("{");
  15049. for (int i = 0; i < values.Data.Length; i += 2)
  15050. {
  15051. if (!(values.Data[i] is LSL_String))
  15052. return ScriptBaseClass.JSON_INVALID;
  15053. string key = ((LSL_String)values.Data[i]).m_string;
  15054. key = EscapeForJSON(key, true);
  15055. sb.Append(key);
  15056. sb.Append(":");
  15057. sb.Append(ListToJson(values.Data[i+1]));
  15058. if(i < values.Data.Length - 2)
  15059. sb.Append(",");
  15060. }
  15061. sb.Append("}");
  15062. return (LSL_String)sb.ToString();
  15063. }
  15064. return ScriptBaseClass.JSON_INVALID;
  15065. }
  15066. catch
  15067. {
  15068. return ScriptBaseClass.JSON_INVALID;
  15069. }
  15070. }
  15071. private string ListToJson(object o)
  15072. {
  15073. if (o is LSL_Float || o is double)
  15074. {
  15075. double float_val;
  15076. if (o is double)
  15077. float_val = ((double)o);
  15078. else
  15079. float_val = ((LSL_Float)o).value;
  15080. if(double.IsInfinity(float_val))
  15081. return "\"Inf\"";
  15082. if(double.IsNaN(float_val))
  15083. return "\"NaN\"";
  15084. return ((LSL_Float)float_val).ToString();
  15085. }
  15086. if (o is LSL_Integer || o is int)
  15087. {
  15088. int i;
  15089. if (o is int)
  15090. i = ((int)o);
  15091. else
  15092. i = ((LSL_Integer)o).value;
  15093. return i.ToString();
  15094. }
  15095. if (o is LSL_Rotation)
  15096. {
  15097. StringBuilder sb = new StringBuilder(128);
  15098. sb.Append("\"");
  15099. LSL_Rotation r = (LSL_Rotation)o;
  15100. sb.Append(r.ToString());
  15101. sb.Append("\"");
  15102. return sb.ToString();
  15103. }
  15104. if (o is LSL_Vector)
  15105. {
  15106. StringBuilder sb = new StringBuilder(128);
  15107. sb.Append("\"");
  15108. LSL_Vector v = (LSL_Vector)o;
  15109. sb.Append(v.ToString());
  15110. sb.Append("\"");
  15111. return sb.ToString();
  15112. }
  15113. if (o is LSL_String || o is string)
  15114. {
  15115. string str;
  15116. if (o is string)
  15117. str = ((string)o);
  15118. else
  15119. str = ((LSL_String)o).m_string;
  15120. if(str == ScriptBaseClass.JSON_TRUE || str == "true")
  15121. return "true";
  15122. if(str == ScriptBaseClass.JSON_FALSE ||str == "false")
  15123. return "false";
  15124. if(str == ScriptBaseClass.JSON_NULL || str == "null")
  15125. return "null";
  15126. str.Trim();
  15127. if (str[0] == '{')
  15128. return str;
  15129. if (str[0] == '[')
  15130. return str;
  15131. return EscapeForJSON(str, true);
  15132. }
  15133. throw new IndexOutOfRangeException();
  15134. }
  15135. private string EscapeForJSON(string s, bool AddOuter)
  15136. {
  15137. int i;
  15138. char c;
  15139. String t;
  15140. int len = s.Length;
  15141. StringBuilder sb = new StringBuilder(len + 64);
  15142. if(AddOuter)
  15143. sb.Append("\"");
  15144. for (i = 0; i < len; i++)
  15145. {
  15146. c = s[i];
  15147. switch (c)
  15148. {
  15149. case '\\':
  15150. case '"':
  15151. case '/':
  15152. sb.Append('\\');
  15153. sb.Append(c);
  15154. break;
  15155. case '\b':
  15156. sb.Append("\\b");
  15157. break;
  15158. case '\t':
  15159. sb.Append("\\t");
  15160. break;
  15161. case '\n':
  15162. sb.Append("\\n");
  15163. break;
  15164. case '\f':
  15165. sb.Append("\\f");
  15166. break;
  15167. case '\r':
  15168. sb.Append("\\r");
  15169. break;
  15170. default:
  15171. if (c < ' ')
  15172. {
  15173. t = "000" + String.Format("{0:X}", c);
  15174. sb.Append("\\u" + t.Substring(t.Length - 4));
  15175. }
  15176. else
  15177. {
  15178. sb.Append(c);
  15179. }
  15180. break;
  15181. }
  15182. }
  15183. if(AddOuter)
  15184. sb.Append("\"");
  15185. return sb.ToString();
  15186. }
  15187. public LSL_String llJsonSetValue(LSL_String json, LSL_List specifiers, LSL_String value)
  15188. {
  15189. bool noSpecifiers = specifiers.Length == 0;
  15190. LitJson.JsonData workData;
  15191. try
  15192. {
  15193. if(noSpecifiers)
  15194. specifiers.Add(new LSL_Integer(0));
  15195. if(!String.IsNullOrEmpty(json))
  15196. workData = LitJson.JsonMapper.ToObject(json);
  15197. else
  15198. {
  15199. workData = new LitJson.JsonData();
  15200. workData.SetJsonType(LitJson.JsonType.Array);
  15201. }
  15202. }
  15203. catch (Exception e)
  15204. {
  15205. string m = e.Message; // debug point
  15206. return ScriptBaseClass.JSON_INVALID;
  15207. }
  15208. try
  15209. {
  15210. LitJson.JsonData replace = JsonSetSpecific(workData, specifiers, 0, value);
  15211. if(replace != null)
  15212. workData = replace;
  15213. }
  15214. catch (Exception e)
  15215. {
  15216. string m = e.Message; // debug point
  15217. return ScriptBaseClass.JSON_INVALID;
  15218. }
  15219. try
  15220. {
  15221. string r = LitJson.JsonMapper.ToJson(workData);
  15222. if(noSpecifiers)
  15223. r = r.Substring(1,r.Length -2); // strip leading and trailing brakets
  15224. return r;
  15225. }
  15226. catch (Exception e)
  15227. {
  15228. string m = e.Message; // debug point
  15229. }
  15230. return ScriptBaseClass.JSON_INVALID;
  15231. }
  15232. private LitJson.JsonData JsonSetSpecific(LitJson.JsonData elem, LSL_List specifiers, int level, LSL_String val)
  15233. {
  15234. object spec = specifiers.Data[level];
  15235. if(spec is LSL_String)
  15236. spec = ((LSL_String)spec).m_string;
  15237. else if (spec is LSL_Integer)
  15238. spec = ((LSL_Integer)spec).value;
  15239. if(!(spec is string || spec is int))
  15240. throw new IndexOutOfRangeException();
  15241. int speclen = specifiers.Data.Length - 1;
  15242. bool hasvalue = false;
  15243. LitJson.JsonData value = null;
  15244. LitJson.JsonType elemType = elem.GetJsonType();
  15245. if (elemType == LitJson.JsonType.Array)
  15246. {
  15247. if (spec is int)
  15248. {
  15249. int v = (int)spec;
  15250. int c = elem.Count;
  15251. if(v < 0 || (v != 0 && v > c))
  15252. throw new IndexOutOfRangeException();
  15253. if(v == c)
  15254. elem.Add(JsonBuildRestOfSpec(specifiers, level + 1, val));
  15255. else
  15256. {
  15257. hasvalue = true;
  15258. value = elem[v];
  15259. }
  15260. }
  15261. else if (spec is string)
  15262. {
  15263. if((string)spec == ScriptBaseClass.JSON_APPEND)
  15264. elem.Add(JsonBuildRestOfSpec(specifiers, level + 1, val));
  15265. else if(elem.Count < 2)
  15266. {
  15267. // our initial guess of array was wrong
  15268. LitJson.JsonData newdata = new LitJson.JsonData();
  15269. newdata.SetJsonType(LitJson.JsonType.Object);
  15270. IOrderedDictionary no = newdata as IOrderedDictionary;
  15271. no.Add((string)spec,JsonBuildRestOfSpec(specifiers, level + 1, val));
  15272. return newdata;
  15273. }
  15274. }
  15275. }
  15276. else if (elemType == LitJson.JsonType.Object)
  15277. {
  15278. if (spec is string)
  15279. {
  15280. IOrderedDictionary e = elem as IOrderedDictionary;
  15281. string key = (string)spec;
  15282. if(e.Contains(key))
  15283. {
  15284. hasvalue = true;
  15285. value = (LitJson.JsonData)e[key];
  15286. }
  15287. else
  15288. e.Add(key, JsonBuildRestOfSpec(specifiers, level + 1, val));
  15289. }
  15290. else if(spec is int && (int)spec == 0)
  15291. {
  15292. //we are replacing a object by a array
  15293. LitJson.JsonData newData = new LitJson.JsonData();
  15294. newData.SetJsonType(LitJson.JsonType.Array);
  15295. newData.Add(JsonBuildRestOfSpec(specifiers, level + 1, val));
  15296. return newData;
  15297. }
  15298. }
  15299. else
  15300. {
  15301. LitJson.JsonData newData = JsonBuildRestOfSpec(specifiers, level, val);
  15302. return newData;
  15303. }
  15304. if (hasvalue)
  15305. {
  15306. if (level < speclen)
  15307. {
  15308. LitJson.JsonData replace = JsonSetSpecific(value, specifiers, level + 1, val);
  15309. if(replace != null)
  15310. {
  15311. if(elemType == LitJson.JsonType.Array)
  15312. {
  15313. if(spec is int)
  15314. elem[(int)spec] = replace;
  15315. else if( spec is string)
  15316. {
  15317. LitJson.JsonData newdata = new LitJson.JsonData();
  15318. newdata.SetJsonType(LitJson.JsonType.Object);
  15319. IOrderedDictionary no = newdata as IOrderedDictionary;
  15320. no.Add((string)spec, replace);
  15321. return newdata;
  15322. }
  15323. }
  15324. else if(elemType == LitJson.JsonType.Object)
  15325. {
  15326. if(spec is string)
  15327. elem[(string)spec] = replace;
  15328. else if(spec is int && (int)spec == 0)
  15329. {
  15330. LitJson.JsonData newdata = new LitJson.JsonData();
  15331. newdata.SetJsonType(LitJson.JsonType.Array);
  15332. newdata.Add(replace);
  15333. return newdata;
  15334. }
  15335. }
  15336. }
  15337. return null;
  15338. }
  15339. else if(speclen == level)
  15340. {
  15341. if(val == ScriptBaseClass.JSON_DELETE)
  15342. {
  15343. if(elemType == LitJson.JsonType.Array)
  15344. {
  15345. if(spec is int)
  15346. {
  15347. IList el = elem as IList;
  15348. el.RemoveAt((int)spec);
  15349. }
  15350. }
  15351. else if(elemType == LitJson.JsonType.Object)
  15352. {
  15353. if(spec is string)
  15354. {
  15355. IOrderedDictionary eo = elem as IOrderedDictionary;
  15356. eo.Remove((string) spec);
  15357. }
  15358. }
  15359. return null;
  15360. }
  15361. LitJson.JsonData newval = null;
  15362. float num;
  15363. if(val == null || val == ScriptBaseClass.JSON_NULL || val == "null")
  15364. newval = null;
  15365. else if(val == ScriptBaseClass.JSON_TRUE || val == "true")
  15366. newval = new LitJson.JsonData(true);
  15367. else if(val == ScriptBaseClass.JSON_FALSE || val == "false")
  15368. newval = new LitJson.JsonData(false);
  15369. else if(float.TryParse(val, out num))
  15370. {
  15371. // assuming we are at en.us already
  15372. if(num - (int)num == 0.0f && !val.Contains("."))
  15373. newval = new LitJson.JsonData((int)num);
  15374. else
  15375. {
  15376. num = (float)Math.Round(num,6);
  15377. newval = new LitJson.JsonData((double)num);
  15378. }
  15379. }
  15380. else
  15381. {
  15382. string str = val.m_string;
  15383. newval = new LitJson.JsonData(str);
  15384. }
  15385. if(elemType == LitJson.JsonType.Array)
  15386. {
  15387. if(spec is int)
  15388. elem[(int)spec] = newval;
  15389. else if( spec is string)
  15390. {
  15391. LitJson.JsonData newdata = new LitJson.JsonData();
  15392. newdata.SetJsonType(LitJson.JsonType.Object);
  15393. IOrderedDictionary no = newdata as IOrderedDictionary;
  15394. no.Add((string)spec,newval);
  15395. return newdata;
  15396. }
  15397. }
  15398. else if(elemType == LitJson.JsonType.Object)
  15399. {
  15400. if(spec is string)
  15401. elem[(string)spec] = newval;
  15402. else if(spec is int && (int)spec == 0)
  15403. {
  15404. LitJson.JsonData newdata = new LitJson.JsonData();
  15405. newdata.SetJsonType(LitJson.JsonType.Array);
  15406. newdata.Add(newval);
  15407. return newdata;
  15408. }
  15409. }
  15410. }
  15411. }
  15412. if(val == ScriptBaseClass.JSON_DELETE)
  15413. throw new IndexOutOfRangeException();
  15414. return null;
  15415. }
  15416. private LitJson.JsonData JsonBuildRestOfSpec(LSL_List specifiers, int level, LSL_String val)
  15417. {
  15418. object spec = level >= specifiers.Data.Length ? null : specifiers.Data[level];
  15419. // 20131224 not used object specNext = i+1 >= specifiers.Data.Length ? null : specifiers.Data[i+1];
  15420. float num;
  15421. if (spec == null)
  15422. {
  15423. if(val == null || val == ScriptBaseClass.JSON_NULL || val == "null")
  15424. return null;
  15425. if(val == ScriptBaseClass.JSON_DELETE)
  15426. throw new IndexOutOfRangeException();
  15427. if(val == ScriptBaseClass.JSON_TRUE || val == "true")
  15428. return new LitJson.JsonData(true);
  15429. if(val == ScriptBaseClass.JSON_FALSE || val == "false")
  15430. return new LitJson.JsonData(false);
  15431. if(val == null || val == ScriptBaseClass.JSON_NULL || val == "null")
  15432. return null;
  15433. if(float.TryParse(val, out num))
  15434. {
  15435. // assuming we are at en.us already
  15436. if(num - (int)num == 0.0f && !val.Contains("."))
  15437. return new LitJson.JsonData((int)num);
  15438. else
  15439. {
  15440. num = (float)Math.Round(num,6);
  15441. return new LitJson.JsonData(num);
  15442. }
  15443. }
  15444. else
  15445. {
  15446. string str = val.m_string;
  15447. return new LitJson.JsonData(str);
  15448. }
  15449. throw new IndexOutOfRangeException();
  15450. }
  15451. if(spec is LSL_String)
  15452. spec = ((LSL_String)spec).m_string;
  15453. else if (spec is LSL_Integer)
  15454. spec = ((LSL_Integer)spec).value;
  15455. if (spec is int ||
  15456. (spec is string && ((string)spec) == ScriptBaseClass.JSON_APPEND) )
  15457. {
  15458. if(spec is int && (int)spec != 0)
  15459. throw new IndexOutOfRangeException();
  15460. LitJson.JsonData newdata = new LitJson.JsonData();
  15461. newdata.SetJsonType(LitJson.JsonType.Array);
  15462. newdata.Add(JsonBuildRestOfSpec(specifiers, level + 1, val));
  15463. return newdata;
  15464. }
  15465. else if (spec is string)
  15466. {
  15467. LitJson.JsonData newdata = new LitJson.JsonData();
  15468. newdata.SetJsonType(LitJson.JsonType.Object);
  15469. IOrderedDictionary no = newdata as IOrderedDictionary;
  15470. no.Add((string)spec,JsonBuildRestOfSpec(specifiers, level + 1, val));
  15471. return newdata;
  15472. }
  15473. throw new IndexOutOfRangeException();
  15474. }
  15475. private bool JsonFind(LitJson.JsonData elem, LSL_List specifiers, int level, out LitJson.JsonData value)
  15476. {
  15477. value = null;
  15478. if(elem == null)
  15479. return false;
  15480. object spec;
  15481. spec = specifiers.Data[level];
  15482. bool haveVal = false;
  15483. LitJson.JsonData next = null;
  15484. if (elem.GetJsonType() == LitJson.JsonType.Array)
  15485. {
  15486. if (spec is LSL_Integer)
  15487. {
  15488. int indx = (LSL_Integer)spec;
  15489. if(indx >= 0 && indx < elem.Count)
  15490. {
  15491. haveVal = true;
  15492. next = (LitJson.JsonData)elem[indx];
  15493. }
  15494. }
  15495. }
  15496. else if (elem.GetJsonType() == LitJson.JsonType.Object)
  15497. {
  15498. if (spec is LSL_String)
  15499. {
  15500. IOrderedDictionary e = elem as IOrderedDictionary;
  15501. string key = (LSL_String)spec;
  15502. if(e.Contains(key))
  15503. {
  15504. haveVal = true;
  15505. next = (LitJson.JsonData)e[key];
  15506. }
  15507. }
  15508. }
  15509. if (haveVal)
  15510. {
  15511. if(level == specifiers.Data.Length - 1)
  15512. {
  15513. value = next;
  15514. return true;
  15515. }
  15516. level++;
  15517. if(next == null)
  15518. return false;
  15519. LitJson.JsonType nextType = next.GetJsonType();
  15520. if(nextType != LitJson.JsonType.Object && nextType != LitJson.JsonType.Array)
  15521. return false;
  15522. return JsonFind(next, specifiers, level, out value);
  15523. }
  15524. return false;
  15525. }
  15526. public LSL_String llJsonGetValue(LSL_String json, LSL_List specifiers)
  15527. {
  15528. if(String.IsNullOrWhiteSpace(json))
  15529. return ScriptBaseClass.JSON_INVALID;
  15530. if(specifiers.Length > 0 && (json == "{}" || json == "[]"))
  15531. return ScriptBaseClass.JSON_INVALID;
  15532. char first = ((string)json)[0];
  15533. if((first != '[' && first !='{'))
  15534. {
  15535. if(specifiers.Length > 0)
  15536. return ScriptBaseClass.JSON_INVALID;
  15537. json = "[" + json + "]"; // could handle single element case.. but easier like this
  15538. specifiers.Add((LSL_Integer)0);
  15539. }
  15540. LitJson.JsonData jsonData;
  15541. try
  15542. {
  15543. jsonData = LitJson.JsonMapper.ToObject(json);
  15544. }
  15545. catch (Exception e)
  15546. {
  15547. string m = e.Message; // debug point
  15548. return ScriptBaseClass.JSON_INVALID;
  15549. }
  15550. LitJson.JsonData elem = null;
  15551. if(specifiers.Length == 0)
  15552. elem = jsonData;
  15553. else
  15554. {
  15555. if(!JsonFind(jsonData, specifiers, 0, out elem))
  15556. return ScriptBaseClass.JSON_INVALID;
  15557. }
  15558. return JsonElementToString(elem);
  15559. }
  15560. private LSL_String JsonElementToString(LitJson.JsonData elem)
  15561. {
  15562. if(elem == null)
  15563. return ScriptBaseClass.JSON_NULL;
  15564. LitJson.JsonType elemType = elem.GetJsonType();
  15565. switch(elemType)
  15566. {
  15567. case LitJson.JsonType.Array:
  15568. return new LSL_String(LitJson.JsonMapper.ToJson(elem));
  15569. case LitJson.JsonType.Boolean:
  15570. return new LSL_String((bool)elem ? ScriptBaseClass.JSON_TRUE : ScriptBaseClass.JSON_FALSE);
  15571. case LitJson.JsonType.Double:
  15572. double d= (double)elem;
  15573. string sd = String.Format(Culture.FormatProvider, "{0:0.0#####}",d);
  15574. return new LSL_String(sd);
  15575. case LitJson.JsonType.Int:
  15576. int i = (int)elem;
  15577. return new LSL_String(i.ToString());
  15578. case LitJson.JsonType.Long:
  15579. long l = (long)elem;
  15580. return new LSL_String(l.ToString());
  15581. case LitJson.JsonType.Object:
  15582. return new LSL_String(LitJson.JsonMapper.ToJson(elem));
  15583. case LitJson.JsonType.String:
  15584. string s = (string)elem;
  15585. return new LSL_String(s);
  15586. case LitJson.JsonType.None:
  15587. return ScriptBaseClass.JSON_NULL;
  15588. default:
  15589. return ScriptBaseClass.JSON_INVALID;
  15590. }
  15591. }
  15592. public LSL_String llJsonValueType(LSL_String json, LSL_List specifiers)
  15593. {
  15594. if(String.IsNullOrWhiteSpace(json))
  15595. return ScriptBaseClass.JSON_INVALID;
  15596. if(specifiers.Length > 0 && (json == "{}" || json == "[]"))
  15597. return ScriptBaseClass.JSON_INVALID;
  15598. char first = ((string)json)[0];
  15599. if((first != '[' && first !='{'))
  15600. {
  15601. if(specifiers.Length > 0)
  15602. return ScriptBaseClass.JSON_INVALID;
  15603. json = "[" + json + "]"; // could handle single element case.. but easier like this
  15604. specifiers.Add((LSL_Integer)0);
  15605. }
  15606. LitJson.JsonData jsonData;
  15607. try
  15608. {
  15609. jsonData = LitJson.JsonMapper.ToObject(json);
  15610. }
  15611. catch (Exception e)
  15612. {
  15613. string m = e.Message; // debug point
  15614. return ScriptBaseClass.JSON_INVALID;
  15615. }
  15616. LitJson.JsonData elem = null;
  15617. if(specifiers.Length == 0)
  15618. elem = jsonData;
  15619. else
  15620. {
  15621. if(!JsonFind(jsonData, specifiers, 0, out elem))
  15622. return ScriptBaseClass.JSON_INVALID;
  15623. }
  15624. if(elem == null)
  15625. return ScriptBaseClass.JSON_NULL;
  15626. LitJson.JsonType elemType = elem.GetJsonType();
  15627. switch(elemType)
  15628. {
  15629. case LitJson.JsonType.Array:
  15630. return ScriptBaseClass.JSON_ARRAY;
  15631. case LitJson.JsonType.Boolean:
  15632. return (bool)elem ? ScriptBaseClass.JSON_TRUE : ScriptBaseClass.JSON_FALSE;
  15633. case LitJson.JsonType.Double:
  15634. case LitJson.JsonType.Int:
  15635. case LitJson.JsonType.Long:
  15636. return ScriptBaseClass.JSON_NUMBER;
  15637. case LitJson.JsonType.Object:
  15638. return ScriptBaseClass.JSON_OBJECT;
  15639. case LitJson.JsonType.String:
  15640. string s = (string)elem;
  15641. if(s == ScriptBaseClass.JSON_NULL)
  15642. return ScriptBaseClass.JSON_NULL;
  15643. if(s == ScriptBaseClass.JSON_TRUE)
  15644. return ScriptBaseClass.JSON_TRUE;
  15645. if(s == ScriptBaseClass.JSON_FALSE)
  15646. return ScriptBaseClass.JSON_FALSE;
  15647. return ScriptBaseClass.JSON_STRING;
  15648. case LitJson.JsonType.None:
  15649. return ScriptBaseClass.JSON_NULL;
  15650. default:
  15651. return ScriptBaseClass.JSON_INVALID;
  15652. }
  15653. }
  15654. }
  15655. public class NotecardCache
  15656. {
  15657. protected class Notecard
  15658. {
  15659. public string[] text;
  15660. public DateTime lastRef;
  15661. }
  15662. private static Dictionary<UUID, Notecard> m_Notecards =
  15663. new Dictionary<UUID, Notecard>();
  15664. public static void Cache(UUID assetID, byte[] text)
  15665. {
  15666. CheckCache();
  15667. lock (m_Notecards)
  15668. {
  15669. if (m_Notecards.ContainsKey(assetID))
  15670. return;
  15671. Notecard nc = new Notecard();
  15672. nc.lastRef = DateTime.Now;
  15673. try
  15674. {
  15675. nc.text = SLUtil.ParseNotecardToArray(text);
  15676. }
  15677. catch(SLUtil.NotANotecardFormatException)
  15678. {
  15679. nc.text = new string[0];
  15680. }
  15681. m_Notecards[assetID] = nc;
  15682. }
  15683. }
  15684. public static bool IsCached(UUID assetID)
  15685. {
  15686. lock (m_Notecards)
  15687. {
  15688. return m_Notecards.ContainsKey(assetID);
  15689. }
  15690. }
  15691. public static int GetLines(UUID assetID)
  15692. {
  15693. if (!IsCached(assetID))
  15694. return -1;
  15695. lock (m_Notecards)
  15696. {
  15697. m_Notecards[assetID].lastRef = DateTime.Now;
  15698. return m_Notecards[assetID].text.Length;
  15699. }
  15700. }
  15701. /// <summary>
  15702. /// Get a notecard line.
  15703. /// </summary>
  15704. /// <param name="assetID"></param>
  15705. /// <param name="lineNumber">Lines start at index 0</param>
  15706. /// <returns></returns>
  15707. public static string GetLine(UUID assetID, int lineNumber)
  15708. {
  15709. if (lineNumber < 0)
  15710. return "";
  15711. string data;
  15712. if (!IsCached(assetID))
  15713. return "";
  15714. lock (m_Notecards)
  15715. {
  15716. m_Notecards[assetID].lastRef = DateTime.Now;
  15717. if (lineNumber >= m_Notecards[assetID].text.Length)
  15718. return "\n\n\n";
  15719. data = m_Notecards[assetID].text[lineNumber];
  15720. return data;
  15721. }
  15722. }
  15723. /// <summary>
  15724. /// Get a notecard line.
  15725. /// </summary>
  15726. /// <param name="assetID"></param>
  15727. /// <param name="lineNumber">Lines start at index 0</param>
  15728. /// <param name="maxLength">
  15729. /// Maximum length of the returned line.
  15730. /// </param>
  15731. /// <returns>
  15732. /// If the line length is longer than <paramref name="maxLength"/>,
  15733. /// the return string will be truncated.
  15734. /// </returns>
  15735. public static string GetLine(UUID assetID, int lineNumber, int maxLength)
  15736. {
  15737. string line = GetLine(assetID, lineNumber);
  15738. if (line.Length > maxLength)
  15739. line = line.Substring(0, maxLength);
  15740. return line;
  15741. }
  15742. public static void CheckCache()
  15743. {
  15744. lock (m_Notecards)
  15745. {
  15746. foreach (UUID key in new List<UUID>(m_Notecards.Keys))
  15747. {
  15748. Notecard nc = m_Notecards[key];
  15749. if (nc.lastRef.AddSeconds(30) < DateTime.Now)
  15750. m_Notecards.Remove(key);
  15751. }
  15752. }
  15753. }
  15754. }
  15755. }