LSL_Api.cs 598 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617961896199620962196229623962496259626962796289629963096319632963396349635963696379638963996409641964296439644964596469647964896499650965196529653965496559656965796589659966096619662966396649665966696679668966996709671967296739674967596769677967896799680968196829683968496859686968796889689969096919692969396949695969696979698969997009701970297039704970597069707970897099710971197129713971497159716971797189719972097219722972397249725972697279728972997309731973297339734973597369737973897399740974197429743974497459746974797489749975097519752975397549755975697579758975997609761976297639764976597669767976897699770977197729773977497759776977797789779978097819782978397849785978697879788978997909791979297939794979597969797979897999800980198029803980498059806980798089809981098119812981398149815981698179818981998209821982298239824982598269827982898299830983198329833983498359836983798389839984098419842984398449845984698479848984998509851985298539854985598569857985898599860986198629863986498659866986798689869987098719872987398749875987698779878987998809881988298839884988598869887988898899890989198929893989498959896989798989899990099019902990399049905990699079908990999109911991299139914991599169917991899199920992199229923992499259926992799289929993099319932993399349935993699379938993999409941994299439944994599469947994899499950995199529953995499559956995799589959996099619962996399649965996699679968996999709971997299739974997599769977997899799980998199829983998499859986998799889989999099919992999399949995999699979998999910000100011000210003100041000510006100071000810009100101001110012100131001410015100161001710018100191002010021100221002310024100251002610027100281002910030100311003210033100341003510036100371003810039100401004110042100431004410045100461004710048100491005010051100521005310054100551005610057100581005910060100611006210063100641006510066100671006810069100701007110072100731007410075100761007710078100791008010081100821008310084100851008610087100881008910090100911009210093100941009510096100971009810099101001010110102101031010410105101061010710108101091011010111101121011310114101151011610117101181011910120101211012210123101241012510126101271012810129101301013110132101331013410135101361013710138101391014010141101421014310144101451014610147101481014910150101511015210153101541015510156101571015810159101601016110162101631016410165101661016710168101691017010171101721017310174101751017610177101781017910180101811018210183101841018510186101871018810189101901019110192101931019410195101961019710198101991020010201102021020310204102051020610207102081020910210102111021210213102141021510216102171021810219102201022110222102231022410225102261022710228102291023010231102321023310234102351023610237102381023910240102411024210243102441024510246102471024810249102501025110252102531025410255102561025710258102591026010261102621026310264102651026610267102681026910270102711027210273102741027510276102771027810279102801028110282102831028410285102861028710288102891029010291102921029310294102951029610297102981029910300103011030210303103041030510306103071030810309103101031110312103131031410315103161031710318103191032010321103221032310324103251032610327103281032910330103311033210333103341033510336103371033810339103401034110342103431034410345103461034710348103491035010351103521035310354103551035610357103581035910360103611036210363103641036510366103671036810369103701037110372103731037410375103761037710378103791038010381103821038310384103851038610387103881038910390103911039210393103941039510396103971039810399104001040110402104031040410405104061040710408104091041010411104121041310414104151041610417104181041910420104211042210423104241042510426104271042810429104301043110432104331043410435104361043710438104391044010441104421044310444104451044610447104481044910450104511045210453104541045510456104571045810459104601046110462104631046410465104661046710468104691047010471104721047310474104751047610477104781047910480104811048210483104841048510486104871048810489104901049110492104931049410495104961049710498104991050010501105021050310504105051050610507105081050910510105111051210513105141051510516105171051810519105201052110522105231052410525105261052710528105291053010531105321053310534105351053610537105381053910540105411054210543105441054510546105471054810549105501055110552105531055410555105561055710558105591056010561105621056310564105651056610567105681056910570105711057210573105741057510576105771057810579105801058110582105831058410585105861058710588105891059010591105921059310594105951059610597105981059910600106011060210603106041060510606106071060810609106101061110612106131061410615106161061710618106191062010621106221062310624106251062610627106281062910630106311063210633106341063510636106371063810639106401064110642106431064410645106461064710648106491065010651106521065310654106551065610657106581065910660106611066210663106641066510666106671066810669106701067110672106731067410675106761067710678106791068010681106821068310684106851068610687106881068910690106911069210693106941069510696106971069810699107001070110702107031070410705107061070710708107091071010711107121071310714107151071610717107181071910720107211072210723107241072510726107271072810729107301073110732107331073410735107361073710738107391074010741107421074310744107451074610747107481074910750107511075210753107541075510756107571075810759107601076110762107631076410765107661076710768107691077010771107721077310774107751077610777107781077910780107811078210783107841078510786107871078810789107901079110792107931079410795107961079710798107991080010801108021080310804108051080610807108081080910810108111081210813108141081510816108171081810819108201082110822108231082410825108261082710828108291083010831108321083310834108351083610837108381083910840108411084210843108441084510846108471084810849108501085110852108531085410855108561085710858108591086010861108621086310864108651086610867108681086910870108711087210873108741087510876108771087810879108801088110882108831088410885108861088710888108891089010891108921089310894108951089610897108981089910900109011090210903109041090510906109071090810909109101091110912109131091410915109161091710918109191092010921109221092310924109251092610927109281092910930109311093210933109341093510936109371093810939109401094110942109431094410945109461094710948109491095010951109521095310954109551095610957109581095910960109611096210963109641096510966109671096810969109701097110972109731097410975109761097710978109791098010981109821098310984109851098610987109881098910990109911099210993109941099510996109971099810999110001100111002110031100411005110061100711008110091101011011110121101311014110151101611017110181101911020110211102211023110241102511026110271102811029110301103111032110331103411035110361103711038110391104011041110421104311044110451104611047110481104911050110511105211053110541105511056110571105811059110601106111062110631106411065110661106711068110691107011071110721107311074110751107611077110781107911080110811108211083110841108511086110871108811089110901109111092110931109411095110961109711098110991110011101111021110311104111051110611107111081110911110111111111211113111141111511116111171111811119111201112111122111231112411125111261112711128111291113011131111321113311134111351113611137111381113911140111411114211143111441114511146111471114811149111501115111152111531115411155111561115711158111591116011161111621116311164111651116611167111681116911170111711117211173111741117511176111771117811179111801118111182111831118411185111861118711188111891119011191111921119311194111951119611197111981119911200112011120211203112041120511206112071120811209112101121111212112131121411215112161121711218112191122011221112221122311224112251122611227112281122911230112311123211233112341123511236112371123811239112401124111242112431124411245112461124711248112491125011251112521125311254112551125611257112581125911260112611126211263112641126511266112671126811269112701127111272112731127411275112761127711278112791128011281112821128311284112851128611287112881128911290112911129211293112941129511296112971129811299113001130111302113031130411305113061130711308113091131011311113121131311314113151131611317113181131911320113211132211323113241132511326113271132811329113301133111332113331133411335113361133711338113391134011341113421134311344113451134611347113481134911350113511135211353113541135511356113571135811359113601136111362113631136411365113661136711368113691137011371113721137311374113751137611377113781137911380113811138211383113841138511386113871138811389113901139111392113931139411395113961139711398113991140011401114021140311404114051140611407114081140911410114111141211413114141141511416114171141811419114201142111422114231142411425114261142711428114291143011431114321143311434114351143611437114381143911440114411144211443114441144511446114471144811449114501145111452114531145411455114561145711458114591146011461114621146311464114651146611467114681146911470114711147211473114741147511476114771147811479114801148111482114831148411485114861148711488114891149011491114921149311494114951149611497114981149911500115011150211503115041150511506115071150811509115101151111512115131151411515115161151711518115191152011521115221152311524115251152611527115281152911530115311153211533115341153511536115371153811539115401154111542115431154411545115461154711548115491155011551115521155311554115551155611557115581155911560115611156211563115641156511566115671156811569115701157111572115731157411575115761157711578115791158011581115821158311584115851158611587115881158911590115911159211593115941159511596115971159811599116001160111602116031160411605116061160711608116091161011611116121161311614116151161611617116181161911620116211162211623116241162511626116271162811629116301163111632116331163411635116361163711638116391164011641116421164311644116451164611647116481164911650116511165211653116541165511656116571165811659116601166111662116631166411665116661166711668116691167011671116721167311674116751167611677116781167911680116811168211683116841168511686116871168811689116901169111692116931169411695116961169711698116991170011701117021170311704117051170611707117081170911710117111171211713117141171511716117171171811719117201172111722117231172411725117261172711728117291173011731117321173311734117351173611737117381173911740117411174211743117441174511746117471174811749117501175111752117531175411755117561175711758117591176011761117621176311764117651176611767117681176911770117711177211773117741177511776117771177811779117801178111782117831178411785117861178711788117891179011791117921179311794117951179611797117981179911800118011180211803118041180511806118071180811809118101181111812118131181411815118161181711818118191182011821118221182311824118251182611827118281182911830118311183211833118341183511836118371183811839118401184111842118431184411845118461184711848118491185011851118521185311854118551185611857118581185911860118611186211863118641186511866118671186811869118701187111872118731187411875118761187711878118791188011881118821188311884118851188611887118881188911890118911189211893118941189511896118971189811899119001190111902119031190411905119061190711908119091191011911119121191311914119151191611917119181191911920119211192211923119241192511926119271192811929119301193111932119331193411935119361193711938119391194011941119421194311944119451194611947119481194911950119511195211953119541195511956119571195811959119601196111962119631196411965119661196711968119691197011971119721197311974119751197611977119781197911980119811198211983119841198511986119871198811989119901199111992119931199411995119961199711998119991200012001120021200312004120051200612007120081200912010120111201212013120141201512016120171201812019120201202112022120231202412025120261202712028120291203012031120321203312034120351203612037120381203912040120411204212043120441204512046120471204812049120501205112052120531205412055120561205712058120591206012061120621206312064120651206612067120681206912070120711207212073120741207512076120771207812079120801208112082120831208412085120861208712088120891209012091120921209312094120951209612097120981209912100121011210212103121041210512106121071210812109121101211112112121131211412115121161211712118121191212012121121221212312124121251212612127121281212912130121311213212133121341213512136121371213812139121401214112142121431214412145121461214712148121491215012151121521215312154121551215612157121581215912160121611216212163121641216512166121671216812169121701217112172121731217412175121761217712178121791218012181121821218312184121851218612187121881218912190121911219212193121941219512196121971219812199122001220112202122031220412205122061220712208122091221012211122121221312214122151221612217122181221912220122211222212223122241222512226122271222812229122301223112232122331223412235122361223712238122391224012241122421224312244122451224612247122481224912250122511225212253122541225512256122571225812259122601226112262122631226412265122661226712268122691227012271122721227312274122751227612277122781227912280122811228212283122841228512286122871228812289122901229112292122931229412295122961229712298122991230012301123021230312304123051230612307123081230912310123111231212313123141231512316123171231812319123201232112322123231232412325123261232712328123291233012331123321233312334123351233612337123381233912340123411234212343123441234512346123471234812349123501235112352123531235412355123561235712358123591236012361123621236312364123651236612367123681236912370123711237212373123741237512376123771237812379123801238112382123831238412385123861238712388123891239012391123921239312394123951239612397123981239912400124011240212403124041240512406124071240812409124101241112412124131241412415124161241712418124191242012421124221242312424124251242612427124281242912430124311243212433124341243512436124371243812439124401244112442124431244412445124461244712448124491245012451124521245312454124551245612457124581245912460124611246212463124641246512466124671246812469124701247112472124731247412475124761247712478124791248012481124821248312484124851248612487124881248912490124911249212493124941249512496124971249812499125001250112502125031250412505125061250712508125091251012511125121251312514125151251612517125181251912520125211252212523125241252512526125271252812529125301253112532125331253412535125361253712538125391254012541125421254312544125451254612547125481254912550125511255212553125541255512556125571255812559125601256112562125631256412565125661256712568125691257012571125721257312574125751257612577125781257912580125811258212583125841258512586125871258812589125901259112592125931259412595125961259712598125991260012601126021260312604126051260612607126081260912610126111261212613126141261512616126171261812619126201262112622126231262412625126261262712628126291263012631126321263312634126351263612637126381263912640126411264212643126441264512646126471264812649126501265112652126531265412655126561265712658126591266012661126621266312664126651266612667126681266912670126711267212673126741267512676126771267812679126801268112682126831268412685126861268712688126891269012691126921269312694126951269612697126981269912700127011270212703127041270512706127071270812709127101271112712127131271412715127161271712718127191272012721127221272312724127251272612727127281272912730127311273212733127341273512736127371273812739127401274112742127431274412745127461274712748127491275012751127521275312754127551275612757127581275912760127611276212763127641276512766127671276812769127701277112772127731277412775127761277712778127791278012781127821278312784127851278612787127881278912790127911279212793127941279512796127971279812799128001280112802128031280412805128061280712808128091281012811128121281312814128151281612817128181281912820128211282212823128241282512826128271282812829128301283112832128331283412835128361283712838128391284012841128421284312844128451284612847128481284912850128511285212853128541285512856128571285812859128601286112862128631286412865128661286712868128691287012871128721287312874128751287612877128781287912880128811288212883128841288512886128871288812889128901289112892128931289412895128961289712898128991290012901129021290312904129051290612907129081290912910129111291212913129141291512916129171291812919129201292112922129231292412925129261292712928129291293012931129321293312934129351293612937129381293912940129411294212943129441294512946129471294812949129501295112952129531295412955129561295712958129591296012961129621296312964129651296612967129681296912970129711297212973129741297512976129771297812979129801298112982129831298412985129861298712988129891299012991129921299312994129951299612997129981299913000130011300213003130041300513006130071300813009130101301113012130131301413015130161301713018130191302013021130221302313024130251302613027130281302913030130311303213033130341303513036130371303813039130401304113042130431304413045130461304713048130491305013051130521305313054130551305613057130581305913060130611306213063130641306513066130671306813069130701307113072130731307413075130761307713078130791308013081130821308313084130851308613087130881308913090130911309213093130941309513096130971309813099131001310113102131031310413105131061310713108131091311013111131121311313114131151311613117131181311913120131211312213123131241312513126131271312813129131301313113132131331313413135131361313713138131391314013141131421314313144131451314613147131481314913150131511315213153131541315513156131571315813159131601316113162131631316413165131661316713168131691317013171131721317313174131751317613177131781317913180131811318213183131841318513186131871318813189131901319113192131931319413195131961319713198131991320013201132021320313204132051320613207132081320913210132111321213213132141321513216132171321813219132201322113222132231322413225132261322713228132291323013231132321323313234132351323613237132381323913240132411324213243132441324513246132471324813249132501325113252132531325413255132561325713258132591326013261132621326313264132651326613267132681326913270132711327213273132741327513276132771327813279132801328113282132831328413285132861328713288132891329013291132921329313294132951329613297132981329913300133011330213303133041330513306133071330813309133101331113312133131331413315133161331713318133191332013321133221332313324133251332613327133281332913330133311333213333133341333513336133371333813339133401334113342133431334413345133461334713348133491335013351133521335313354133551335613357133581335913360133611336213363133641336513366133671336813369133701337113372133731337413375133761337713378133791338013381133821338313384133851338613387133881338913390133911339213393133941339513396133971339813399134001340113402134031340413405134061340713408134091341013411134121341313414134151341613417134181341913420134211342213423134241342513426134271342813429134301343113432134331343413435134361343713438134391344013441134421344313444134451344613447134481344913450134511345213453134541345513456134571345813459134601346113462134631346413465134661346713468134691347013471134721347313474134751347613477134781347913480134811348213483134841348513486134871348813489134901349113492134931349413495134961349713498134991350013501135021350313504135051350613507135081350913510135111351213513135141351513516135171351813519135201352113522135231352413525135261352713528135291353013531135321353313534135351353613537135381353913540135411354213543135441354513546135471354813549135501355113552135531355413555135561355713558135591356013561135621356313564135651356613567135681356913570135711357213573135741357513576135771357813579135801358113582135831358413585135861358713588135891359013591135921359313594135951359613597135981359913600136011360213603136041360513606136071360813609136101361113612136131361413615136161361713618136191362013621136221362313624136251362613627136281362913630136311363213633136341363513636136371363813639136401364113642136431364413645136461364713648136491365013651136521365313654136551365613657136581365913660136611366213663136641366513666136671366813669136701367113672136731367413675136761367713678136791368013681136821368313684136851368613687136881368913690136911369213693136941369513696136971369813699137001370113702137031370413705137061370713708137091371013711137121371313714137151371613717137181371913720137211372213723137241372513726137271372813729137301373113732137331373413735137361373713738137391374013741137421374313744137451374613747137481374913750137511375213753137541375513756137571375813759137601376113762137631376413765137661376713768137691377013771137721377313774137751377613777137781377913780137811378213783137841378513786137871378813789137901379113792137931379413795137961379713798137991380013801138021380313804138051380613807138081380913810138111381213813138141381513816138171381813819138201382113822138231382413825138261382713828138291383013831138321383313834138351383613837138381383913840138411384213843138441384513846138471384813849138501385113852138531385413855138561385713858138591386013861138621386313864138651386613867138681386913870138711387213873138741387513876138771387813879138801388113882138831388413885138861388713888138891389013891138921389313894138951389613897138981389913900139011390213903139041390513906139071390813909139101391113912139131391413915139161391713918139191392013921139221392313924139251392613927139281392913930139311393213933139341393513936139371393813939139401394113942139431394413945139461394713948139491395013951139521395313954139551395613957139581395913960139611396213963139641396513966139671396813969139701397113972139731397413975139761397713978139791398013981139821398313984139851398613987139881398913990139911399213993139941399513996139971399813999140001400114002140031400414005140061400714008140091401014011140121401314014140151401614017140181401914020140211402214023140241402514026140271402814029140301403114032140331403414035140361403714038140391404014041140421404314044140451404614047140481404914050140511405214053140541405514056140571405814059140601406114062140631406414065140661406714068140691407014071140721407314074140751407614077140781407914080140811408214083140841408514086140871408814089140901409114092140931409414095140961409714098140991410014101141021410314104141051410614107141081410914110141111411214113141141411514116141171411814119141201412114122141231412414125141261412714128141291413014131141321413314134141351413614137141381413914140141411414214143141441414514146141471414814149141501415114152141531415414155141561415714158141591416014161141621416314164141651416614167141681416914170141711417214173141741417514176141771417814179141801418114182141831418414185141861418714188141891419014191141921419314194141951419614197141981419914200142011420214203142041420514206142071420814209142101421114212142131421414215142161421714218142191422014221142221422314224142251422614227142281422914230142311423214233142341423514236142371423814239142401424114242142431424414245142461424714248142491425014251142521425314254142551425614257142581425914260142611426214263142641426514266142671426814269142701427114272142731427414275142761427714278142791428014281142821428314284142851428614287142881428914290142911429214293142941429514296142971429814299143001430114302143031430414305143061430714308143091431014311143121431314314143151431614317143181431914320143211432214323143241432514326143271432814329143301433114332143331433414335143361433714338143391434014341143421434314344143451434614347143481434914350143511435214353143541435514356143571435814359143601436114362143631436414365143661436714368143691437014371143721437314374143751437614377143781437914380143811438214383143841438514386143871438814389143901439114392143931439414395143961439714398143991440014401144021440314404144051440614407144081440914410144111441214413144141441514416144171441814419144201442114422144231442414425144261442714428144291443014431144321443314434144351443614437144381443914440144411444214443144441444514446144471444814449144501445114452144531445414455144561445714458144591446014461144621446314464144651446614467144681446914470144711447214473144741447514476144771447814479144801448114482144831448414485144861448714488144891449014491144921449314494144951449614497144981449914500145011450214503145041450514506145071450814509145101451114512145131451414515145161451714518145191452014521145221452314524145251452614527145281452914530145311453214533145341453514536145371453814539145401454114542145431454414545145461454714548145491455014551145521455314554145551455614557145581455914560145611456214563145641456514566145671456814569145701457114572145731457414575145761457714578145791458014581145821458314584145851458614587145881458914590145911459214593145941459514596145971459814599146001460114602146031460414605146061460714608146091461014611146121461314614146151461614617146181461914620146211462214623146241462514626146271462814629146301463114632146331463414635146361463714638146391464014641146421464314644146451464614647146481464914650146511465214653146541465514656146571465814659146601466114662146631466414665146661466714668146691467014671146721467314674146751467614677146781467914680146811468214683146841468514686146871468814689146901469114692146931469414695146961469714698146991470014701147021470314704147051470614707147081470914710147111471214713147141471514716147171471814719147201472114722147231472414725147261472714728147291473014731147321473314734147351473614737147381473914740147411474214743147441474514746147471474814749147501475114752147531475414755147561475714758147591476014761147621476314764147651476614767147681476914770147711477214773147741477514776147771477814779147801478114782147831478414785147861478714788147891479014791147921479314794147951479614797147981479914800148011480214803148041480514806148071480814809148101481114812148131481414815148161481714818148191482014821148221482314824148251482614827148281482914830148311483214833148341483514836148371483814839148401484114842148431484414845148461484714848148491485014851148521485314854148551485614857148581485914860148611486214863148641486514866148671486814869148701487114872148731487414875148761487714878148791488014881148821488314884148851488614887148881488914890148911489214893148941489514896148971489814899149001490114902149031490414905149061490714908149091491014911149121491314914149151491614917149181491914920149211492214923149241492514926149271492814929149301493114932149331493414935149361493714938149391494014941149421494314944149451494614947149481494914950149511495214953149541495514956149571495814959149601496114962149631496414965149661496714968149691497014971149721497314974149751497614977149781497914980149811498214983149841498514986149871498814989149901499114992149931499414995149961499714998149991500015001150021500315004150051500615007150081500915010150111501215013150141501515016150171501815019150201502115022150231502415025150261502715028150291503015031150321503315034150351503615037150381503915040150411504215043150441504515046150471504815049150501505115052150531505415055150561505715058150591506015061
  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.Drawing;
  31. using System.Drawing.Imaging;
  32. using System.Runtime.Remoting.Lifetime;
  33. using System.Text;
  34. using System.Threading;
  35. using System.Text.RegularExpressions;
  36. using Nini.Config;
  37. using log4net;
  38. using OpenMetaverse;
  39. using OpenMetaverse.Assets;
  40. using OpenMetaverse.Packets;
  41. using OpenMetaverse.Rendering;
  42. using OpenSim;
  43. using OpenSim.Framework;
  44. using OpenSim.Region.CoreModules;
  45. using OpenSim.Region.CoreModules.World.Land;
  46. using OpenSim.Region.CoreModules.World.Terrain;
  47. using OpenSim.Region.Framework.Interfaces;
  48. using OpenSim.Region.Framework.Scenes;
  49. using OpenSim.Region.Framework.Scenes.Animation;
  50. using OpenSim.Region.Framework.Scenes.Scripting;
  51. using OpenSim.Region.Physics.Manager;
  52. using OpenSim.Region.ScriptEngine.Shared;
  53. using OpenSim.Region.ScriptEngine.Shared.Api.Plugins;
  54. using OpenSim.Region.ScriptEngine.Shared.ScriptBase;
  55. using OpenSim.Region.ScriptEngine.Interfaces;
  56. using OpenSim.Region.ScriptEngine.Shared.Api.Interfaces;
  57. using OpenSim.Services.Interfaces;
  58. using GridRegion = OpenSim.Services.Interfaces.GridRegion;
  59. using PresenceInfo = OpenSim.Services.Interfaces.PresenceInfo;
  60. using PrimType = OpenSim.Region.Framework.Scenes.PrimType;
  61. using AssetLandmark = OpenSim.Framework.AssetLandmark;
  62. using RegionFlags = OpenSim.Framework.RegionFlags;
  63. using LSL_Float = OpenSim.Region.ScriptEngine.Shared.LSL_Types.LSLFloat;
  64. using LSL_Integer = OpenSim.Region.ScriptEngine.Shared.LSL_Types.LSLInteger;
  65. using LSL_Key = OpenSim.Region.ScriptEngine.Shared.LSL_Types.LSLString;
  66. using LSL_List = OpenSim.Region.ScriptEngine.Shared.LSL_Types.list;
  67. using LSL_Rotation = OpenSim.Region.ScriptEngine.Shared.LSL_Types.Quaternion;
  68. using LSL_String = OpenSim.Region.ScriptEngine.Shared.LSL_Types.LSLString;
  69. using LSL_Vector = OpenSim.Region.ScriptEngine.Shared.LSL_Types.Vector3;
  70. using System.Reflection;
  71. using System.Linq;
  72. using PermissionMask = OpenSim.Framework.PermissionMask;
  73. namespace OpenSim.Region.ScriptEngine.Shared.Api
  74. {
  75. // MUST be a ref type
  76. public class UserInfoCacheEntry
  77. {
  78. public int time;
  79. public UserAccount account;
  80. public PresenceInfo pinfo;
  81. }
  82. /// <summary>
  83. /// Contains all LSL ll-functions. This class will be in Default AppDomain.
  84. /// </summary>
  85. public class LSL_Api : MarshalByRefObject, ILSL_Api, IScriptApi
  86. {
  87. private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
  88. public int LlRequestAgentDataCacheTimeoutMs { get; set; }
  89. protected IScriptEngine m_ScriptEngine;
  90. protected SceneObjectPart m_host;
  91. /// <summary>
  92. /// Used for script sleeps when we are using co-operative script termination.
  93. /// </summary>
  94. /// <remarks>null if co-operative script termination is not active</remarks>
  95. WaitHandle m_coopSleepHandle;
  96. /// <summary>
  97. /// The item that hosts this script
  98. /// </summary>
  99. protected TaskInventoryItem m_item;
  100. protected bool throwErrorOnNotImplemented = false;
  101. protected AsyncCommandManager AsyncCommands = null;
  102. protected float m_ScriptDelayFactor = 1.0f;
  103. protected float m_ScriptDistanceFactor = 1.0f;
  104. protected float m_MinTimerInterval = 0.5f;
  105. protected float m_recoilScaleFactor = 0.0f;
  106. protected DateTime m_timer = DateTime.Now;
  107. protected bool m_waitingForScriptAnswer = false;
  108. protected bool m_automaticLinkPermission = false;
  109. protected IMessageTransferModule m_TransferModule = null;
  110. protected int m_notecardLineReadCharsMax = 255;
  111. protected int m_scriptConsoleChannel = 0;
  112. protected bool m_scriptConsoleChannelEnabled = false;
  113. protected IUrlModule m_UrlModule = null;
  114. protected Dictionary<UUID, UserInfoCacheEntry> m_userInfoCache = new Dictionary<UUID, UserInfoCacheEntry>();
  115. protected int EMAIL_PAUSE_TIME = 20; // documented delay value for smtp.
  116. protected int m_sleepMsOnSetTexture = 200;
  117. protected int m_sleepMsOnSetLinkTexture = 200;
  118. protected int m_sleepMsOnScaleTexture = 200;
  119. protected int m_sleepMsOnOffsetTexture = 200;
  120. protected int m_sleepMsOnRotateTexture = 200;
  121. protected int m_sleepMsOnSetPos = 200;
  122. protected int m_sleepMsOnSetRot = 200;
  123. protected int m_sleepMsOnSetLocalRot = 200;
  124. protected int m_sleepMsOnPreloadSound = 1000;
  125. protected int m_sleepMsOnMakeExplosion = 100;
  126. protected int m_sleepMsOnMakeFountain = 100;
  127. protected int m_sleepMsOnMakeSmoke = 100;
  128. protected int m_sleepMsOnMakeFire = 100;
  129. protected int m_sleepMsOnRezAtRoot = 100;
  130. protected int m_sleepMsOnInstantMessage = 2000;
  131. protected int m_sleepMsOnEmail = 20000;
  132. protected int m_sleepMsOnCreateLink = 1000;
  133. protected int m_sleepMsOnGiveInventory = 3000;
  134. protected int m_sleepMsOnRequestAgentData = 100;
  135. protected int m_sleepMsOnRequestInventoryData = 1000;
  136. protected int m_sleepMsOnSetDamage = 5000;
  137. protected int m_sleepMsOnTextBox = 1000;
  138. protected int m_sleepMsOnAdjustSoundVolume = 100;
  139. protected int m_sleepMsOnEjectFromLand = 5000;
  140. protected int m_sleepMsOnAddToLandPassList = 100;
  141. protected int m_sleepMsOnDialog = 1000;
  142. protected int m_sleepMsOnRemoteLoadScript = 3000;
  143. protected int m_sleepMsOnRemoteLoadScriptPin = 3000;
  144. protected int m_sleepMsOnOpenRemoteDataChannel = 1000;
  145. protected int m_sleepMsOnSendRemoteData = 3000;
  146. protected int m_sleepMsOnRemoteDataReply = 3000;
  147. protected int m_sleepMsOnCloseRemoteDataChannel = 1000;
  148. protected int m_sleepMsOnSetPrimitiveParams = 200;
  149. protected int m_sleepMsOnSetLinkPrimitiveParams = 200;
  150. protected int m_sleepMsOnXorBase64Strings = 300;
  151. protected int m_sleepMsOnSetParcelMusicURL = 2000;
  152. protected int m_sleepMsOnGetPrimMediaParams = 1000;
  153. protected int m_sleepMsOnGetLinkMedia = 1000;
  154. protected int m_sleepMsOnSetPrimMediaParams = 1000;
  155. protected int m_sleepMsOnSetLinkMedia = 1000;
  156. protected int m_sleepMsOnClearPrimMedia = 1000;
  157. protected int m_sleepMsOnClearLinkMedia = 1000;
  158. protected int m_sleepMsOnRequestSimulatorData = 1000;
  159. protected int m_sleepMsOnLoadURL = 10000;
  160. protected int m_sleepMsOnParcelMediaCommandList = 2000;
  161. protected int m_sleepMsOnParcelMediaQuery = 2000;
  162. protected int m_sleepMsOnModPow = 1000;
  163. protected int m_sleepMsOnSetPrimURL = 2000;
  164. protected int m_sleepMsOnRefreshPrimURL = 20000;
  165. protected int m_sleepMsOnMapDestination = 1000;
  166. protected int m_sleepMsOnAddToLandBanList = 100;
  167. protected int m_sleepMsOnRemoveFromLandPassList = 100;
  168. protected int m_sleepMsOnRemoveFromLandBanList = 100;
  169. protected int m_sleepMsOnResetLandBanList = 100;
  170. protected int m_sleepMsOnResetLandPassList = 100;
  171. protected int m_sleepMsOnGetParcelPrimOwners = 2000;
  172. protected int m_sleepMsOnGetNumberOfNotecardLines = 100;
  173. protected int m_sleepMsOnGetNotecardLine = 100;
  174. protected string m_internalObjectHost = "lsl.opensim.local";
  175. protected bool m_restrictEmail = false;
  176. protected ISoundModule m_SoundModule = null;
  177. protected float m_avatarHeightCorrection = 0.2f;
  178. protected bool m_useSimpleBoxesInGetBoundingBox = false;
  179. protected bool m_addStatsInGetBoundingBox = false;
  180. //LSL Avatar Bounding Box (lABB), lower (1) and upper (2),
  181. //standing (Std), Groundsitting (Grs), Sitting (Sit),
  182. //along X, Y and Z axes, constants (0) and coefficients (1)
  183. protected float m_lABB1StdX0 = -0.275f;
  184. protected float m_lABB2StdX0 = 0.275f;
  185. protected float m_lABB1StdY0 = -0.35f;
  186. protected float m_lABB2StdY0 = 0.35f;
  187. protected float m_lABB1StdZ0 = -0.1f;
  188. protected float m_lABB1StdZ1 = -0.5f;
  189. protected float m_lABB2StdZ0 = 0.1f;
  190. protected float m_lABB2StdZ1 = 0.5f;
  191. protected float m_lABB1GrsX0 = -0.3875f;
  192. protected float m_lABB2GrsX0 = 0.3875f;
  193. protected float m_lABB1GrsY0 = -0.5f;
  194. protected float m_lABB2GrsY0 = 0.5f;
  195. protected float m_lABB1GrsZ0 = -0.05f;
  196. protected float m_lABB1GrsZ1 = -0.375f;
  197. protected float m_lABB2GrsZ0 = 0.5f;
  198. protected float m_lABB2GrsZ1 = 0.0f;
  199. protected float m_lABB1SitX0 = -0.5875f;
  200. protected float m_lABB2SitX0 = 0.1875f;
  201. protected float m_lABB1SitY0 = -0.35f;
  202. protected float m_lABB2SitY0 = 0.35f;
  203. protected float m_lABB1SitZ0 = -0.35f;
  204. protected float m_lABB1SitZ1 = -0.375f;
  205. protected float m_lABB2SitZ0 = -0.25f;
  206. protected float m_lABB2SitZ1 = 0.25f;
  207. protected float m_primSafetyCoeffX = 2.414214f;
  208. protected float m_primSafetyCoeffY = 2.414214f;
  209. protected float m_primSafetyCoeffZ = 1.618034f;
  210. protected float m_floatToleranceInCastRay = 0.000001f;
  211. protected float m_floatTolerance2InCastRay = 0.0001f;
  212. protected int m_maxHitsInCastRay = 16;
  213. protected int m_maxHitsPerPrimInCastRay = 16;
  214. protected int m_maxHitsPerObjectInCastRay = 16;
  215. protected bool m_detectExitsInCastRay = false;
  216. protected bool m_filterPartsInCastRay = false;
  217. protected bool m_doAttachmentsInCastRay = false;
  218. protected bool m_useCastRayV1 = true;
  219. //An array of HTTP/1.1 headers that are not allowed to be used
  220. //as custom headers by llHTTPRequest.
  221. private string[] HttpStandardHeaders =
  222. {
  223. "Accept", "Accept-Charset", "Accept-Encoding", "Accept-Language",
  224. "Accept-Ranges", "Age", "Allow", "Authorization", "Cache-Control",
  225. "Connection", "Content-Encoding", "Content-Language",
  226. "Content-Length", "Content-Location", "Content-MD5",
  227. "Content-Range", "Content-Type", "Date", "ETag", "Expect",
  228. "Expires", "From", "Host", "If-Match", "If-Modified-Since",
  229. "If-None-Match", "If-Range", "If-Unmodified-Since", "Last-Modified",
  230. "Location", "Max-Forwards", "Pragma", "Proxy-Authenticate",
  231. "Proxy-Authorization", "Range", "Referer", "Retry-After", "Server",
  232. "TE", "Trailer", "Transfer-Encoding", "Upgrade", "User-Agent",
  233. "Vary", "Via", "Warning", "WWW-Authenticate"
  234. };
  235. public void Initialize(
  236. IScriptEngine scriptEngine, SceneObjectPart host, TaskInventoryItem item, WaitHandle coopSleepHandle)
  237. {
  238. m_ScriptEngine = scriptEngine;
  239. m_host = host;
  240. m_item = item;
  241. m_coopSleepHandle = coopSleepHandle;
  242. LoadConfig();
  243. m_TransferModule =
  244. m_ScriptEngine.World.RequestModuleInterface<IMessageTransferModule>();
  245. m_UrlModule = m_ScriptEngine.World.RequestModuleInterface<IUrlModule>();
  246. m_SoundModule = m_ScriptEngine.World.RequestModuleInterface<ISoundModule>();
  247. AsyncCommands = new AsyncCommandManager(m_ScriptEngine);
  248. }
  249. /// <summary>
  250. /// Load configuration items that affect script, object and run-time behavior. */
  251. /// </summary>
  252. private void LoadConfig()
  253. {
  254. LlRequestAgentDataCacheTimeoutMs = 20000;
  255. IConfig seConfig = m_ScriptEngine.Config;
  256. if (seConfig != null)
  257. {
  258. m_ScriptDelayFactor =
  259. seConfig.GetFloat("ScriptDelayFactor", m_ScriptDelayFactor);
  260. m_ScriptDistanceFactor =
  261. seConfig.GetFloat("ScriptDistanceLimitFactor", m_ScriptDistanceFactor);
  262. m_MinTimerInterval =
  263. seConfig.GetFloat("MinTimerInterval", m_MinTimerInterval);
  264. m_automaticLinkPermission =
  265. seConfig.GetBoolean("AutomaticLinkPermission", m_automaticLinkPermission);
  266. m_notecardLineReadCharsMax =
  267. seConfig.GetInt("NotecardLineReadCharsMax", m_notecardLineReadCharsMax);
  268. // Rezzing an object with a velocity can create recoil. This feature seems to have been
  269. // removed from recent versions of SL. The code computes recoil (vel*mass) and scales
  270. // it by this factor. May be zero to turn off recoil all together.
  271. m_recoilScaleFactor = m_ScriptEngine.Config.GetFloat("RecoilScaleFactor", m_recoilScaleFactor);
  272. }
  273. if (m_notecardLineReadCharsMax > 65535)
  274. m_notecardLineReadCharsMax = 65535;
  275. // load limits for particular subsystems.
  276. IConfigSource seConfigSource = m_ScriptEngine.ConfigSource;
  277. if (seConfigSource != null)
  278. {
  279. IConfig lslConfig = seConfigSource.Configs["LL-Functions"];
  280. if (lslConfig != null)
  281. {
  282. m_restrictEmail = lslConfig.GetBoolean("RestrictEmail", m_restrictEmail);
  283. m_avatarHeightCorrection = lslConfig.GetFloat("AvatarHeightCorrection", m_avatarHeightCorrection);
  284. m_useSimpleBoxesInGetBoundingBox = lslConfig.GetBoolean("UseSimpleBoxesInGetBoundingBox", m_useSimpleBoxesInGetBoundingBox);
  285. m_addStatsInGetBoundingBox = lslConfig.GetBoolean("AddStatsInGetBoundingBox", m_addStatsInGetBoundingBox);
  286. m_lABB1StdX0 = lslConfig.GetFloat("LowerAvatarBoundingBoxStandingXconst", m_lABB1StdX0);
  287. m_lABB2StdX0 = lslConfig.GetFloat("UpperAvatarBoundingBoxStandingXconst", m_lABB2StdX0);
  288. m_lABB1StdY0 = lslConfig.GetFloat("LowerAvatarBoundingBoxStandingYconst", m_lABB1StdY0);
  289. m_lABB2StdY0 = lslConfig.GetFloat("UpperAvatarBoundingBoxStandingYconst", m_lABB2StdY0);
  290. m_lABB1StdZ0 = lslConfig.GetFloat("LowerAvatarBoundingBoxStandingZconst", m_lABB1StdZ0);
  291. m_lABB1StdZ1 = lslConfig.GetFloat("LowerAvatarBoundingBoxStandingZcoeff", m_lABB1StdZ1);
  292. m_lABB2StdZ0 = lslConfig.GetFloat("UpperAvatarBoundingBoxStandingZconst", m_lABB2StdZ0);
  293. m_lABB2StdZ1 = lslConfig.GetFloat("UpperAvatarBoundingBoxStandingZcoeff", m_lABB2StdZ1);
  294. m_lABB1GrsX0 = lslConfig.GetFloat("LowerAvatarBoundingBoxGroundsittingXconst", m_lABB1GrsX0);
  295. m_lABB2GrsX0 = lslConfig.GetFloat("UpperAvatarBoundingBoxGroundsittingXconst", m_lABB2GrsX0);
  296. m_lABB1GrsY0 = lslConfig.GetFloat("LowerAvatarBoundingBoxGroundsittingYconst", m_lABB1GrsY0);
  297. m_lABB2GrsY0 = lslConfig.GetFloat("UpperAvatarBoundingBoxGroundsittingYconst", m_lABB2GrsY0);
  298. m_lABB1GrsZ0 = lslConfig.GetFloat("LowerAvatarBoundingBoxGroundsittingZconst", m_lABB1GrsZ0);
  299. m_lABB1GrsZ1 = lslConfig.GetFloat("LowerAvatarBoundingBoxGroundsittingZcoeff", m_lABB1GrsZ1);
  300. m_lABB2GrsZ0 = lslConfig.GetFloat("UpperAvatarBoundingBoxGroundsittingZconst", m_lABB2GrsZ0);
  301. m_lABB2GrsZ1 = lslConfig.GetFloat("UpperAvatarBoundingBoxGroundsittingZcoeff", m_lABB2GrsZ1);
  302. m_lABB1SitX0 = lslConfig.GetFloat("LowerAvatarBoundingBoxSittingXconst", m_lABB1SitX0);
  303. m_lABB2SitX0 = lslConfig.GetFloat("UpperAvatarBoundingBoxSittingXconst", m_lABB2SitX0);
  304. m_lABB1SitY0 = lslConfig.GetFloat("LowerAvatarBoundingBoxSittingYconst", m_lABB1SitY0);
  305. m_lABB2SitY0 = lslConfig.GetFloat("UpperAvatarBoundingBoxSittingYconst", m_lABB2SitY0);
  306. m_lABB1SitZ0 = lslConfig.GetFloat("LowerAvatarBoundingBoxSittingZconst", m_lABB1SitZ0);
  307. m_lABB1SitZ1 = lslConfig.GetFloat("LowerAvatarBoundingBoxSittingZcoeff", m_lABB1SitZ1);
  308. m_lABB2SitZ0 = lslConfig.GetFloat("UpperAvatarBoundingBoxSittingZconst", m_lABB2SitZ0);
  309. m_lABB2SitZ1 = lslConfig.GetFloat("UpperAvatarBoundingBoxSittingZcoeff", m_lABB2SitZ1);
  310. m_primSafetyCoeffX = lslConfig.GetFloat("PrimBoundingBoxSafetyCoefficientX", m_primSafetyCoeffX);
  311. m_primSafetyCoeffY = lslConfig.GetFloat("PrimBoundingBoxSafetyCoefficientY", m_primSafetyCoeffY);
  312. m_primSafetyCoeffZ = lslConfig.GetFloat("PrimBoundingBoxSafetyCoefficientZ", m_primSafetyCoeffZ);
  313. m_floatToleranceInCastRay = lslConfig.GetFloat("FloatToleranceInLlCastRay", m_floatToleranceInCastRay);
  314. m_floatTolerance2InCastRay = lslConfig.GetFloat("FloatTolerance2InLlCastRay", m_floatTolerance2InCastRay);
  315. m_maxHitsInCastRay = lslConfig.GetInt("MaxHitsInLlCastRay", m_maxHitsInCastRay);
  316. m_maxHitsPerPrimInCastRay = lslConfig.GetInt("MaxHitsPerPrimInLlCastRay", m_maxHitsPerPrimInCastRay);
  317. m_maxHitsPerObjectInCastRay = lslConfig.GetInt("MaxHitsPerObjectInLlCastRay", m_maxHitsPerObjectInCastRay);
  318. m_detectExitsInCastRay = lslConfig.GetBoolean("DetectExitHitsInLlCastRay", m_detectExitsInCastRay);
  319. m_filterPartsInCastRay = lslConfig.GetBoolean("FilterPartsInLlCastRay", m_filterPartsInCastRay);
  320. m_doAttachmentsInCastRay = lslConfig.GetBoolean("DoAttachmentsInLlCastRay", m_doAttachmentsInCastRay);
  321. m_useCastRayV1 = lslConfig.GetBoolean("UseLlCastRayV1", m_useCastRayV1);
  322. }
  323. IConfig smtpConfig = seConfigSource.Configs["SMTP"];
  324. if (smtpConfig != null)
  325. {
  326. // there's an smtp config, so load in the snooze time.
  327. EMAIL_PAUSE_TIME = smtpConfig.GetInt("email_pause_time", EMAIL_PAUSE_TIME);
  328. m_internalObjectHost = smtpConfig.GetString("internal_object_host", m_internalObjectHost);
  329. }
  330. }
  331. m_sleepMsOnEmail = EMAIL_PAUSE_TIME * 1000;
  332. }
  333. public override Object InitializeLifetimeService()
  334. {
  335. ILease lease = (ILease)base.InitializeLifetimeService();
  336. if (lease.CurrentState == LeaseState.Initial)
  337. {
  338. lease.InitialLeaseTime = TimeSpan.FromMinutes(0);
  339. // lease.RenewOnCallTime = TimeSpan.FromSeconds(10.0);
  340. // lease.SponsorshipTimeout = TimeSpan.FromMinutes(1.0);
  341. }
  342. return lease;
  343. }
  344. protected virtual void ScriptSleep(int delay)
  345. {
  346. delay = (int)((float)delay * m_ScriptDelayFactor);
  347. if (delay == 0)
  348. return;
  349. Sleep(delay);
  350. }
  351. protected virtual void Sleep(int delay)
  352. {
  353. if (m_coopSleepHandle == null)
  354. System.Threading.Thread.Sleep(delay);
  355. else
  356. CheckForCoopTermination(delay);
  357. }
  358. /// <summary>
  359. /// Check for co-operative termination.
  360. /// </summary>
  361. /// <param name='delay'>If called with 0, then just the check is performed with no wait.</param>
  362. protected virtual void CheckForCoopTermination(int delay)
  363. {
  364. if (m_coopSleepHandle.WaitOne(delay))
  365. throw new ScriptCoopStopException();
  366. }
  367. public Scene World
  368. {
  369. get { return m_ScriptEngine.World; }
  370. }
  371. public void state(string newState)
  372. {
  373. m_ScriptEngine.SetState(m_item.ItemID, newState);
  374. }
  375. /// <summary>
  376. /// Reset the named script. The script must be present
  377. /// in the same prim.
  378. /// </summary>
  379. public void llResetScript()
  380. {
  381. m_host.AddScriptLPS(1);
  382. // We need to tell the URL module, if we hav one, to release
  383. // the allocated URLs
  384. if (m_UrlModule != null)
  385. m_UrlModule.ScriptRemoved(m_item.ItemID);
  386. m_ScriptEngine.ApiResetScript(m_item.ItemID);
  387. }
  388. public void llResetOtherScript(string name)
  389. {
  390. UUID item;
  391. m_host.AddScriptLPS(1);
  392. if ((item = GetScriptByName(name)) != UUID.Zero)
  393. m_ScriptEngine.ResetScript(item);
  394. else
  395. Error("llResetOtherScript", "Can't find script '" + name + "'");
  396. }
  397. public LSL_Integer llGetScriptState(string name)
  398. {
  399. UUID item;
  400. m_host.AddScriptLPS(1);
  401. if ((item = GetScriptByName(name)) != UUID.Zero)
  402. {
  403. return m_ScriptEngine.GetScriptState(item) ?1:0;
  404. }
  405. Error("llGetScriptState", "Can't find script '" + name + "'");
  406. // If we didn't find it, then it's safe to
  407. // assume it is not running.
  408. return 0;
  409. }
  410. public void llSetScriptState(string name, int run)
  411. {
  412. UUID item;
  413. m_host.AddScriptLPS(1);
  414. // These functions are supposed to be robust,
  415. // so get the state one step at a time.
  416. if ((item = GetScriptByName(name)) != UUID.Zero)
  417. {
  418. m_ScriptEngine.SetScriptState(item, run == 0 ? false : true);
  419. }
  420. else
  421. {
  422. Error("llSetScriptState", "Can't find script '" + name + "'");
  423. }
  424. }
  425. /// <summary>
  426. /// Get a given link entity from a linkset (linked objects and any sitting avatars).
  427. /// </summary>
  428. /// <remarks>
  429. /// If there are any ScenePresence's in the linkset (i.e. because they are sat upon one of the prims), then
  430. /// these are counted as extra entities that correspond to linknums beyond the number of prims in the linkset.
  431. /// The ScenePresences receive linknums in the order in which they sat.
  432. /// </remarks>
  433. /// <returns>
  434. /// The link entity. null if not found.
  435. /// </returns>
  436. /// <param name='part'></param>
  437. /// <param name='linknum'>
  438. /// Can be either a non-negative integer or ScriptBaseClass.LINK_THIS (-4).
  439. /// If ScriptBaseClass.LINK_THIS then the entity containing the script is returned.
  440. /// If the linkset has one entity and a linknum of zero is given, then the single entity is returned. If any
  441. /// positive integer is given in this case then null is returned.
  442. /// If the linkset has more than one entity and a linknum greater than zero but equal to or less than the number
  443. /// of entities, then the entity which corresponds to that linknum is returned.
  444. /// Otherwise, if a positive linknum is given which is greater than the number of entities in the linkset, then
  445. /// null is returned.
  446. /// </param>
  447. public ISceneEntity GetLinkEntity(SceneObjectPart part, int linknum)
  448. {
  449. if (linknum < 0)
  450. {
  451. if (linknum == ScriptBaseClass.LINK_THIS)
  452. return part;
  453. else
  454. return null;
  455. }
  456. int actualPrimCount = part.ParentGroup.PrimCount;
  457. List<ScenePresence> sittingAvatars = part.ParentGroup.GetSittingAvatars();
  458. int adjustedPrimCount = actualPrimCount + sittingAvatars.Count;
  459. // Special case for a single prim. In this case the linknum is zero. However, this will not match a single
  460. // prim that has any avatars sat upon it (in which case the root prim is link 1).
  461. if (linknum == 0)
  462. {
  463. if (actualPrimCount == 1 && sittingAvatars.Count == 0)
  464. return part;
  465. return null;
  466. }
  467. // Special case to handle a single prim with sitting avatars. GetLinkPart() would only match zero but
  468. // here we must match 1 (ScriptBaseClass.LINK_ROOT).
  469. else if (linknum == ScriptBaseClass.LINK_ROOT && actualPrimCount == 1)
  470. {
  471. if (sittingAvatars.Count > 0)
  472. return part.ParentGroup.RootPart;
  473. else
  474. return null;
  475. }
  476. else if (linknum <= adjustedPrimCount)
  477. {
  478. if (linknum <= actualPrimCount)
  479. {
  480. return part.ParentGroup.GetLinkNumPart(linknum);
  481. }
  482. else
  483. {
  484. return sittingAvatars[linknum - actualPrimCount - 1];
  485. }
  486. }
  487. else
  488. {
  489. return null;
  490. }
  491. }
  492. public List<SceneObjectPart> GetLinkParts(int linkType)
  493. {
  494. return GetLinkParts(m_host, linkType);
  495. }
  496. public static List<SceneObjectPart> GetLinkParts(SceneObjectPart part, int linkType)
  497. {
  498. List<SceneObjectPart> ret = new List<SceneObjectPart>();
  499. ret.Add(part);
  500. switch (linkType)
  501. {
  502. case ScriptBaseClass.LINK_SET:
  503. return new List<SceneObjectPart>(part.ParentGroup.Parts);
  504. case ScriptBaseClass.LINK_ROOT:
  505. ret = new List<SceneObjectPart>();
  506. ret.Add(part.ParentGroup.RootPart);
  507. return ret;
  508. case ScriptBaseClass.LINK_ALL_OTHERS:
  509. ret = new List<SceneObjectPart>(part.ParentGroup.Parts);
  510. if (ret.Contains(part))
  511. ret.Remove(part);
  512. return ret;
  513. case ScriptBaseClass.LINK_ALL_CHILDREN:
  514. ret = new List<SceneObjectPart>(part.ParentGroup.Parts);
  515. if (ret.Contains(part.ParentGroup.RootPart))
  516. ret.Remove(part.ParentGroup.RootPart);
  517. return ret;
  518. case ScriptBaseClass.LINK_THIS:
  519. return ret;
  520. default:
  521. if (linkType < 0)
  522. return new List<SceneObjectPart>();
  523. SceneObjectPart target = part.ParentGroup.GetLinkNumPart(linkType);
  524. if (target == null)
  525. return new List<SceneObjectPart>();
  526. ret = new List<SceneObjectPart>();
  527. ret.Add(target);
  528. return ret;
  529. }
  530. }
  531. public List<ISceneEntity> GetLinkEntities(int linkType)
  532. {
  533. return GetLinkEntities(m_host, linkType);
  534. }
  535. public List<ISceneEntity> GetLinkEntities(SceneObjectPart part, int linkType)
  536. {
  537. List<ISceneEntity> ret;
  538. switch (linkType)
  539. {
  540. case ScriptBaseClass.LINK_SET:
  541. return new List<ISceneEntity>(part.ParentGroup.Parts);
  542. case ScriptBaseClass.LINK_ROOT:
  543. return new List<ISceneEntity>() { part.ParentGroup.RootPart };
  544. case ScriptBaseClass.LINK_ALL_OTHERS:
  545. ret = new List<ISceneEntity>(part.ParentGroup.Parts);
  546. if (ret.Contains(part))
  547. ret.Remove(part);
  548. return ret;
  549. case ScriptBaseClass.LINK_ALL_CHILDREN:
  550. ret = new List<ISceneEntity>(part.ParentGroup.Parts);
  551. if (ret.Contains(part.ParentGroup.RootPart))
  552. ret.Remove(part.ParentGroup.RootPart);
  553. return ret;
  554. case ScriptBaseClass.LINK_THIS:
  555. return new List<ISceneEntity>() { part };
  556. default:
  557. if (linkType < 0)
  558. return new List<ISceneEntity>();
  559. ISceneEntity target = GetLinkEntity(part, linkType);
  560. if (target == null)
  561. return new List<ISceneEntity>();
  562. return new List<ISceneEntity>() { target };
  563. }
  564. }
  565. //These are the implementations of the various ll-functions used by the LSL scripts.
  566. public LSL_Float llSin(double f)
  567. {
  568. m_host.AddScriptLPS(1);
  569. return (double)Math.Sin(f);
  570. }
  571. public LSL_Float llCos(double f)
  572. {
  573. m_host.AddScriptLPS(1);
  574. return (double)Math.Cos(f);
  575. }
  576. public LSL_Float llTan(double f)
  577. {
  578. m_host.AddScriptLPS(1);
  579. return (double)Math.Tan(f);
  580. }
  581. public LSL_Float llAtan2(double x, double y)
  582. {
  583. m_host.AddScriptLPS(1);
  584. return (double)Math.Atan2(x, y);
  585. }
  586. public LSL_Float llSqrt(double f)
  587. {
  588. m_host.AddScriptLPS(1);
  589. return (double)Math.Sqrt(f);
  590. }
  591. public LSL_Float llPow(double fbase, double fexponent)
  592. {
  593. m_host.AddScriptLPS(1);
  594. return (double)Math.Pow(fbase, fexponent);
  595. }
  596. public LSL_Integer llAbs(int i)
  597. {
  598. // changed to replicate LSL behaviour whereby minimum int value is returned untouched.
  599. m_host.AddScriptLPS(1);
  600. if (i == Int32.MinValue)
  601. return i;
  602. else
  603. return (int)Math.Abs(i);
  604. }
  605. public LSL_Float llFabs(double f)
  606. {
  607. m_host.AddScriptLPS(1);
  608. return (double)Math.Abs(f);
  609. }
  610. public LSL_Float llFrand(double mag)
  611. {
  612. m_host.AddScriptLPS(1);
  613. return Util.RandomClass.NextDouble() * mag;
  614. }
  615. public LSL_Integer llFloor(double f)
  616. {
  617. m_host.AddScriptLPS(1);
  618. return (int)Math.Floor(f);
  619. }
  620. public LSL_Integer llCeil(double f)
  621. {
  622. m_host.AddScriptLPS(1);
  623. return (int)Math.Ceiling(f);
  624. }
  625. // Xantor 01/May/2008 fixed midpointrounding (2.5 becomes 3.0 instead of 2.0, default = ToEven)
  626. public LSL_Integer llRound(double f)
  627. {
  628. m_host.AddScriptLPS(1);
  629. return (int)Math.Round(f, MidpointRounding.AwayFromZero);
  630. }
  631. //This next group are vector operations involving squaring and square root. ckrinke
  632. public LSL_Float llVecMag(LSL_Vector v)
  633. {
  634. m_host.AddScriptLPS(1);
  635. return LSL_Vector.Mag(v);
  636. }
  637. public LSL_Vector llVecNorm(LSL_Vector v)
  638. {
  639. m_host.AddScriptLPS(1);
  640. return LSL_Vector.Norm(v);
  641. }
  642. private double VecDist(LSL_Vector a, LSL_Vector b)
  643. {
  644. double dx = a.x - b.x;
  645. double dy = a.y - b.y;
  646. double dz = a.z - b.z;
  647. return Math.Sqrt(dx * dx + dy * dy + dz * dz);
  648. }
  649. public LSL_Float llVecDist(LSL_Vector a, LSL_Vector b)
  650. {
  651. m_host.AddScriptLPS(1);
  652. return VecDist(a, b);
  653. }
  654. //Now we start getting into quaternions which means sin/cos, matrices and vectors. ckrinke
  655. /// <summary>
  656. /// Convert an LSL rotation to a Euler vector.
  657. /// </summary>
  658. /// <remarks>
  659. /// Using algorithm based off http://www.euclideanspace.com/maths/geometry/rotations/conversions/quaternionToEuler/quat_2_euler_paper_ver2-1.pdf
  660. /// to avoid issues with singularity and rounding with Y rotation of +/- PI/2
  661. /// </remarks>
  662. /// <param name="r"></param>
  663. /// <returns></returns>
  664. public LSL_Vector llRot2Euler(LSL_Rotation r)
  665. {
  666. m_host.AddScriptLPS(1);
  667. LSL_Vector v = new LSL_Vector(0.0, 0.0, 1.0) * r; // Z axis unit vector unaffected by Z rotation component of r.
  668. double m = LSL_Vector.Mag(v); // Just in case v isn't normalized, need magnitude for Asin() operation later.
  669. if (m == 0.0) return new LSL_Vector();
  670. double x = Math.Atan2(-v.y, v.z);
  671. double sin = v.x / m;
  672. if (sin < -0.999999 || sin > 0.999999) x = 0.0; // Force X rotation to 0 at the singularities.
  673. double y = Math.Asin(sin);
  674. // Rotate X axis unit vector by r and unwind the X and Y rotations leaving only the Z rotation
  675. v = new LSL_Vector(1.0, 0.0, 0.0) * ((r * new LSL_Rotation(Math.Sin(-x / 2.0), 0.0, 0.0, Math.Cos(-x / 2.0))) * new LSL_Rotation(0.0, Math.Sin(-y / 2.0), 0.0, Math.Cos(-y / 2.0)));
  676. double z = Math.Atan2(v.y, v.x);
  677. return new LSL_Vector(x, y, z);
  678. }
  679. /* From wiki:
  680. The Euler angle vector (in radians) is converted to a rotation by doing the rotations around the 3 axes
  681. in Z, Y, X order. So llEuler2Rot(<1.0, 2.0, 3.0> * DEG_TO_RAD) generates a rotation by taking the zero rotation,
  682. a vector pointing along the X axis, first rotating it 3 degrees around the global Z axis, then rotating the resulting
  683. vector 2 degrees around the global Y axis, and finally rotating that 1 degree around the global X axis.
  684. */
  685. /* How we arrived at this llEuler2Rot
  686. *
  687. * Experiment in SL to determine conventions:
  688. * llEuler2Rot(<PI,0,0>)=<1,0,0,0>
  689. * llEuler2Rot(<0,PI,0>)=<0,1,0,0>
  690. * llEuler2Rot(<0,0,PI>)=<0,0,1,0>
  691. *
  692. * Important facts about Quaternions
  693. * - multiplication is non-commutative (a*b != b*a)
  694. * - http://en.wikipedia.org/wiki/Quaternion#Basis_multiplication
  695. *
  696. * Above SL experiment gives (c1,c2,c3,s1,s2,s3 as defined in our llEuler2Rot):
  697. * Qx = c1+i*s1
  698. * Qy = c2+j*s2;
  699. * Qz = c3+k*s3;
  700. *
  701. * Rotations applied in order (from above) Z, Y, X
  702. * Q = (Qz * Qy) * Qx
  703. * ((c1+i*s1)*(c2+j*s2))*(c3+k*s3)
  704. * (c1*c2+i*s1*c2+j*c1*s2+ij*s1*s2)*(c3+k*s3)
  705. * (c1*c2+i*s1*c2+j*c1*s2+k*s1*s2)*(c3+k*s3)
  706. * 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
  707. * 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
  708. * regroup: x=i*(s1*c2*c3+c1*s2*s3)
  709. * y=j*(c1*s2*c3-s1*c2*s3)
  710. * z=k*(s1*s2*c3+c1*c2*s3)
  711. * s= c1*c2*c3-s1*s2*s3
  712. *
  713. * This implementation agrees with the functions found here:
  714. * http://lslwiki.net/lslwiki/wakka.php?wakka=LibraryRotationFunctions
  715. * And with the results in SL.
  716. *
  717. * It's also possible to calculate llEuler2Rot by direct multiplication of
  718. * the Qz, Qy, and Qx vectors (as above - and done in the "accurate" function
  719. * from the wiki).
  720. * Apparently in some cases this is better from a numerical precision perspective?
  721. */
  722. public LSL_Rotation llEuler2Rot(LSL_Vector v)
  723. {
  724. m_host.AddScriptLPS(1);
  725. double x,y,z,s;
  726. double c1 = Math.Cos(v.x * 0.5);
  727. double c2 = Math.Cos(v.y * 0.5);
  728. double c3 = Math.Cos(v.z * 0.5);
  729. double s1 = Math.Sin(v.x * 0.5);
  730. double s2 = Math.Sin(v.y * 0.5);
  731. double s3 = Math.Sin(v.z * 0.5);
  732. x = s1 * c2 * c3 + c1 * s2 * s3;
  733. y = c1 * s2 * c3 - s1 * c2 * s3;
  734. z = s1 * s2 * c3 + c1 * c2 * s3;
  735. s = c1 * c2 * c3 - s1 * s2 * s3;
  736. return new LSL_Rotation(x, y, z, s);
  737. }
  738. public LSL_Rotation llAxes2Rot(LSL_Vector fwd, LSL_Vector left, LSL_Vector up)
  739. {
  740. m_host.AddScriptLPS(1);
  741. double s;
  742. double tr = fwd.x + left.y + up.z + 1.0;
  743. if (tr >= 1.0)
  744. {
  745. s = 0.5 / Math.Sqrt(tr);
  746. return new LSL_Rotation(
  747. (left.z - up.y) * s,
  748. (up.x - fwd.z) * s,
  749. (fwd.y - left.x) * s,
  750. 0.25 / s);
  751. }
  752. else
  753. {
  754. double max = (left.y > up.z) ? left.y : up.z;
  755. if (max < fwd.x)
  756. {
  757. s = Math.Sqrt(fwd.x - (left.y + up.z) + 1.0);
  758. double x = s * 0.5;
  759. s = 0.5 / s;
  760. return new LSL_Rotation(
  761. x,
  762. (fwd.y + left.x) * s,
  763. (up.x + fwd.z) * s,
  764. (left.z - up.y) * s);
  765. }
  766. else if (max == left.y)
  767. {
  768. s = Math.Sqrt(left.y - (up.z + fwd.x) + 1.0);
  769. double y = s * 0.5;
  770. s = 0.5 / s;
  771. return new LSL_Rotation(
  772. (fwd.y + left.x) * s,
  773. y,
  774. (left.z + up.y) * s,
  775. (up.x - fwd.z) * s);
  776. }
  777. else
  778. {
  779. s = Math.Sqrt(up.z - (fwd.x + left.y) + 1.0);
  780. double z = s * 0.5;
  781. s = 0.5 / s;
  782. return new LSL_Rotation(
  783. (up.x + fwd.z) * s,
  784. (left.z + up.y) * s,
  785. z,
  786. (fwd.y - left.x) * s);
  787. }
  788. }
  789. }
  790. public LSL_Vector llRot2Fwd(LSL_Rotation r)
  791. {
  792. m_host.AddScriptLPS(1);
  793. double x, y, z, m;
  794. m = r.x * r.x + r.y * r.y + r.z * r.z + r.s * r.s;
  795. // m is always greater than zero
  796. // if m is not equal to 1 then Rotation needs to be normalized
  797. if (Math.Abs(1.0 - m) > 0.000001) // allow a little slop here for calculation precision
  798. {
  799. m = 1.0 / Math.Sqrt(m);
  800. r.x *= m;
  801. r.y *= m;
  802. r.z *= m;
  803. r.s *= m;
  804. }
  805. // Fast Algebric Calculations instead of Vectors & Quaternions Product
  806. x = r.x * r.x - r.y * r.y - r.z * r.z + r.s * r.s;
  807. y = 2 * (r.x * r.y + r.z * r.s);
  808. z = 2 * (r.x * r.z - r.y * r.s);
  809. return (new LSL_Vector(x, y, z));
  810. }
  811. public LSL_Vector llRot2Left(LSL_Rotation r)
  812. {
  813. m_host.AddScriptLPS(1);
  814. double x, y, z, m;
  815. m = r.x * r.x + r.y * r.y + r.z * r.z + r.s * r.s;
  816. // m is always greater than zero
  817. // if m is not equal to 1 then Rotation needs to be normalized
  818. if (Math.Abs(1.0 - m) > 0.000001) // allow a little slop here for calculation precision
  819. {
  820. m = 1.0 / Math.Sqrt(m);
  821. r.x *= m;
  822. r.y *= m;
  823. r.z *= m;
  824. r.s *= m;
  825. }
  826. // Fast Algebric Calculations instead of Vectors & Quaternions Product
  827. x = 2 * (r.x * r.y - r.z * r.s);
  828. y = -r.x * r.x + r.y * r.y - r.z * r.z + r.s * r.s;
  829. z = 2 * (r.x * r.s + r.y * r.z);
  830. return (new LSL_Vector(x, y, z));
  831. }
  832. public LSL_Vector llRot2Up(LSL_Rotation r)
  833. {
  834. m_host.AddScriptLPS(1);
  835. double x, y, z, m;
  836. m = r.x * r.x + r.y * r.y + r.z * r.z + r.s * r.s;
  837. // m is always greater than zero
  838. // if m is not equal to 1 then Rotation needs to be normalized
  839. if (Math.Abs(1.0 - m) > 0.000001) // allow a little slop here for calculation precision
  840. {
  841. m = 1.0 / Math.Sqrt(m);
  842. r.x *= m;
  843. r.y *= m;
  844. r.z *= m;
  845. r.s *= m;
  846. }
  847. // Fast Algebric Calculations instead of Vectors & Quaternions Product
  848. x = 2 * (r.x * r.z + r.y * r.s);
  849. y = 2 * (-r.x * r.s + r.y * r.z);
  850. z = -r.x * r.x - r.y * r.y + r.z * r.z + r.s * r.s;
  851. return (new LSL_Vector(x, y, z));
  852. }
  853. public LSL_Rotation llRotBetween(LSL_Vector a, LSL_Vector b)
  854. {
  855. //A and B should both be normalized
  856. m_host.AddScriptLPS(1);
  857. LSL_Rotation rotBetween;
  858. // Check for zero vectors. If either is zero, return zero rotation. Otherwise,
  859. // continue calculation.
  860. if (a == new LSL_Vector(0.0f, 0.0f, 0.0f) || b == new LSL_Vector(0.0f, 0.0f, 0.0f))
  861. {
  862. rotBetween = new LSL_Rotation(0.0f, 0.0f, 0.0f, 1.0f);
  863. }
  864. else
  865. {
  866. a = LSL_Vector.Norm(a);
  867. b = LSL_Vector.Norm(b);
  868. double dotProduct = LSL_Vector.Dot(a, b);
  869. // There are two degenerate cases possible. These are for vectors 180 or
  870. // 0 degrees apart. These have to be detected and handled individually.
  871. //
  872. // Check for vectors 180 degrees apart.
  873. // A dot product of -1 would mean the angle between vectors is 180 degrees.
  874. if (dotProduct < -0.9999999f)
  875. {
  876. // First assume X axis is orthogonal to the vectors.
  877. LSL_Vector orthoVector = new LSL_Vector(1.0f, 0.0f, 0.0f);
  878. orthoVector = orthoVector - a * (a.x / LSL_Vector.Dot(a, a));
  879. // Check for near zero vector. A very small non-zero number here will create
  880. // a rotation in an undesired direction.
  881. if (LSL_Vector.Mag(orthoVector) > 0.0001)
  882. {
  883. rotBetween = new LSL_Rotation(orthoVector.x, orthoVector.y, orthoVector.z, 0.0f);
  884. }
  885. // If the magnitude of the vector was near zero, then assume the X axis is not
  886. // orthogonal and use the Z axis instead.
  887. else
  888. {
  889. // Set 180 z rotation.
  890. rotBetween = new LSL_Rotation(0.0f, 0.0f, 1.0f, 0.0f);
  891. }
  892. }
  893. // Check for parallel vectors.
  894. // A dot product of 1 would mean the angle between vectors is 0 degrees.
  895. else if (dotProduct > 0.9999999f)
  896. {
  897. // Set zero rotation.
  898. rotBetween = new LSL_Rotation(0.0f, 0.0f, 0.0f, 1.0f);
  899. }
  900. else
  901. {
  902. // All special checks have been performed so get the axis of rotation.
  903. LSL_Vector crossProduct = LSL_Vector.Cross(a, b);
  904. // Quarternion s value is the length of the unit vector + dot product.
  905. double qs = 1.0 + dotProduct;
  906. rotBetween = new LSL_Rotation(crossProduct.x, crossProduct.y, crossProduct.z, qs);
  907. // Normalize the rotation.
  908. double mag = LSL_Rotation.Mag(rotBetween);
  909. // We shouldn't have to worry about a divide by zero here. The qs value will be
  910. // non-zero because we already know if we're here, then the dotProduct is not -1 so
  911. // qs will not be zero. Also, we've already handled the input vectors being zero so the
  912. // crossProduct vector should also not be zero.
  913. rotBetween.x = rotBetween.x / mag;
  914. rotBetween.y = rotBetween.y / mag;
  915. rotBetween.z = rotBetween.z / mag;
  916. rotBetween.s = rotBetween.s / mag;
  917. // Check for undefined values and set zero rotation if any found. This code might not actually be required
  918. // any longer since zero vectors are checked for at the top.
  919. if (Double.IsNaN(rotBetween.x) || Double.IsNaN(rotBetween.y) || Double.IsNaN(rotBetween.z) || Double.IsNaN(rotBetween.s))
  920. {
  921. rotBetween = new LSL_Rotation(0.0f, 0.0f, 0.0f, 1.0f);
  922. }
  923. }
  924. }
  925. return rotBetween;
  926. }
  927. public void llWhisper(int channelID, string text)
  928. {
  929. m_host.AddScriptLPS(1);
  930. if (text.Length > 1023)
  931. text = text.Substring(0, 1023);
  932. World.SimChat(Utils.StringToBytes(text),
  933. ChatTypeEnum.Whisper, channelID, m_host.ParentGroup.RootPart.AbsolutePosition, m_host.Name, m_host.UUID, false);
  934. IWorldComm wComm = m_ScriptEngine.World.RequestModuleInterface<IWorldComm>();
  935. if (wComm != null)
  936. wComm.DeliverMessage(ChatTypeEnum.Whisper, channelID, m_host.Name, m_host.UUID, text);
  937. }
  938. public void llSay(int channelID, string text)
  939. {
  940. m_host.AddScriptLPS(1);
  941. if (m_scriptConsoleChannelEnabled && (channelID == m_scriptConsoleChannel))
  942. {
  943. Console.WriteLine(text);
  944. }
  945. else
  946. {
  947. if (text.Length > 1023)
  948. text = text.Substring(0, 1023);
  949. World.SimChat(Utils.StringToBytes(text),
  950. ChatTypeEnum.Say, channelID, m_host.ParentGroup.RootPart.AbsolutePosition, m_host.Name, m_host.UUID, false);
  951. IWorldComm wComm = m_ScriptEngine.World.RequestModuleInterface<IWorldComm>();
  952. if (wComm != null)
  953. wComm.DeliverMessage(ChatTypeEnum.Say, channelID, m_host.Name, m_host.UUID, text);
  954. }
  955. }
  956. public void llShout(int channelID, string text)
  957. {
  958. m_host.AddScriptLPS(1);
  959. if (text.Length > 1023)
  960. text = text.Substring(0, 1023);
  961. World.SimChat(Utils.StringToBytes(text),
  962. ChatTypeEnum.Shout, channelID, m_host.ParentGroup.RootPart.AbsolutePosition, m_host.Name, m_host.UUID, true);
  963. IWorldComm wComm = m_ScriptEngine.World.RequestModuleInterface<IWorldComm>();
  964. if (wComm != null)
  965. wComm.DeliverMessage(ChatTypeEnum.Shout, channelID, m_host.Name, m_host.UUID, text);
  966. }
  967. public void llRegionSay(int channelID, string text)
  968. {
  969. if (channelID == 0)
  970. {
  971. Error("llRegionSay", "Cannot use on channel 0");
  972. return;
  973. }
  974. if (text.Length > 1023)
  975. text = text.Substring(0, 1023);
  976. m_host.AddScriptLPS(1);
  977. World.SimChat(Utils.StringToBytes(text),
  978. ChatTypeEnum.Region, channelID, m_host.ParentGroup.RootPart.AbsolutePosition, m_host.Name, m_host.UUID, false);
  979. IWorldComm wComm = m_ScriptEngine.World.RequestModuleInterface<IWorldComm>();
  980. if (wComm != null)
  981. wComm.DeliverMessage(ChatTypeEnum.Region, channelID, m_host.Name, m_host.UUID, text);
  982. }
  983. public void llRegionSayTo(string target, int channel, string msg)
  984. {
  985. if (msg.Length > 1023)
  986. msg = msg.Substring(0, 1023);
  987. m_host.AddScriptLPS(1);
  988. if (channel == ScriptBaseClass.DEBUG_CHANNEL)
  989. {
  990. return;
  991. }
  992. UUID TargetID;
  993. UUID.TryParse(target, out TargetID);
  994. World.SimChatToAgent(TargetID, Utils.StringToBytes(msg),
  995. channel, m_host.ParentGroup.RootPart.AbsolutePosition, m_host.Name, m_host.UUID, true);
  996. IWorldComm wComm = m_ScriptEngine.World.RequestModuleInterface<IWorldComm>();
  997. if (wComm != null)
  998. wComm.DeliverMessageTo(TargetID, channel, m_host.AbsolutePosition, m_host.Name, m_host.UUID, msg);
  999. }
  1000. public LSL_Integer llListen(int channelID, string name, string ID, string msg)
  1001. {
  1002. m_host.AddScriptLPS(1);
  1003. UUID keyID;
  1004. UUID.TryParse(ID, out keyID);
  1005. IWorldComm wComm = m_ScriptEngine.World.RequestModuleInterface<IWorldComm>();
  1006. if (wComm != null)
  1007. return wComm.Listen(m_host.LocalId, m_item.ItemID, m_host.UUID, channelID, name, keyID, msg);
  1008. else
  1009. return -1;
  1010. }
  1011. public void llListenControl(int number, int active)
  1012. {
  1013. m_host.AddScriptLPS(1);
  1014. IWorldComm wComm = m_ScriptEngine.World.RequestModuleInterface<IWorldComm>();
  1015. if (wComm != null)
  1016. wComm.ListenControl(m_item.ItemID, number, active);
  1017. }
  1018. public void llListenRemove(int number)
  1019. {
  1020. m_host.AddScriptLPS(1);
  1021. IWorldComm wComm = m_ScriptEngine.World.RequestModuleInterface<IWorldComm>();
  1022. if (wComm != null)
  1023. wComm.ListenRemove(m_item.ItemID, number);
  1024. }
  1025. public void llSensor(string name, string id, int type, double range, double arc)
  1026. {
  1027. m_host.AddScriptLPS(1);
  1028. UUID keyID = UUID.Zero;
  1029. UUID.TryParse(id, out keyID);
  1030. AsyncCommands.SensorRepeatPlugin.SenseOnce(m_host.LocalId, m_item.ItemID, name, keyID, type, range, arc, m_host);
  1031. }
  1032. public void llSensorRepeat(string name, string id, int type, double range, double arc, double rate)
  1033. {
  1034. m_host.AddScriptLPS(1);
  1035. UUID keyID = UUID.Zero;
  1036. UUID.TryParse(id, out keyID);
  1037. AsyncCommands.SensorRepeatPlugin.SetSenseRepeatEvent(m_host.LocalId, m_item.ItemID, name, keyID, type, range, arc, rate, m_host);
  1038. }
  1039. public void llSensorRemove()
  1040. {
  1041. m_host.AddScriptLPS(1);
  1042. AsyncCommands.SensorRepeatPlugin.UnSetSenseRepeaterEvents(m_host.LocalId, m_item.ItemID);
  1043. }
  1044. public string resolveName(UUID objecUUID)
  1045. {
  1046. // try avatar username surname
  1047. UserAccount account = World.UserAccountService.GetUserAccount(World.RegionInfo.ScopeID, objecUUID);
  1048. if (account != null)
  1049. {
  1050. string avatarname = account.Name;
  1051. return avatarname;
  1052. }
  1053. // try an scene object
  1054. SceneObjectPart SOP = World.GetSceneObjectPart(objecUUID);
  1055. if (SOP != null)
  1056. {
  1057. string objectname = SOP.Name;
  1058. return objectname;
  1059. }
  1060. EntityBase SensedObject;
  1061. World.Entities.TryGetValue(objecUUID, out SensedObject);
  1062. if (SensedObject == null)
  1063. {
  1064. IGroupsModule groups = World.RequestModuleInterface<IGroupsModule>();
  1065. if (groups != null)
  1066. {
  1067. GroupRecord gr = groups.GetGroupRecord(objecUUID);
  1068. if (gr != null)
  1069. return gr.GroupName;
  1070. }
  1071. return String.Empty;
  1072. }
  1073. return SensedObject.Name;
  1074. }
  1075. public LSL_String llDetectedName(int number)
  1076. {
  1077. m_host.AddScriptLPS(1);
  1078. DetectParams detectedParams = m_ScriptEngine.GetDetectParams(m_item.ItemID, number);
  1079. if (detectedParams == null)
  1080. return String.Empty;
  1081. return detectedParams.Name;
  1082. }
  1083. public LSL_String llDetectedKey(int number)
  1084. {
  1085. m_host.AddScriptLPS(1);
  1086. DetectParams detectedParams = m_ScriptEngine.GetDetectParams(m_item.ItemID, number);
  1087. if (detectedParams == null)
  1088. return String.Empty;
  1089. return detectedParams.Key.ToString();
  1090. }
  1091. public LSL_String llDetectedOwner(int number)
  1092. {
  1093. m_host.AddScriptLPS(1);
  1094. DetectParams detectedParams = m_ScriptEngine.GetDetectParams(m_item.ItemID, number);
  1095. if (detectedParams == null)
  1096. return String.Empty;
  1097. return detectedParams.Owner.ToString();
  1098. }
  1099. public LSL_Integer llDetectedType(int number)
  1100. {
  1101. m_host.AddScriptLPS(1);
  1102. DetectParams detectedParams = m_ScriptEngine.GetDetectParams(m_item.ItemID, number);
  1103. if (detectedParams == null)
  1104. return 0;
  1105. return new LSL_Integer(detectedParams.Type);
  1106. }
  1107. public LSL_Vector llDetectedPos(int number)
  1108. {
  1109. m_host.AddScriptLPS(1);
  1110. DetectParams detectedParams = m_ScriptEngine.GetDetectParams(m_item.ItemID, number);
  1111. if (detectedParams == null)
  1112. return new LSL_Vector();
  1113. return detectedParams.Position;
  1114. }
  1115. public LSL_Vector llDetectedVel(int number)
  1116. {
  1117. m_host.AddScriptLPS(1);
  1118. DetectParams detectedParams = m_ScriptEngine.GetDetectParams(m_item.ItemID, number);
  1119. if (detectedParams == null)
  1120. return new LSL_Vector();
  1121. return detectedParams.Velocity;
  1122. }
  1123. public LSL_Vector llDetectedGrab(int number)
  1124. {
  1125. m_host.AddScriptLPS(1);
  1126. DetectParams parms = m_ScriptEngine.GetDetectParams(m_item.ItemID, number);
  1127. if (parms == null)
  1128. return new LSL_Vector(0, 0, 0);
  1129. return parms.OffsetPos;
  1130. }
  1131. public LSL_Rotation llDetectedRot(int number)
  1132. {
  1133. m_host.AddScriptLPS(1);
  1134. DetectParams detectedParams = m_ScriptEngine.GetDetectParams(m_item.ItemID, number);
  1135. if (detectedParams == null)
  1136. return new LSL_Rotation();
  1137. return detectedParams.Rotation;
  1138. }
  1139. public LSL_Integer llDetectedGroup(int number)
  1140. {
  1141. m_host.AddScriptLPS(1);
  1142. DetectParams detectedParams = m_ScriptEngine.GetDetectParams(m_item.ItemID, number);
  1143. if (detectedParams == null)
  1144. return new LSL_Integer(0);
  1145. if (m_host.GroupID == detectedParams.Group)
  1146. return new LSL_Integer(1);
  1147. return new LSL_Integer(0);
  1148. }
  1149. public LSL_Integer llDetectedLinkNumber(int number)
  1150. {
  1151. m_host.AddScriptLPS(1);
  1152. DetectParams parms = m_ScriptEngine.GetDetectParams(m_item.ItemID, number);
  1153. if (parms == null)
  1154. return new LSL_Integer(0);
  1155. return new LSL_Integer(parms.LinkNum);
  1156. }
  1157. /// <summary>
  1158. /// See http://wiki.secondlife.com/wiki/LlDetectedTouchBinormal for details
  1159. /// </summary>
  1160. public LSL_Vector llDetectedTouchBinormal(int index)
  1161. {
  1162. m_host.AddScriptLPS(1);
  1163. DetectParams detectedParams = m_ScriptEngine.GetDetectParams(m_item.ItemID, index);
  1164. if (detectedParams == null)
  1165. return new LSL_Vector();
  1166. return detectedParams.TouchBinormal;
  1167. }
  1168. /// <summary>
  1169. /// See http://wiki.secondlife.com/wiki/LlDetectedTouchFace for details
  1170. /// </summary>
  1171. public LSL_Integer llDetectedTouchFace(int index)
  1172. {
  1173. m_host.AddScriptLPS(1);
  1174. DetectParams detectedParams = m_ScriptEngine.GetDetectParams(m_item.ItemID, index);
  1175. if (detectedParams == null)
  1176. return new LSL_Integer(-1);
  1177. return new LSL_Integer(detectedParams.TouchFace);
  1178. }
  1179. /// <summary>
  1180. /// See http://wiki.secondlife.com/wiki/LlDetectedTouchNormal for details
  1181. /// </summary>
  1182. public LSL_Vector llDetectedTouchNormal(int index)
  1183. {
  1184. m_host.AddScriptLPS(1);
  1185. DetectParams detectedParams = m_ScriptEngine.GetDetectParams(m_item.ItemID, index);
  1186. if (detectedParams == null)
  1187. return new LSL_Vector();
  1188. return detectedParams.TouchNormal;
  1189. }
  1190. /// <summary>
  1191. /// See http://wiki.secondlife.com/wiki/LlDetectedTouchPos for details
  1192. /// </summary>
  1193. public LSL_Vector llDetectedTouchPos(int index)
  1194. {
  1195. m_host.AddScriptLPS(1);
  1196. DetectParams detectedParams = m_ScriptEngine.GetDetectParams(m_item.ItemID, index);
  1197. if (detectedParams == null)
  1198. return new LSL_Vector();
  1199. return detectedParams.TouchPos;
  1200. }
  1201. /// <summary>
  1202. /// See http://wiki.secondlife.com/wiki/LlDetectedTouchST for details
  1203. /// </summary>
  1204. public LSL_Vector llDetectedTouchST(int index)
  1205. {
  1206. m_host.AddScriptLPS(1);
  1207. DetectParams detectedParams = m_ScriptEngine.GetDetectParams(m_item.ItemID, index);
  1208. if (detectedParams == null)
  1209. return new LSL_Vector(-1.0, -1.0, 0.0);
  1210. return detectedParams.TouchST;
  1211. }
  1212. /// <summary>
  1213. /// See http://wiki.secondlife.com/wiki/LlDetectedTouchUV for details
  1214. /// </summary>
  1215. public LSL_Vector llDetectedTouchUV(int index)
  1216. {
  1217. m_host.AddScriptLPS(1);
  1218. DetectParams detectedParams = m_ScriptEngine.GetDetectParams(m_item.ItemID, index);
  1219. if (detectedParams == null)
  1220. return new LSL_Vector(-1.0, -1.0, 0.0);
  1221. return detectedParams.TouchUV;
  1222. }
  1223. public virtual void llDie()
  1224. {
  1225. m_host.AddScriptLPS(1);
  1226. throw new SelfDeleteException();
  1227. }
  1228. public LSL_Float llGround(LSL_Vector offset)
  1229. {
  1230. m_host.AddScriptLPS(1);
  1231. Vector3 pos = m_host.GetWorldPosition() + (Vector3)offset;
  1232. //Get the slope normal. This gives us the equation of the plane tangent to the slope.
  1233. LSL_Vector vsn = llGroundNormal(offset);
  1234. // Clamp to valid position
  1235. if (pos.X < 0)
  1236. pos.X = 0;
  1237. else if (pos.X >= World.Heightmap.Width)
  1238. pos.X = World.Heightmap.Width - 1;
  1239. if (pos.Y < 0)
  1240. pos.Y = 0;
  1241. else if (pos.Y >= World.Heightmap.Height)
  1242. pos.Y = World.Heightmap.Height - 1;
  1243. //Get the height for the integer coordinates from the Heightmap
  1244. float baseheight = (float)World.Heightmap[(int)pos.X, (int)pos.Y];
  1245. //Calculate the difference between the actual coordinates and the integer coordinates
  1246. float xdiff = pos.X - (float)((int)pos.X);
  1247. float ydiff = pos.Y - (float)((int)pos.Y);
  1248. //Use the equation of the tangent plane to adjust the height to account for slope
  1249. return (((vsn.x * xdiff) + (vsn.y * ydiff)) / (-1 * vsn.z)) + baseheight;
  1250. }
  1251. public LSL_Float llCloud(LSL_Vector offset)
  1252. {
  1253. m_host.AddScriptLPS(1);
  1254. float cloudCover = 0f;
  1255. ICloudModule module = World.RequestModuleInterface<ICloudModule>();
  1256. if (module != null)
  1257. {
  1258. Vector3 pos = m_host.GetWorldPosition();
  1259. int x = (int)(pos.X + offset.x);
  1260. int y = (int)(pos.Y + offset.y);
  1261. cloudCover = module.CloudCover(x, y, 0);
  1262. }
  1263. return cloudCover;
  1264. }
  1265. public LSL_Vector llWind(LSL_Vector offset)
  1266. {
  1267. m_host.AddScriptLPS(1);
  1268. LSL_Vector wind = new LSL_Vector(0, 0, 0);
  1269. IWindModule module = World.RequestModuleInterface<IWindModule>();
  1270. if (module != null)
  1271. {
  1272. Vector3 pos = m_host.GetWorldPosition();
  1273. int x = (int)(pos.X + offset.x);
  1274. int y = (int)(pos.Y + offset.y);
  1275. Vector3 windSpeed = module.WindSpeed(x, y, 0);
  1276. wind.x = windSpeed.X;
  1277. wind.y = windSpeed.Y;
  1278. }
  1279. return wind;
  1280. }
  1281. public void llSetStatus(int status, int value)
  1282. {
  1283. m_host.AddScriptLPS(1);
  1284. int statusrotationaxis = 0;
  1285. if ((status & ScriptBaseClass.STATUS_PHYSICS) == ScriptBaseClass.STATUS_PHYSICS)
  1286. {
  1287. if (value != 0)
  1288. {
  1289. SceneObjectGroup group = m_host.ParentGroup;
  1290. bool allow = true;
  1291. foreach (SceneObjectPart part in group.Parts)
  1292. {
  1293. if (part.Scale.X > World.m_maxPhys || part.Scale.Y > World.m_maxPhys || part.Scale.Z > World.m_maxPhys)
  1294. {
  1295. allow = false;
  1296. break;
  1297. }
  1298. }
  1299. if (!allow)
  1300. return;
  1301. m_host.ScriptSetPhysicsStatus(true);
  1302. }
  1303. else
  1304. {
  1305. m_host.ScriptSetPhysicsStatus(false);
  1306. }
  1307. }
  1308. if ((status & ScriptBaseClass.STATUS_PHANTOM) == ScriptBaseClass.STATUS_PHANTOM)
  1309. {
  1310. m_host.ParentGroup.ScriptSetPhantomStatus(value != 0);
  1311. }
  1312. if ((status & ScriptBaseClass.STATUS_CAST_SHADOWS) == ScriptBaseClass.STATUS_CAST_SHADOWS)
  1313. {
  1314. m_host.AddFlag(PrimFlags.CastShadows);
  1315. }
  1316. if ((status & ScriptBaseClass.STATUS_ROTATE_X) == ScriptBaseClass.STATUS_ROTATE_X)
  1317. {
  1318. statusrotationaxis |= ScriptBaseClass.STATUS_ROTATE_X;
  1319. }
  1320. if ((status & ScriptBaseClass.STATUS_ROTATE_Y) == ScriptBaseClass.STATUS_ROTATE_Y)
  1321. {
  1322. statusrotationaxis |= ScriptBaseClass.STATUS_ROTATE_Y;
  1323. }
  1324. if ((status & ScriptBaseClass.STATUS_ROTATE_Z) == ScriptBaseClass.STATUS_ROTATE_Z)
  1325. {
  1326. statusrotationaxis |= ScriptBaseClass.STATUS_ROTATE_Z;
  1327. }
  1328. if ((status & ScriptBaseClass.STATUS_BLOCK_GRAB) == ScriptBaseClass.STATUS_BLOCK_GRAB)
  1329. m_host.BlockGrab = value != 0;
  1330. if ((status & ScriptBaseClass.STATUS_BLOCK_GRAB_OBJECT) == ScriptBaseClass.STATUS_BLOCK_GRAB_OBJECT)
  1331. m_host.ParentGroup.BlockGrabOverride = value != 0;
  1332. if ((status & ScriptBaseClass.STATUS_DIE_AT_EDGE) == ScriptBaseClass.STATUS_DIE_AT_EDGE)
  1333. {
  1334. if (value != 0)
  1335. m_host.SetDieAtEdge(true);
  1336. else
  1337. m_host.SetDieAtEdge(false);
  1338. }
  1339. if ((status & ScriptBaseClass.STATUS_RETURN_AT_EDGE) == ScriptBaseClass.STATUS_RETURN_AT_EDGE)
  1340. {
  1341. if (value != 0)
  1342. m_host.SetReturnAtEdge(true);
  1343. else
  1344. m_host.SetReturnAtEdge(false);
  1345. }
  1346. if ((status & ScriptBaseClass.STATUS_SANDBOX) == ScriptBaseClass.STATUS_SANDBOX)
  1347. {
  1348. if (value != 0)
  1349. m_host.SetStatusSandbox(true);
  1350. else
  1351. m_host.SetStatusSandbox(false);
  1352. }
  1353. if (statusrotationaxis != 0)
  1354. {
  1355. m_host.SetAxisRotation(statusrotationaxis, value);
  1356. }
  1357. }
  1358. private bool IsPhysical()
  1359. {
  1360. return ((m_host.GetEffectiveObjectFlags() & (uint)PrimFlags.Physics) == (uint)PrimFlags.Physics);
  1361. }
  1362. public LSL_Integer llGetStatus(int status)
  1363. {
  1364. m_host.AddScriptLPS(1);
  1365. // m_log.Debug(m_host.ToString() + " status is " + m_host.GetEffectiveObjectFlags().ToString());
  1366. switch (status)
  1367. {
  1368. case ScriptBaseClass.STATUS_PHYSICS:
  1369. return IsPhysical() ? 1 : 0;
  1370. case ScriptBaseClass.STATUS_PHANTOM:
  1371. if ((m_host.GetEffectiveObjectFlags() & (uint)PrimFlags.Phantom) == (uint)PrimFlags.Phantom)
  1372. {
  1373. return 1;
  1374. }
  1375. return 0;
  1376. case ScriptBaseClass.STATUS_CAST_SHADOWS:
  1377. if ((m_host.GetEffectiveObjectFlags() & (uint)PrimFlags.CastShadows) == (uint)PrimFlags.CastShadows)
  1378. {
  1379. return 1;
  1380. }
  1381. return 0;
  1382. case ScriptBaseClass.STATUS_BLOCK_GRAB:
  1383. return m_host.BlockGrab ? 1 : 0;
  1384. case ScriptBaseClass.STATUS_BLOCK_GRAB_OBJECT:
  1385. return m_host.ParentGroup.BlockGrabOverride ? 1 : 0;
  1386. case ScriptBaseClass.STATUS_DIE_AT_EDGE:
  1387. if (m_host.GetDieAtEdge())
  1388. return 1;
  1389. else
  1390. return 0;
  1391. case ScriptBaseClass.STATUS_RETURN_AT_EDGE:
  1392. if (m_host.GetReturnAtEdge())
  1393. return 1;
  1394. else
  1395. return 0;
  1396. case ScriptBaseClass.STATUS_ROTATE_X:
  1397. // if (m_host.GetAxisRotation(2) != 0)
  1398. if (m_host.GetAxisRotation((int)SceneObjectGroup.axisSelect.STATUS_ROTATE_X) != 0)
  1399. return 1;
  1400. else
  1401. return 0;
  1402. case ScriptBaseClass.STATUS_ROTATE_Y:
  1403. if (m_host.GetAxisRotation((int)SceneObjectGroup.axisSelect.STATUS_ROTATE_Y) != 0)
  1404. return 1;
  1405. else
  1406. return 0;
  1407. case ScriptBaseClass.STATUS_ROTATE_Z:
  1408. if (m_host.GetAxisRotation((int)SceneObjectGroup.axisSelect.STATUS_ROTATE_Z) != 0)
  1409. return 1;
  1410. else
  1411. return 0;
  1412. case ScriptBaseClass.STATUS_SANDBOX:
  1413. if (m_host.GetStatusSandbox())
  1414. return 1;
  1415. else
  1416. return 0;
  1417. }
  1418. return 0;
  1419. }
  1420. public void llSetScale(LSL_Vector scale)
  1421. {
  1422. m_host.AddScriptLPS(1);
  1423. SetScale(m_host, scale);
  1424. }
  1425. protected void SetScale(SceneObjectPart part, LSL_Vector scale)
  1426. {
  1427. // TODO: this needs to trigger a persistance save as well
  1428. if (part == null || part.ParentGroup.IsDeleted)
  1429. return;
  1430. // First we need to check whether or not we need to clamp the size of a physics-enabled prim
  1431. PhysicsActor pa = part.ParentGroup.RootPart.PhysActor;
  1432. if (pa != null && pa.IsPhysical)
  1433. {
  1434. scale.x = Math.Max(World.m_minPhys, Math.Min(World.m_maxPhys, scale.x));
  1435. scale.y = Math.Max(World.m_minPhys, Math.Min(World.m_maxPhys, scale.y));
  1436. scale.z = Math.Max(World.m_minPhys, Math.Min(World.m_maxPhys, scale.z));
  1437. }
  1438. else
  1439. {
  1440. // If not physical, then we clamp the scale to the non-physical min/max
  1441. scale.x = Math.Max(World.m_minNonphys, Math.Min(World.m_maxNonphys, scale.x));
  1442. scale.y = Math.Max(World.m_minNonphys, Math.Min(World.m_maxNonphys, scale.y));
  1443. scale.z = Math.Max(World.m_minNonphys, Math.Min(World.m_maxNonphys, scale.z));
  1444. }
  1445. Vector3 tmp = part.Scale;
  1446. tmp.X = (float)scale.x;
  1447. tmp.Y = (float)scale.y;
  1448. tmp.Z = (float)scale.z;
  1449. part.Scale = tmp;
  1450. part.SendFullUpdateToAllClients();
  1451. }
  1452. public LSL_Vector llGetScale()
  1453. {
  1454. m_host.AddScriptLPS(1);
  1455. return new LSL_Vector(m_host.Scale.X, m_host.Scale.Y, m_host.Scale.Z);
  1456. }
  1457. public void llSetClickAction(int action)
  1458. {
  1459. m_host.AddScriptLPS(1);
  1460. m_host.ClickAction = (byte)action;
  1461. m_host.ParentGroup.HasGroupChanged = true;
  1462. m_host.ScheduleFullUpdate();
  1463. return;
  1464. }
  1465. public void llSetColor(LSL_Vector color, int face)
  1466. {
  1467. m_host.AddScriptLPS(1);
  1468. if (face == ScriptBaseClass.ALL_SIDES)
  1469. face = SceneObjectPart.ALL_SIDES;
  1470. m_host.SetFaceColorAlpha(face, color, null);
  1471. }
  1472. public void llSetContentType(LSL_Key id, LSL_Integer type)
  1473. {
  1474. m_host.AddScriptLPS(1);
  1475. if (m_UrlModule == null)
  1476. return;
  1477. // Make sure the content type is text/plain to start with
  1478. m_UrlModule.HttpContentType(new UUID(id), "text/plain");
  1479. // Is the object owner online and in the region
  1480. ScenePresence agent = World.GetScenePresence(m_host.ParentGroup.OwnerID);
  1481. if (agent == null || agent.IsChildAgent)
  1482. return; // Fail if the owner is not in the same region
  1483. // Is it the embeded browser?
  1484. string userAgent = m_UrlModule.GetHttpHeader(new UUID(id), "user-agent");
  1485. if (userAgent.IndexOf("SecondLife") < 0)
  1486. return; // Not the embedded browser. Is this check good enough?
  1487. // Use the IP address of the client and check against the request
  1488. // seperate logins from the same IP will allow all of them to get non-text/plain as long
  1489. // as the owner is in the region. Same as SL!
  1490. string logonFromIPAddress = agent.ControllingClient.RemoteEndPoint.Address.ToString();
  1491. string requestFromIPAddress = m_UrlModule.GetHttpHeader(new UUID(id), "remote_addr");
  1492. //m_log.Debug("IP from header='" + requestFromIPAddress + "' IP from endpoint='" + logonFromIPAddress + "'");
  1493. if (requestFromIPAddress == null || requestFromIPAddress.Trim() == "")
  1494. return;
  1495. if (logonFromIPAddress == null || logonFromIPAddress.Trim() == "")
  1496. return;
  1497. // If the request isnt from the same IP address then the request cannot be from the owner
  1498. if (!requestFromIPAddress.Trim().Equals(logonFromIPAddress.Trim()))
  1499. return;
  1500. switch (type)
  1501. {
  1502. case ScriptBaseClass.CONTENT_TYPE_HTML:
  1503. m_UrlModule.HttpContentType(new UUID(id), "text/html");
  1504. break;
  1505. case ScriptBaseClass.CONTENT_TYPE_XML:
  1506. m_UrlModule.HttpContentType(new UUID(id), "application/xml");
  1507. break;
  1508. case ScriptBaseClass.CONTENT_TYPE_XHTML:
  1509. m_UrlModule.HttpContentType(new UUID(id), "application/xhtml+xml");
  1510. break;
  1511. case ScriptBaseClass.CONTENT_TYPE_ATOM:
  1512. m_UrlModule.HttpContentType(new UUID(id), "application/atom+xml");
  1513. break;
  1514. case ScriptBaseClass.CONTENT_TYPE_JSON:
  1515. m_UrlModule.HttpContentType(new UUID(id), "application/json");
  1516. break;
  1517. case ScriptBaseClass.CONTENT_TYPE_LLSD:
  1518. m_UrlModule.HttpContentType(new UUID(id), "application/llsd+xml");
  1519. break;
  1520. case ScriptBaseClass.CONTENT_TYPE_FORM:
  1521. m_UrlModule.HttpContentType(new UUID(id), "application/x-www-form-urlencoded");
  1522. break;
  1523. case ScriptBaseClass.CONTENT_TYPE_RSS:
  1524. m_UrlModule.HttpContentType(new UUID(id), "application/rss+xml");
  1525. break;
  1526. default:
  1527. m_UrlModule.HttpContentType(new UUID(id), "text/plain");
  1528. break;
  1529. }
  1530. }
  1531. public void SetTexGen(SceneObjectPart part, int face,int style)
  1532. {
  1533. Primitive.TextureEntry tex = part.Shape.Textures;
  1534. MappingType textype;
  1535. textype = MappingType.Default;
  1536. if (style == (int)ScriptBaseClass.PRIM_TEXGEN_PLANAR)
  1537. textype = MappingType.Planar;
  1538. if (face >= 0 && face < GetNumberOfSides(part))
  1539. {
  1540. tex.CreateFace((uint) face);
  1541. tex.FaceTextures[face].TexMapType = textype;
  1542. part.UpdateTextureEntry(tex.GetBytes());
  1543. return;
  1544. }
  1545. else if (face == ScriptBaseClass.ALL_SIDES)
  1546. {
  1547. for (uint i = 0; i < GetNumberOfSides(part); i++)
  1548. {
  1549. if (tex.FaceTextures[i] != null)
  1550. {
  1551. tex.FaceTextures[i].TexMapType = textype;
  1552. }
  1553. tex.DefaultTexture.TexMapType = textype;
  1554. }
  1555. part.UpdateTextureEntry(tex.GetBytes());
  1556. return;
  1557. }
  1558. }
  1559. public void SetGlow(SceneObjectPart part, int face, float glow)
  1560. {
  1561. Primitive.TextureEntry tex = part.Shape.Textures;
  1562. if (face >= 0 && face < GetNumberOfSides(part))
  1563. {
  1564. tex.CreateFace((uint) face);
  1565. tex.FaceTextures[face].Glow = glow;
  1566. part.UpdateTextureEntry(tex.GetBytes());
  1567. return;
  1568. }
  1569. else if (face == ScriptBaseClass.ALL_SIDES)
  1570. {
  1571. for (uint i = 0; i < GetNumberOfSides(part); i++)
  1572. {
  1573. if (tex.FaceTextures[i] != null)
  1574. {
  1575. tex.FaceTextures[i].Glow = glow;
  1576. }
  1577. tex.DefaultTexture.Glow = glow;
  1578. }
  1579. part.UpdateTextureEntry(tex.GetBytes());
  1580. return;
  1581. }
  1582. }
  1583. public void SetShiny(SceneObjectPart part, int face, int shiny, Bumpiness bump)
  1584. {
  1585. Shininess sval = new Shininess();
  1586. switch (shiny)
  1587. {
  1588. case 0:
  1589. sval = Shininess.None;
  1590. break;
  1591. case 1:
  1592. sval = Shininess.Low;
  1593. break;
  1594. case 2:
  1595. sval = Shininess.Medium;
  1596. break;
  1597. case 3:
  1598. sval = Shininess.High;
  1599. break;
  1600. default:
  1601. sval = Shininess.None;
  1602. break;
  1603. }
  1604. Primitive.TextureEntry tex = part.Shape.Textures;
  1605. if (face >= 0 && face < GetNumberOfSides(part))
  1606. {
  1607. tex.CreateFace((uint) face);
  1608. tex.FaceTextures[face].Shiny = sval;
  1609. tex.FaceTextures[face].Bump = bump;
  1610. part.UpdateTextureEntry(tex.GetBytes());
  1611. return;
  1612. }
  1613. else if (face == ScriptBaseClass.ALL_SIDES)
  1614. {
  1615. for (uint i = 0; i < GetNumberOfSides(part); i++)
  1616. {
  1617. if (tex.FaceTextures[i] != null)
  1618. {
  1619. tex.FaceTextures[i].Shiny = sval;
  1620. tex.FaceTextures[i].Bump = bump;
  1621. }
  1622. tex.DefaultTexture.Shiny = sval;
  1623. tex.DefaultTexture.Bump = bump;
  1624. }
  1625. part.UpdateTextureEntry(tex.GetBytes());
  1626. return;
  1627. }
  1628. }
  1629. public void SetFullBright(SceneObjectPart part, int face, bool bright)
  1630. {
  1631. Primitive.TextureEntry tex = part.Shape.Textures;
  1632. if (face >= 0 && face < GetNumberOfSides(part))
  1633. {
  1634. tex.CreateFace((uint) face);
  1635. tex.FaceTextures[face].Fullbright = bright;
  1636. part.UpdateTextureEntry(tex.GetBytes());
  1637. return;
  1638. }
  1639. else if (face == ScriptBaseClass.ALL_SIDES)
  1640. {
  1641. for (uint i = 0; i < GetNumberOfSides(part); i++)
  1642. {
  1643. if (tex.FaceTextures[i] != null)
  1644. {
  1645. tex.FaceTextures[i].Fullbright = bright;
  1646. }
  1647. }
  1648. tex.DefaultTexture.Fullbright = bright;
  1649. part.UpdateTextureEntry(tex.GetBytes());
  1650. return;
  1651. }
  1652. }
  1653. public LSL_Float llGetAlpha(int face)
  1654. {
  1655. m_host.AddScriptLPS(1);
  1656. return GetAlpha(m_host, face);
  1657. }
  1658. protected LSL_Float GetAlpha(SceneObjectPart part, int face)
  1659. {
  1660. Primitive.TextureEntry tex = part.Shape.Textures;
  1661. if (face == ScriptBaseClass.ALL_SIDES)
  1662. {
  1663. int i;
  1664. double sum = 0.0;
  1665. for (i = 0 ; i < GetNumberOfSides(part); i++)
  1666. sum += (double)tex.GetFace((uint)i).RGBA.A;
  1667. return sum;
  1668. }
  1669. if (face >= 0 && face < GetNumberOfSides(part))
  1670. {
  1671. return (double)tex.GetFace((uint)face).RGBA.A;
  1672. }
  1673. return 0.0;
  1674. }
  1675. public void llSetAlpha(double alpha, int face)
  1676. {
  1677. m_host.AddScriptLPS(1);
  1678. SetAlpha(m_host, alpha, face);
  1679. }
  1680. public void llSetLinkAlpha(int linknumber, double alpha, int face)
  1681. {
  1682. m_host.AddScriptLPS(1);
  1683. List<SceneObjectPart> parts = GetLinkParts(linknumber);
  1684. foreach (SceneObjectPart part in parts)
  1685. SetAlpha(part, alpha, face);
  1686. }
  1687. protected void SetAlpha(SceneObjectPart part, double alpha, int face)
  1688. {
  1689. Primitive.TextureEntry tex = part.Shape.Textures;
  1690. Color4 texcolor;
  1691. if (face >= 0 && face < GetNumberOfSides(part))
  1692. {
  1693. texcolor = tex.CreateFace((uint)face).RGBA;
  1694. texcolor.A = Util.Clip((float)alpha, 0.0f, 1.0f);
  1695. tex.FaceTextures[face].RGBA = texcolor;
  1696. part.UpdateTextureEntry(tex.GetBytes());
  1697. return;
  1698. }
  1699. else if (face == ScriptBaseClass.ALL_SIDES)
  1700. {
  1701. for (int i = 0; i < GetNumberOfSides(part); i++)
  1702. {
  1703. if (tex.FaceTextures[i] != null)
  1704. {
  1705. texcolor = tex.FaceTextures[i].RGBA;
  1706. texcolor.A = Util.Clip((float)alpha, 0.0f, 1.0f);
  1707. tex.FaceTextures[i].RGBA = texcolor;
  1708. }
  1709. }
  1710. // In some cases, the default texture can be null, eg when every face
  1711. // has a unique texture
  1712. if (tex.DefaultTexture != null)
  1713. {
  1714. texcolor = tex.DefaultTexture.RGBA;
  1715. texcolor.A = Util.Clip((float)alpha, 0.0f, 1.0f);
  1716. tex.DefaultTexture.RGBA = texcolor;
  1717. }
  1718. part.UpdateTextureEntry(tex.GetBytes());
  1719. return;
  1720. }
  1721. }
  1722. /// <summary>
  1723. /// Set flexi parameters of a part.
  1724. ///
  1725. /// FIXME: Much of this code should probably be within the part itself.
  1726. /// </summary>
  1727. /// <param name="part"></param>
  1728. /// <param name="flexi"></param>
  1729. /// <param name="softness"></param>
  1730. /// <param name="gravity"></param>
  1731. /// <param name="friction"></param>
  1732. /// <param name="wind"></param>
  1733. /// <param name="tension"></param>
  1734. /// <param name="Force"></param>
  1735. protected void SetFlexi(SceneObjectPart part, bool flexi, int softness, float gravity, float friction,
  1736. float wind, float tension, LSL_Vector Force)
  1737. {
  1738. if (part == null)
  1739. return;
  1740. if (flexi)
  1741. {
  1742. part.Shape.FlexiEntry = true; // this setting flexi true isn't working, but the below parameters do
  1743. // work once the prim is already flexi
  1744. part.Shape.FlexiSoftness = softness;
  1745. part.Shape.FlexiGravity = gravity;
  1746. part.Shape.FlexiDrag = friction;
  1747. part.Shape.FlexiWind = wind;
  1748. part.Shape.FlexiTension = tension;
  1749. part.Shape.FlexiForceX = (float)Force.x;
  1750. part.Shape.FlexiForceY = (float)Force.y;
  1751. part.Shape.FlexiForceZ = (float)Force.z;
  1752. part.Shape.PathCurve = (byte)Extrusion.Flexible;
  1753. }
  1754. else
  1755. {
  1756. // Other values not set, they do not seem to be sent to the viewer
  1757. // Setting PathCurve appears to be what actually toggles the check box and turns Flexi on and off
  1758. part.Shape.PathCurve = (byte)Extrusion.Straight;
  1759. part.Shape.FlexiEntry = false;
  1760. }
  1761. part.ParentGroup.HasGroupChanged = true;
  1762. part.ScheduleFullUpdate();
  1763. }
  1764. /// <summary>
  1765. /// Set a light point on a part
  1766. /// </summary>
  1767. /// FIXME: Much of this code should probably be in SceneObjectGroup
  1768. ///
  1769. /// <param name="part"></param>
  1770. /// <param name="light"></param>
  1771. /// <param name="color"></param>
  1772. /// <param name="intensity"></param>
  1773. /// <param name="radius"></param>
  1774. /// <param name="falloff"></param>
  1775. protected void SetPointLight(SceneObjectPart part, bool light, LSL_Vector color, float intensity, float radius, float falloff)
  1776. {
  1777. if (part == null)
  1778. return;
  1779. if (light)
  1780. {
  1781. part.Shape.LightEntry = true;
  1782. part.Shape.LightColorR = Util.Clip((float)color.x, 0.0f, 1.0f);
  1783. part.Shape.LightColorG = Util.Clip((float)color.y, 0.0f, 1.0f);
  1784. part.Shape.LightColorB = Util.Clip((float)color.z, 0.0f, 1.0f);
  1785. part.Shape.LightIntensity = Util.Clip((float)intensity, 0.0f, 1.0f);
  1786. part.Shape.LightRadius = Util.Clip((float)radius, 0.1f, 20.0f);
  1787. part.Shape.LightFalloff = Util.Clip((float)falloff, 0.01f, 2.0f);
  1788. }
  1789. else
  1790. {
  1791. part.Shape.LightEntry = false;
  1792. }
  1793. part.ParentGroup.HasGroupChanged = true;
  1794. part.ScheduleFullUpdate();
  1795. }
  1796. public LSL_Vector llGetColor(int face)
  1797. {
  1798. m_host.AddScriptLPS(1);
  1799. return GetColor(m_host, face);
  1800. }
  1801. protected LSL_Vector GetColor(SceneObjectPart part, int face)
  1802. {
  1803. Primitive.TextureEntry tex = part.Shape.Textures;
  1804. Color4 texcolor;
  1805. LSL_Vector rgb = new LSL_Vector();
  1806. if (face == ScriptBaseClass.ALL_SIDES)
  1807. {
  1808. int i;
  1809. for (i = 0 ; i < GetNumberOfSides(part); i++)
  1810. {
  1811. texcolor = tex.GetFace((uint)i).RGBA;
  1812. rgb.x += texcolor.R;
  1813. rgb.y += texcolor.G;
  1814. rgb.z += texcolor.B;
  1815. }
  1816. rgb.x /= (float)GetNumberOfSides(part);
  1817. rgb.y /= (float)GetNumberOfSides(part);
  1818. rgb.z /= (float)GetNumberOfSides(part);
  1819. return rgb;
  1820. }
  1821. if (face >= 0 && face < GetNumberOfSides(part))
  1822. {
  1823. texcolor = tex.GetFace((uint)face).RGBA;
  1824. rgb.x = texcolor.R;
  1825. rgb.y = texcolor.G;
  1826. rgb.z = texcolor.B;
  1827. return rgb;
  1828. }
  1829. else
  1830. {
  1831. return new LSL_Vector();
  1832. }
  1833. }
  1834. public void llSetTexture(string texture, int face)
  1835. {
  1836. m_host.AddScriptLPS(1);
  1837. SetTexture(m_host, texture, face);
  1838. ScriptSleep(m_sleepMsOnSetTexture);
  1839. }
  1840. public void llSetLinkTexture(int linknumber, string texture, int face)
  1841. {
  1842. m_host.AddScriptLPS(1);
  1843. List<SceneObjectPart> parts = GetLinkParts(linknumber);
  1844. foreach (SceneObjectPart part in parts)
  1845. SetTexture(part, texture, face);
  1846. ScriptSleep(m_sleepMsOnSetLinkTexture);
  1847. }
  1848. protected void SetTexture(SceneObjectPart part, string texture, int face)
  1849. {
  1850. UUID textureID = new UUID();
  1851. textureID = ScriptUtils.GetAssetIdFromItemName(m_host, texture, (int)AssetType.Texture);
  1852. if (textureID == UUID.Zero)
  1853. {
  1854. if (!UUID.TryParse(texture, out textureID))
  1855. return;
  1856. }
  1857. Primitive.TextureEntry tex = part.Shape.Textures;
  1858. if (face >= 0 && face < GetNumberOfSides(part))
  1859. {
  1860. Primitive.TextureEntryFace texface = tex.CreateFace((uint)face);
  1861. texface.TextureID = textureID;
  1862. tex.FaceTextures[face] = texface;
  1863. part.UpdateTextureEntry(tex.GetBytes());
  1864. return;
  1865. }
  1866. else if (face == ScriptBaseClass.ALL_SIDES)
  1867. {
  1868. for (uint i = 0; i < GetNumberOfSides(part); i++)
  1869. {
  1870. if (tex.FaceTextures[i] != null)
  1871. {
  1872. tex.FaceTextures[i].TextureID = textureID;
  1873. }
  1874. }
  1875. tex.DefaultTexture.TextureID = textureID;
  1876. part.UpdateTextureEntry(tex.GetBytes());
  1877. return;
  1878. }
  1879. }
  1880. public void llScaleTexture(double u, double v, int face)
  1881. {
  1882. m_host.AddScriptLPS(1);
  1883. ScaleTexture(m_host, u, v, face);
  1884. ScriptSleep(m_sleepMsOnScaleTexture);
  1885. }
  1886. protected void ScaleTexture(SceneObjectPart part, double u, double v, int face)
  1887. {
  1888. Primitive.TextureEntry tex = part.Shape.Textures;
  1889. if (face >= 0 && face < GetNumberOfSides(part))
  1890. {
  1891. Primitive.TextureEntryFace texface = tex.CreateFace((uint)face);
  1892. texface.RepeatU = (float)u;
  1893. texface.RepeatV = (float)v;
  1894. tex.FaceTextures[face] = texface;
  1895. part.UpdateTextureEntry(tex.GetBytes());
  1896. return;
  1897. }
  1898. if (face == ScriptBaseClass.ALL_SIDES)
  1899. {
  1900. for (int i = 0; i < GetNumberOfSides(part); i++)
  1901. {
  1902. if (tex.FaceTextures[i] != null)
  1903. {
  1904. tex.FaceTextures[i].RepeatU = (float)u;
  1905. tex.FaceTextures[i].RepeatV = (float)v;
  1906. }
  1907. }
  1908. tex.DefaultTexture.RepeatU = (float)u;
  1909. tex.DefaultTexture.RepeatV = (float)v;
  1910. part.UpdateTextureEntry(tex.GetBytes());
  1911. return;
  1912. }
  1913. }
  1914. public void llOffsetTexture(double u, double v, int face)
  1915. {
  1916. m_host.AddScriptLPS(1);
  1917. OffsetTexture(m_host, u, v, face);
  1918. ScriptSleep(m_sleepMsOnOffsetTexture);
  1919. }
  1920. protected void OffsetTexture(SceneObjectPart part, double u, double v, int face)
  1921. {
  1922. Primitive.TextureEntry tex = part.Shape.Textures;
  1923. if (face >= 0 && face < GetNumberOfSides(part))
  1924. {
  1925. Primitive.TextureEntryFace texface = tex.CreateFace((uint)face);
  1926. texface.OffsetU = (float)u;
  1927. texface.OffsetV = (float)v;
  1928. tex.FaceTextures[face] = texface;
  1929. part.UpdateTextureEntry(tex.GetBytes());
  1930. return;
  1931. }
  1932. if (face == ScriptBaseClass.ALL_SIDES)
  1933. {
  1934. for (int i = 0; i < GetNumberOfSides(part); i++)
  1935. {
  1936. if (tex.FaceTextures[i] != null)
  1937. {
  1938. tex.FaceTextures[i].OffsetU = (float)u;
  1939. tex.FaceTextures[i].OffsetV = (float)v;
  1940. }
  1941. }
  1942. tex.DefaultTexture.OffsetU = (float)u;
  1943. tex.DefaultTexture.OffsetV = (float)v;
  1944. part.UpdateTextureEntry(tex.GetBytes());
  1945. return;
  1946. }
  1947. }
  1948. public void llRotateTexture(double rotation, int face)
  1949. {
  1950. m_host.AddScriptLPS(1);
  1951. RotateTexture(m_host, rotation, face);
  1952. ScriptSleep(m_sleepMsOnRotateTexture);
  1953. }
  1954. protected void RotateTexture(SceneObjectPart part, double rotation, int face)
  1955. {
  1956. Primitive.TextureEntry tex = part.Shape.Textures;
  1957. if (face >= 0 && face < GetNumberOfSides(part))
  1958. {
  1959. Primitive.TextureEntryFace texface = tex.CreateFace((uint)face);
  1960. texface.Rotation = (float)rotation;
  1961. tex.FaceTextures[face] = texface;
  1962. part.UpdateTextureEntry(tex.GetBytes());
  1963. return;
  1964. }
  1965. if (face == ScriptBaseClass.ALL_SIDES)
  1966. {
  1967. for (int i = 0; i < GetNumberOfSides(part); i++)
  1968. {
  1969. if (tex.FaceTextures[i] != null)
  1970. {
  1971. tex.FaceTextures[i].Rotation = (float)rotation;
  1972. }
  1973. }
  1974. tex.DefaultTexture.Rotation = (float)rotation;
  1975. part.UpdateTextureEntry(tex.GetBytes());
  1976. return;
  1977. }
  1978. }
  1979. public LSL_String llGetTexture(int face)
  1980. {
  1981. m_host.AddScriptLPS(1);
  1982. return GetTexture(m_host, face);
  1983. }
  1984. protected LSL_String GetTexture(SceneObjectPart part, int face)
  1985. {
  1986. Primitive.TextureEntry tex = part.Shape.Textures;
  1987. if (face == ScriptBaseClass.ALL_SIDES)
  1988. {
  1989. face = 0;
  1990. }
  1991. if (face >= 0 && face < GetNumberOfSides(part))
  1992. {
  1993. Primitive.TextureEntryFace texface;
  1994. texface = tex.GetFace((uint)face);
  1995. string texture = texface.TextureID.ToString();
  1996. lock (part.TaskInventory)
  1997. {
  1998. foreach (KeyValuePair<UUID, TaskInventoryItem> inv in part.TaskInventory)
  1999. {
  2000. if (inv.Value.AssetID == texface.TextureID)
  2001. {
  2002. texture = inv.Value.Name.ToString();
  2003. break;
  2004. }
  2005. }
  2006. }
  2007. return texture;
  2008. }
  2009. else
  2010. {
  2011. return UUID.Zero.ToString();
  2012. }
  2013. }
  2014. public void llSetPos(LSL_Vector pos)
  2015. {
  2016. m_host.AddScriptLPS(1);
  2017. SetPos(m_host, pos, true);
  2018. ScriptSleep(m_sleepMsOnSetPos);
  2019. }
  2020. /// <summary>
  2021. /// Tries to move the entire object so that the root prim is within 0.1m of position. http://wiki.secondlife.com/wiki/LlSetRegionPos
  2022. /// 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.
  2023. /// 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.
  2024. /// </summary>
  2025. /// <param name="pos"></param>
  2026. /// <returns>1 if successful, 0 otherwise.</returns>
  2027. public LSL_Integer llSetRegionPos(LSL_Vector pos)
  2028. {
  2029. m_host.AddScriptLPS(1);
  2030. // BEGIN WORKAROUND
  2031. // IF YOU GET REGION CROSSINGS WORKING WITH THIS FUNCTION, REPLACE THE WORKAROUND.
  2032. //
  2033. // This workaround is to prevent silent failure of this function.
  2034. // According to the specification on the SL Wiki, providing a position outside of the
  2035. if (pos.x < 0 || pos.x > World.RegionInfo.RegionSizeX || pos.y < 0 || pos.y > World.RegionInfo.RegionSizeY)
  2036. {
  2037. return 0;
  2038. }
  2039. // END WORK AROUND
  2040. else if ( // this is not part of the workaround if-block because it's not related to the workaround.
  2041. IsPhysical() ||
  2042. m_host.ParentGroup.IsAttachment || // return FALSE if attachment
  2043. (
  2044. pos.x < -10.0 || // return FALSE if more than 10 meters into a west-adjacent region.
  2045. pos.x > (World.RegionInfo.RegionSizeX + 10) || // return FALSE if more than 10 meters into a east-adjacent region.
  2046. pos.y < -10.0 || // return FALSE if more than 10 meters into a south-adjacent region.
  2047. pos.y > (World.RegionInfo.RegionSizeY + 10) || // return FALSE if more than 10 meters into a north-adjacent region.
  2048. pos.z > Constants.RegionHeight // return FALSE if altitude than 4096m
  2049. )
  2050. )
  2051. {
  2052. return 0;
  2053. }
  2054. // if we reach this point, then the object is not physical, it's not an attachment, and the destination is within the valid range.
  2055. // 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.
  2056. Vector3 objectPos = m_host.ParentGroup.RootPart.AbsolutePosition;
  2057. LandData here = World.GetLandData(objectPos);
  2058. LandData there = World.GetLandData(pos);
  2059. // 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.
  2060. bool sameParcel = here.GlobalID == there.GlobalID;
  2061. if (!sameParcel && !World.Permissions.CanRezObject(
  2062. m_host.ParentGroup.PrimCount, m_host.ParentGroup.OwnerID, pos))
  2063. {
  2064. return 0;
  2065. }
  2066. SetPos(m_host.ParentGroup.RootPart, pos, false);
  2067. return VecDist(pos, llGetRootPosition()) <= 0.1 ? 1 : 0;
  2068. }
  2069. // Capped movemment if distance > 10m (http://wiki.secondlife.com/wiki/LlSetPos)
  2070. // note linked setpos is capped "differently"
  2071. private LSL_Vector SetPosAdjust(LSL_Vector start, LSL_Vector end)
  2072. {
  2073. if (llVecDist(start, end) > 10.0f * m_ScriptDistanceFactor)
  2074. return start + m_ScriptDistanceFactor * 10.0f * llVecNorm(end - start);
  2075. else
  2076. return end;
  2077. }
  2078. protected LSL_Vector GetSetPosTarget(SceneObjectPart part, LSL_Vector targetPos, LSL_Vector fromPos)
  2079. {
  2080. if (part == null || part.ParentGroup == null || part.ParentGroup.IsDeleted)
  2081. return fromPos;
  2082. // Capped movemment if distance > 10m (http://wiki.secondlife.com/wiki/LlSetPos)
  2083. float ground = World.GetGroundHeight((float)targetPos.x, (float)targetPos.y);
  2084. bool disable_underground_movement = m_ScriptEngine.Config.GetBoolean("DisableUndergroundMovement", true);
  2085. if (part.ParentGroup.RootPart == part)
  2086. {
  2087. if ((targetPos.z < ground) && disable_underground_movement && m_host.ParentGroup.AttachmentPoint == 0)
  2088. targetPos.z = ground;
  2089. }
  2090. LSL_Vector real_vec = SetPosAdjust(fromPos, targetPos);
  2091. return real_vec;
  2092. }
  2093. /// <summary>
  2094. /// set object position, optionally capping the distance.
  2095. /// </summary>
  2096. /// <param name="part"></param>
  2097. /// <param name="targetPos"></param>
  2098. /// <param name="adjust">if TRUE, will cap the distance to 10m.</param>
  2099. protected void SetPos(SceneObjectPart part, LSL_Vector targetPos, bool adjust)
  2100. {
  2101. // Capped movemment if distance > 10m (http://wiki.secondlife.com/wiki/LlSetPos)
  2102. LSL_Vector currentPos = GetPartLocalPos(part);
  2103. float ground = World.GetGroundHeight((float)targetPos.x, (float)targetPos.y);
  2104. bool disable_underground_movement = m_ScriptEngine.Config.GetBoolean("DisableUndergroundMovement", true);
  2105. if (part.ParentGroup.RootPart == part)
  2106. {
  2107. if ((targetPos.z < ground) && disable_underground_movement && m_host.ParentGroup.AttachmentPoint == 0)
  2108. targetPos.z = ground;
  2109. SceneObjectGroup parent = part.ParentGroup;
  2110. parent.UpdateGroupPosition(!adjust ? targetPos :
  2111. SetPosAdjust(currentPos, targetPos));
  2112. }
  2113. else
  2114. {
  2115. part.OffsetPosition = !adjust ? targetPos :
  2116. SetPosAdjust(currentPos, targetPos);
  2117. SceneObjectGroup parent = part.ParentGroup;
  2118. parent.HasGroupChanged = true;
  2119. parent.ScheduleGroupForTerseUpdate();
  2120. }
  2121. }
  2122. public LSL_Vector llGetPos()
  2123. {
  2124. m_host.AddScriptLPS(1);
  2125. return m_host.GetWorldPosition();
  2126. }
  2127. public LSL_Vector llGetLocalPos()
  2128. {
  2129. m_host.AddScriptLPS(1);
  2130. return GetPartLocalPos(m_host);
  2131. }
  2132. protected LSL_Vector GetPartLocalPos(SceneObjectPart part)
  2133. {
  2134. m_host.AddScriptLPS(1);
  2135. Vector3 pos;
  2136. if (!part.IsRoot)
  2137. {
  2138. pos = part.OffsetPosition;
  2139. }
  2140. else
  2141. {
  2142. if (part.ParentGroup.IsAttachment)
  2143. {
  2144. pos = part.AttachedPos;
  2145. }
  2146. else
  2147. {
  2148. pos = part.AbsolutePosition;
  2149. }
  2150. }
  2151. // m_log.DebugFormat("[LSL API]: Returning {0} in GetPartLocalPos()", pos);
  2152. return new LSL_Vector(pos);
  2153. }
  2154. public void llSetRot(LSL_Rotation rot)
  2155. {
  2156. m_host.AddScriptLPS(1);
  2157. // try to let this work as in SL...
  2158. if (m_host.ParentID == 0)
  2159. {
  2160. // special case: If we are root, rotate complete SOG to new rotation
  2161. SetRot(m_host, rot);
  2162. }
  2163. else
  2164. {
  2165. // we are a child. The rotation values will be set to the one of root modified by rot, as in SL. Don't ask.
  2166. SceneObjectPart rootPart = m_host.ParentGroup.RootPart;
  2167. if (rootPart != null) // better safe than sorry
  2168. {
  2169. SetRot(m_host, rootPart.RotationOffset * (Quaternion)rot);
  2170. }
  2171. }
  2172. ScriptSleep(m_sleepMsOnSetRot);
  2173. }
  2174. public void llSetLocalRot(LSL_Rotation rot)
  2175. {
  2176. m_host.AddScriptLPS(1);
  2177. SetRot(m_host, rot);
  2178. ScriptSleep(m_sleepMsOnSetLocalRot);
  2179. }
  2180. protected void SetRot(SceneObjectPart part, Quaternion rot)
  2181. {
  2182. part.UpdateRotation(rot);
  2183. // Update rotation does not move the object in the physics scene if it's a linkset.
  2184. //KF: Do NOT use this next line if using ODE physics engine. This need a switch based on .ini Phys Engine type
  2185. // part.ParentGroup.AbsolutePosition = part.ParentGroup.AbsolutePosition;
  2186. // So, after thinking about this for a bit, the issue with the part.ParentGroup.AbsolutePosition = part.ParentGroup.AbsolutePosition line
  2187. // is it isn't compatible with vehicles because it causes the vehicle body to have to be broken down and rebuilt
  2188. // It's perfectly okay when the object is not an active physical body though.
  2189. // So, part.ParentGroup.ResetChildPrimPhysicsPositions(); does the thing that Kitto is warning against
  2190. // but only if the object is not physial and active. This is important for rotating doors.
  2191. // without the absoluteposition = absoluteposition happening, the doors do not move in the physics
  2192. // scene
  2193. PhysicsActor pa = part.PhysActor;
  2194. if (pa != null && !pa.IsPhysical)
  2195. {
  2196. part.ParentGroup.ResetChildPrimPhysicsPositions();
  2197. }
  2198. }
  2199. /// <summary>
  2200. /// See http://lslwiki.net/lslwiki/wakka.php?wakka=ChildRotation
  2201. /// </summary>
  2202. public LSL_Rotation llGetRot()
  2203. {
  2204. // unlinked or root prim then use llRootRotation
  2205. // see llRootRotaion for references.
  2206. if (m_host.LinkNum == 0 || m_host.LinkNum == 1)
  2207. {
  2208. return llGetRootRotation();
  2209. }
  2210. m_host.AddScriptLPS(1);
  2211. Quaternion q = m_host.GetWorldRotation();
  2212. return new LSL_Rotation(q.X, q.Y, q.Z, q.W);
  2213. }
  2214. private LSL_Rotation GetPartRot(SceneObjectPart part)
  2215. {
  2216. Quaternion q;
  2217. if (part.LinkNum == 0 || part.LinkNum == 1) // unlinked or root prim
  2218. {
  2219. if (part.ParentGroup.AttachmentPoint != 0)
  2220. {
  2221. ScenePresence avatar = World.GetScenePresence(part.ParentGroup.AttachedAvatar);
  2222. if (avatar != null)
  2223. {
  2224. if ((avatar.AgentControlFlags & (uint)AgentManager.ControlFlags.AGENT_CONTROL_MOUSELOOK) != 0)
  2225. q = avatar.CameraRotation; // Mouselook
  2226. else
  2227. q = avatar.GetWorldRotation(); // Currently infrequently updated so may be inaccurate
  2228. }
  2229. else
  2230. q = part.ParentGroup.GroupRotation; // Likely never get here but just in case
  2231. }
  2232. else
  2233. q = part.ParentGroup.GroupRotation; // just the group rotation
  2234. return new LSL_Rotation(q);
  2235. }
  2236. return new LSL_Rotation(part.GetWorldRotation());
  2237. }
  2238. public LSL_Rotation llGetLocalRot()
  2239. {
  2240. m_host.AddScriptLPS(1);
  2241. return new LSL_Rotation(m_host.RotationOffset);
  2242. }
  2243. public void llSetForce(LSL_Vector force, int local)
  2244. {
  2245. m_host.AddScriptLPS(1);
  2246. if (!m_host.ParentGroup.IsDeleted)
  2247. {
  2248. if (local != 0)
  2249. force *= llGetRot();
  2250. m_host.ParentGroup.RootPart.SetForce(force);
  2251. }
  2252. }
  2253. public LSL_Vector llGetForce()
  2254. {
  2255. LSL_Vector force = new LSL_Vector(0.0, 0.0, 0.0);
  2256. m_host.AddScriptLPS(1);
  2257. if (!m_host.ParentGroup.IsDeleted)
  2258. {
  2259. force = m_host.ParentGroup.RootPart.GetForce();
  2260. }
  2261. return force;
  2262. }
  2263. public void llSetVelocity(LSL_Vector velocity, int local)
  2264. {
  2265. m_host.AddScriptLPS(1);
  2266. if (!m_host.ParentGroup.IsDeleted)
  2267. {
  2268. if (local != 0)
  2269. velocity *= llGetRot();
  2270. m_host.ParentGroup.RootPart.Velocity = velocity;
  2271. }
  2272. }
  2273. public void llSetAngularVelocity(LSL_Vector angularVelocity, int local)
  2274. {
  2275. m_host.AddScriptLPS(1);
  2276. if (!m_host.ParentGroup.IsDeleted)
  2277. {
  2278. if (local != 0)
  2279. angularVelocity *= llGetRot();
  2280. m_host.ParentGroup.RootPart.AngularVelocity = angularVelocity;
  2281. }
  2282. }
  2283. public LSL_Integer llTarget(LSL_Vector position, double range)
  2284. {
  2285. m_host.AddScriptLPS(1);
  2286. return m_host.ParentGroup.registerTargetWaypoint(position,
  2287. (float)range);
  2288. }
  2289. public void llTargetRemove(int number)
  2290. {
  2291. m_host.AddScriptLPS(1);
  2292. m_host.ParentGroup.unregisterTargetWaypoint(number);
  2293. }
  2294. public LSL_Integer llRotTarget(LSL_Rotation rot, double error)
  2295. {
  2296. m_host.AddScriptLPS(1);
  2297. return m_host.ParentGroup.registerRotTargetWaypoint(rot, (float)error);
  2298. }
  2299. public void llRotTargetRemove(int number)
  2300. {
  2301. m_host.AddScriptLPS(1);
  2302. m_host.ParentGroup.unregisterRotTargetWaypoint(number);
  2303. }
  2304. public void llMoveToTarget(LSL_Vector target, double tau)
  2305. {
  2306. m_host.AddScriptLPS(1);
  2307. m_host.MoveToTarget(target, (float)tau);
  2308. }
  2309. public void llStopMoveToTarget()
  2310. {
  2311. m_host.AddScriptLPS(1);
  2312. m_host.StopMoveToTarget();
  2313. }
  2314. public void llApplyImpulse(LSL_Vector force, int local)
  2315. {
  2316. m_host.AddScriptLPS(1);
  2317. //No energy force yet
  2318. Vector3 v = force;
  2319. if (v.Length() > 20000.0f)
  2320. {
  2321. v.Normalize();
  2322. v = v * 20000.0f;
  2323. }
  2324. m_host.ApplyImpulse(v, local != 0);
  2325. }
  2326. public void llApplyRotationalImpulse(LSL_Vector force, int local)
  2327. {
  2328. m_host.AddScriptLPS(1);
  2329. m_host.ApplyAngularImpulse(force, local != 0);
  2330. }
  2331. public void llSetTorque(LSL_Vector torque, int local)
  2332. {
  2333. m_host.AddScriptLPS(1);
  2334. m_host.SetAngularImpulse(torque, local != 0);
  2335. }
  2336. public LSL_Vector llGetTorque()
  2337. {
  2338. m_host.AddScriptLPS(1);
  2339. return new LSL_Vector(m_host.ParentGroup.GetTorque());
  2340. }
  2341. public void llSetForceAndTorque(LSL_Vector force, LSL_Vector torque, int local)
  2342. {
  2343. m_host.AddScriptLPS(1);
  2344. llSetForce(force, local);
  2345. llSetTorque(torque, local);
  2346. }
  2347. public LSL_Vector llGetVel()
  2348. {
  2349. m_host.AddScriptLPS(1);
  2350. Vector3 vel;
  2351. if (m_host.ParentGroup.IsAttachment)
  2352. {
  2353. ScenePresence avatar = m_host.ParentGroup.Scene.GetScenePresence(m_host.ParentGroup.AttachedAvatar);
  2354. vel = avatar.GetWorldVelocity();
  2355. }
  2356. else
  2357. {
  2358. vel = m_host.Velocity;
  2359. }
  2360. return new LSL_Vector(vel);
  2361. }
  2362. public LSL_Vector llGetAccel()
  2363. {
  2364. m_host.AddScriptLPS(1);
  2365. return new LSL_Vector(m_host.Acceleration);
  2366. }
  2367. public LSL_Vector llGetOmega()
  2368. {
  2369. m_host.AddScriptLPS(1);
  2370. return new LSL_Vector(m_host.AngularVelocity);
  2371. }
  2372. public LSL_Float llGetTimeOfDay()
  2373. {
  2374. m_host.AddScriptLPS(1);
  2375. return (double)((DateTime.Now.TimeOfDay.TotalMilliseconds / 1000) % (3600 * 4));
  2376. }
  2377. public LSL_Float llGetWallclock()
  2378. {
  2379. m_host.AddScriptLPS(1);
  2380. return DateTime.Now.TimeOfDay.TotalSeconds;
  2381. }
  2382. public LSL_Float llGetTime()
  2383. {
  2384. m_host.AddScriptLPS(1);
  2385. TimeSpan ScriptTime = DateTime.Now - m_timer;
  2386. return (double)(ScriptTime.TotalMilliseconds / 1000);
  2387. }
  2388. public void llResetTime()
  2389. {
  2390. m_host.AddScriptLPS(1);
  2391. m_timer = DateTime.Now;
  2392. }
  2393. public LSL_Float llGetAndResetTime()
  2394. {
  2395. m_host.AddScriptLPS(1);
  2396. TimeSpan ScriptTime = DateTime.Now - m_timer;
  2397. m_timer = DateTime.Now;
  2398. return (double)(ScriptTime.TotalMilliseconds / 1000);
  2399. }
  2400. public void llSound(string sound, double volume, int queue, int loop)
  2401. {
  2402. m_host.AddScriptLPS(1);
  2403. Deprecated("llSound", "Use llPlaySound instead");
  2404. }
  2405. // Xantor 20080528 PlaySound updated so it accepts an objectinventory name -or- a key to a sound
  2406. // 20080530 Updated to remove code duplication
  2407. public void llPlaySound(string sound, double volume)
  2408. {
  2409. m_host.AddScriptLPS(1);
  2410. // send the sound, once, to all clients in range
  2411. if (m_SoundModule != null)
  2412. {
  2413. m_SoundModule.SendSound(
  2414. m_host.UUID,
  2415. ScriptUtils.GetAssetIdFromKeyOrItemName(m_host, sound, AssetType.Sound),
  2416. volume, false, m_host.SoundQueueing ? (byte)SoundFlags.Queue : (byte)SoundFlags.None,
  2417. 0, false, false);
  2418. }
  2419. }
  2420. public void llLoopSound(string sound, double volume)
  2421. {
  2422. m_host.AddScriptLPS(1);
  2423. if (m_SoundModule != null)
  2424. {
  2425. m_SoundModule.LoopSound(m_host.UUID, ScriptUtils.GetAssetIdFromKeyOrItemName(m_host, sound),
  2426. volume, 20, false);
  2427. }
  2428. }
  2429. public void llLoopSoundMaster(string sound, double volume)
  2430. {
  2431. m_host.AddScriptLPS(1);
  2432. if (m_SoundModule != null)
  2433. {
  2434. m_SoundModule.LoopSound(m_host.UUID, ScriptUtils.GetAssetIdFromKeyOrItemName(m_host, sound),
  2435. volume, 20, true);
  2436. }
  2437. }
  2438. public void llLoopSoundSlave(string sound, double volume)
  2439. {
  2440. m_host.AddScriptLPS(1);
  2441. lock (m_host.ParentGroup.LoopSoundSlavePrims)
  2442. {
  2443. m_host.ParentGroup.LoopSoundSlavePrims.Add(m_host);
  2444. }
  2445. }
  2446. public void llPlaySoundSlave(string sound, double volume)
  2447. {
  2448. m_host.AddScriptLPS(1);
  2449. // send the sound, once, to all clients in range
  2450. if (m_SoundModule != null)
  2451. {
  2452. m_SoundModule.SendSound(m_host.UUID,
  2453. ScriptUtils.GetAssetIdFromKeyOrItemName(m_host, sound, AssetType.Sound), volume, false, 0,
  2454. 0, true, false);
  2455. }
  2456. }
  2457. public void llTriggerSound(string sound, double volume)
  2458. {
  2459. m_host.AddScriptLPS(1);
  2460. // send the sound, once, to all clients in rangeTrigger or play an attached sound in this part's inventory.
  2461. if (m_SoundModule != null)
  2462. {
  2463. m_SoundModule.SendSound(m_host.UUID,
  2464. ScriptUtils.GetAssetIdFromKeyOrItemName(m_host, sound, AssetType.Sound), volume, true, 0, 0,
  2465. false, false);
  2466. }
  2467. }
  2468. public void llStopSound()
  2469. {
  2470. m_host.AddScriptLPS(1);
  2471. if (m_SoundModule != null)
  2472. m_SoundModule.StopSound(m_host.UUID);
  2473. }
  2474. public void llPreloadSound(string sound)
  2475. {
  2476. m_host.AddScriptLPS(1);
  2477. if (m_SoundModule != null)
  2478. m_SoundModule.PreloadSound(m_host.UUID, ScriptUtils.GetAssetIdFromKeyOrItemName(m_host, sound), 0);
  2479. ScriptSleep(m_sleepMsOnPreloadSound);
  2480. }
  2481. /// <summary>
  2482. /// Return a portion of the designated string bounded by
  2483. /// inclusive indices (start and end). As usual, the negative
  2484. /// indices, and the tolerance for out-of-bound values, makes
  2485. /// this more complicated than it might otherwise seem.
  2486. /// </summary>
  2487. public LSL_String llGetSubString(string src, int start, int end)
  2488. {
  2489. m_host.AddScriptLPS(1);
  2490. // Normalize indices (if negative).
  2491. // After normlaization they may still be
  2492. // negative, but that is now relative to
  2493. // the start, rather than the end, of the
  2494. // sequence.
  2495. if (start < 0)
  2496. {
  2497. start = src.Length+start;
  2498. }
  2499. if (end < 0)
  2500. {
  2501. end = src.Length+end;
  2502. }
  2503. // Conventional substring
  2504. if (start <= end)
  2505. {
  2506. // Implies both bounds are out-of-range.
  2507. if (end < 0 || start >= src.Length)
  2508. {
  2509. return String.Empty;
  2510. }
  2511. // If end is positive, then it directly
  2512. // corresponds to the lengt of the substring
  2513. // needed (plus one of course). BUT, it
  2514. // must be within bounds.
  2515. if (end >= src.Length)
  2516. {
  2517. end = src.Length-1;
  2518. }
  2519. if (start < 0)
  2520. {
  2521. return src.Substring(0,end+1);
  2522. }
  2523. // Both indices are positive
  2524. return src.Substring(start, (end+1) - start);
  2525. }
  2526. // Inverted substring (end < start)
  2527. else
  2528. {
  2529. // Implies both indices are below the
  2530. // lower bound. In the inverted case, that
  2531. // means the entire string will be returned
  2532. // unchanged.
  2533. if (start < 0)
  2534. {
  2535. return src;
  2536. }
  2537. // If both indices are greater than the upper
  2538. // bound the result may seem initially counter
  2539. // intuitive.
  2540. if (end >= src.Length)
  2541. {
  2542. return src;
  2543. }
  2544. if (end < 0)
  2545. {
  2546. if (start < src.Length)
  2547. {
  2548. return src.Substring(start);
  2549. }
  2550. else
  2551. {
  2552. return String.Empty;
  2553. }
  2554. }
  2555. else
  2556. {
  2557. if (start < src.Length)
  2558. {
  2559. return src.Substring(0,end+1) + src.Substring(start);
  2560. }
  2561. else
  2562. {
  2563. return src.Substring(0,end+1);
  2564. }
  2565. }
  2566. }
  2567. }
  2568. /// <summary>
  2569. /// Delete substring removes the specified substring bounded
  2570. /// by the inclusive indices start and end. Indices may be
  2571. /// negative (indicating end-relative) and may be inverted,
  2572. /// i.e. end < start.
  2573. /// </summary>
  2574. public LSL_String llDeleteSubString(string src, int start, int end)
  2575. {
  2576. m_host.AddScriptLPS(1);
  2577. // Normalize indices (if negative).
  2578. // After normlaization they may still be
  2579. // negative, but that is now relative to
  2580. // the start, rather than the end, of the
  2581. // sequence.
  2582. if (start < 0)
  2583. {
  2584. start = src.Length+start;
  2585. }
  2586. if (end < 0)
  2587. {
  2588. end = src.Length+end;
  2589. }
  2590. // Conventionally delimited substring
  2591. if (start <= end)
  2592. {
  2593. // If both bounds are outside of the existing
  2594. // string, then return unchanges.
  2595. if (end < 0 || start >= src.Length)
  2596. {
  2597. return src;
  2598. }
  2599. // At least one bound is in-range, so we
  2600. // need to clip the out-of-bound argument.
  2601. if (start < 0)
  2602. {
  2603. start = 0;
  2604. }
  2605. if (end >= src.Length)
  2606. {
  2607. end = src.Length-1;
  2608. }
  2609. return src.Remove(start,end-start+1);
  2610. }
  2611. // Inverted substring
  2612. else
  2613. {
  2614. // In this case, out of bounds means that
  2615. // the existing string is part of the cut.
  2616. if (start < 0 || end >= src.Length)
  2617. {
  2618. return String.Empty;
  2619. }
  2620. if (end > 0)
  2621. {
  2622. if (start < src.Length)
  2623. {
  2624. return src.Remove(start).Remove(0,end+1);
  2625. }
  2626. else
  2627. {
  2628. return src.Remove(0,end+1);
  2629. }
  2630. }
  2631. else
  2632. {
  2633. if (start < src.Length)
  2634. {
  2635. return src.Remove(start);
  2636. }
  2637. else
  2638. {
  2639. return src;
  2640. }
  2641. }
  2642. }
  2643. }
  2644. /// <summary>
  2645. /// Insert string inserts the specified string identified by src
  2646. /// at the index indicated by index. Index may be negative, in
  2647. /// which case it is end-relative. The index may exceed either
  2648. /// string bound, with the result being a concatenation.
  2649. /// </summary>
  2650. public LSL_String llInsertString(string dest, int index, string src)
  2651. {
  2652. m_host.AddScriptLPS(1);
  2653. // Normalize indices (if negative).
  2654. // After normlaization they may still be
  2655. // negative, but that is now relative to
  2656. // the start, rather than the end, of the
  2657. // sequence.
  2658. if (index < 0)
  2659. {
  2660. index = dest.Length+index;
  2661. // Negative now means it is less than the lower
  2662. // bound of the string.
  2663. if (index < 0)
  2664. {
  2665. return src+dest;
  2666. }
  2667. }
  2668. if (index >= dest.Length)
  2669. {
  2670. return dest+src;
  2671. }
  2672. // The index is in bounds.
  2673. // In this case the index refers to the index that will
  2674. // be assigned to the first character of the inserted string.
  2675. // So unlike the other string operations, we do not add one
  2676. // to get the correct string length.
  2677. return dest.Substring(0,index)+src+dest.Substring(index);
  2678. }
  2679. public LSL_String llToUpper(string src)
  2680. {
  2681. m_host.AddScriptLPS(1);
  2682. return src.ToUpper();
  2683. }
  2684. public LSL_String llToLower(string src)
  2685. {
  2686. m_host.AddScriptLPS(1);
  2687. return src.ToLower();
  2688. }
  2689. public void llGiveMoney(string destination, int amount)
  2690. {
  2691. Util.FireAndForget(x =>
  2692. {
  2693. m_host.AddScriptLPS(1);
  2694. if (m_item.PermsGranter == UUID.Zero)
  2695. return;
  2696. if ((m_item.PermsMask & ScriptBaseClass.PERMISSION_DEBIT) == 0)
  2697. {
  2698. Error("llGiveMoney", "No permissions to give money");
  2699. return;
  2700. }
  2701. UUID toID = new UUID();
  2702. if (!UUID.TryParse(destination, out toID))
  2703. {
  2704. Error("llGiveMoney", "Bad key in llGiveMoney");
  2705. return;
  2706. }
  2707. IMoneyModule money = World.RequestModuleInterface<IMoneyModule>();
  2708. if (money == null)
  2709. {
  2710. NotImplemented("llGiveMoney");
  2711. return;
  2712. }
  2713. money.ObjectGiveMoney(
  2714. m_host.ParentGroup.RootPart.UUID, m_host.ParentGroup.RootPart.OwnerID, toID, amount);
  2715. }, null, "LSL_Api.llGiveMoney");
  2716. }
  2717. public void llMakeExplosion(int particles, double scale, double vel, double lifetime, double arc, string texture, LSL_Vector offset)
  2718. {
  2719. m_host.AddScriptLPS(1);
  2720. Deprecated("llMakeExplosion", "Use llParticleSystem instead");
  2721. ScriptSleep(m_sleepMsOnMakeExplosion);
  2722. }
  2723. public void llMakeFountain(int particles, double scale, double vel, double lifetime, double arc, int bounce, string texture, LSL_Vector offset, double bounce_offset)
  2724. {
  2725. m_host.AddScriptLPS(1);
  2726. Deprecated("llMakeFountain", "Use llParticleSystem instead");
  2727. ScriptSleep(m_sleepMsOnMakeFountain);
  2728. }
  2729. public void llMakeSmoke(int particles, double scale, double vel, double lifetime, double arc, string texture, LSL_Vector offset)
  2730. {
  2731. m_host.AddScriptLPS(1);
  2732. Deprecated("llMakeSmoke", "Use llParticleSystem instead");
  2733. ScriptSleep(m_sleepMsOnMakeSmoke);
  2734. }
  2735. public void llMakeFire(int particles, double scale, double vel, double lifetime, double arc, string texture, LSL_Vector offset)
  2736. {
  2737. m_host.AddScriptLPS(1);
  2738. Deprecated("llMakeFire", "Use llParticleSystem instead");
  2739. ScriptSleep(m_sleepMsOnMakeFire);
  2740. }
  2741. public void llRezAtRoot(string inventory, LSL_Vector pos, LSL_Vector vel, LSL_Rotation rot, int param)
  2742. {
  2743. m_host.AddScriptLPS(1);
  2744. Util.FireAndForget(x =>
  2745. {
  2746. if (Double.IsNaN(rot.x) || Double.IsNaN(rot.y) || Double.IsNaN(rot.z) || Double.IsNaN(rot.s))
  2747. return;
  2748. float dist = (float)llVecDist(llGetPos(), pos);
  2749. if (dist > m_ScriptDistanceFactor * 10.0f)
  2750. return;
  2751. TaskInventoryItem item = m_host.Inventory.GetInventoryItem(inventory);
  2752. if (item == null)
  2753. {
  2754. Error("llRezAtRoot", "Can't find object '" + inventory + "'");
  2755. return;
  2756. }
  2757. if (item.InvType != (int)InventoryType.Object)
  2758. {
  2759. Error("llRezAtRoot", "Can't create requested object; object is missing from database");
  2760. return;
  2761. }
  2762. // need the magnitude later
  2763. // float velmag = (float)Util.GetMagnitude(llvel);
  2764. List<SceneObjectGroup> new_groups = World.RezObject(m_host, item, pos, rot, vel, param);
  2765. // If either of these are null, then there was an unknown error.
  2766. if (new_groups == null)
  2767. return;
  2768. foreach (SceneObjectGroup group in new_groups)
  2769. {
  2770. // objects rezzed with this method are die_at_edge by default.
  2771. group.RootPart.SetDieAtEdge(true);
  2772. group.ResumeScripts();
  2773. m_ScriptEngine.PostObjectEvent(m_host.LocalId, new EventParams(
  2774. "object_rez", new Object[] {
  2775. new LSL_String(
  2776. group.RootPart.UUID.ToString()) },
  2777. new DetectParams[0]));
  2778. float groupmass = group.GetMass();
  2779. PhysicsActor pa = group.RootPart.PhysActor;
  2780. //Recoil.
  2781. if (pa != null && pa.IsPhysical && (Vector3)vel != Vector3.Zero)
  2782. {
  2783. Vector3 recoil = -vel * groupmass * m_recoilScaleFactor;
  2784. if (recoil != Vector3.Zero)
  2785. {
  2786. llApplyImpulse(recoil, 0);
  2787. }
  2788. }
  2789. // Variable script delay? (see (http://wiki.secondlife.com/wiki/LSL_Delay)
  2790. }
  2791. }, null, "LSL_Api.llRezAtRoot");
  2792. //ScriptSleep((int)((groupmass * velmag) / 10));
  2793. ScriptSleep(m_sleepMsOnRezAtRoot);
  2794. }
  2795. public void llRezObject(string inventory, LSL_Vector pos, LSL_Vector vel, LSL_Rotation rot, int param)
  2796. {
  2797. llRezAtRoot(inventory, pos, vel, rot, param);
  2798. }
  2799. public void llLookAt(LSL_Vector target, double strength, double damping)
  2800. {
  2801. m_host.AddScriptLPS(1);
  2802. // Determine where we are looking from
  2803. LSL_Vector from = llGetPos();
  2804. // normalized direction to target
  2805. LSL_Vector dir = llVecNorm(target - from);
  2806. // use vertical to help compute left axis
  2807. LSL_Vector up = new LSL_Vector(0.0, 0.0, 1.0);
  2808. // find normalized left axis parallel to horizon
  2809. LSL_Vector left = llVecNorm(LSL_Vector.Cross(up, dir));
  2810. // make up orthogonal to left and dir
  2811. up = LSL_Vector.Cross(dir, left);
  2812. // compute rotation based on orthogonal axes
  2813. LSL_Rotation rot = new LSL_Rotation(0.0, 0.707107, 0.0, 0.707107) * llAxes2Rot(dir, left, up);
  2814. // Per discussion with Melanie, for non-physical objects llLookAt appears to simply
  2815. // set the rotation of the object, copy that behavior
  2816. PhysicsActor pa = m_host.PhysActor;
  2817. if (m_host.ParentGroup.IsAttachment || strength == 0 || pa == null || !pa.IsPhysical)
  2818. {
  2819. llSetRot(rot);
  2820. }
  2821. else
  2822. {
  2823. m_host.StartLookAt(rot, (float)strength, (float)damping);
  2824. }
  2825. }
  2826. public void llStopLookAt()
  2827. {
  2828. m_host.AddScriptLPS(1);
  2829. m_host.StopLookAt();
  2830. }
  2831. public void llSetTimerEvent(double sec)
  2832. {
  2833. if (sec != 0.0 && sec < m_MinTimerInterval)
  2834. sec = m_MinTimerInterval;
  2835. m_host.AddScriptLPS(1);
  2836. // Setting timer repeat
  2837. AsyncCommands.TimerPlugin.SetTimerEvent(m_host.LocalId, m_item.ItemID, sec);
  2838. }
  2839. public virtual void llSleep(double sec)
  2840. {
  2841. // m_log.Info("llSleep snoozing " + sec + "s.");
  2842. m_host.AddScriptLPS(1);
  2843. Sleep((int)(sec * 1000));
  2844. }
  2845. public LSL_Float llGetMass()
  2846. {
  2847. m_host.AddScriptLPS(1);
  2848. if (m_host.ParentGroup.IsAttachment)
  2849. {
  2850. ScenePresence attachedAvatar = World.GetScenePresence(m_host.ParentGroup.AttachedAvatar);
  2851. if (attachedAvatar != null)
  2852. {
  2853. return attachedAvatar.GetMass();
  2854. }
  2855. else
  2856. {
  2857. return 0;
  2858. }
  2859. }
  2860. else
  2861. {
  2862. if (m_host.IsRoot)
  2863. {
  2864. return m_host.ParentGroup.GetMass();
  2865. }
  2866. else
  2867. {
  2868. return m_host.GetMass();
  2869. }
  2870. }
  2871. }
  2872. public LSL_Float llGetMassMKS()
  2873. {
  2874. // this is what the wiki says it does!
  2875. // http://wiki.secondlife.com/wiki/LlGetMassMKS
  2876. return llGetMass() * 100.0;
  2877. }
  2878. public void llCollisionFilter(string name, string id, int accept)
  2879. {
  2880. m_host.AddScriptLPS(1);
  2881. m_host.CollisionFilter.Clear();
  2882. UUID objectID;
  2883. if (!UUID.TryParse(id, out objectID))
  2884. objectID = UUID.Zero;
  2885. if (objectID == UUID.Zero && name == "")
  2886. return;
  2887. m_host.CollisionFilter.Add(accept,objectID.ToString() + name);
  2888. }
  2889. public void llTakeControls(int controls, int accept, int pass_on)
  2890. {
  2891. if (m_item.PermsGranter != UUID.Zero)
  2892. {
  2893. ScenePresence presence = World.GetScenePresence(m_item.PermsGranter);
  2894. if (presence != null)
  2895. {
  2896. if ((m_item.PermsMask & ScriptBaseClass.PERMISSION_TAKE_CONTROLS) != 0)
  2897. {
  2898. presence.RegisterControlEventsToScript(controls, accept, pass_on, m_host.LocalId, m_item.ItemID);
  2899. }
  2900. }
  2901. }
  2902. m_host.AddScriptLPS(1);
  2903. }
  2904. public void llReleaseControls()
  2905. {
  2906. m_host.AddScriptLPS(1);
  2907. if (m_item.PermsGranter != UUID.Zero)
  2908. {
  2909. ScenePresence presence = World.GetScenePresence(m_item.PermsGranter);
  2910. if (presence != null)
  2911. {
  2912. if ((m_item.PermsMask & ScriptBaseClass.PERMISSION_TAKE_CONTROLS) != 0)
  2913. {
  2914. // Unregister controls from Presence
  2915. presence.UnRegisterControlEventsToScript(m_host.LocalId, m_item.ItemID);
  2916. // Remove Take Control permission.
  2917. m_item.PermsMask &= ~ScriptBaseClass.PERMISSION_TAKE_CONTROLS;
  2918. }
  2919. }
  2920. }
  2921. }
  2922. public void llReleaseURL(string url)
  2923. {
  2924. m_host.AddScriptLPS(1);
  2925. if (m_UrlModule != null)
  2926. m_UrlModule.ReleaseURL(url);
  2927. }
  2928. /// <summary>
  2929. /// Attach the object containing this script to the avatar that owns it.
  2930. /// </summary>
  2931. /// <param name='attachmentPoint'>
  2932. /// The attachment point (e.g. <see cref="OpenSim.Region.ScriptEngine.Shared.ScriptBase.ScriptBaseClass.ATTACH_CHEST">ATTACH_CHEST</see>)
  2933. /// </param>
  2934. /// <returns>true if the attach suceeded, false if it did not</returns>
  2935. public bool AttachToAvatar(int attachmentPoint)
  2936. {
  2937. SceneObjectGroup grp = m_host.ParentGroup;
  2938. ScenePresence presence = World.GetScenePresence(m_host.OwnerID);
  2939. IAttachmentsModule attachmentsModule = m_ScriptEngine.World.AttachmentsModule;
  2940. if (attachmentsModule != null)
  2941. return attachmentsModule.AttachObject(presence, grp, (uint)attachmentPoint, false, true, true);
  2942. else
  2943. return false;
  2944. }
  2945. /// <summary>
  2946. /// Detach the object containing this script from the avatar it is attached to.
  2947. /// </summary>
  2948. /// <remarks>
  2949. /// Nothing happens if the object is not attached.
  2950. /// </remarks>
  2951. public void DetachFromAvatar()
  2952. {
  2953. Util.FireAndForget(DetachWrapper, m_host, "LSL_Api.DetachFromAvatar");
  2954. }
  2955. private void DetachWrapper(object o)
  2956. {
  2957. if (World.AttachmentsModule != null)
  2958. {
  2959. SceneObjectPart host = (SceneObjectPart)o;
  2960. ScenePresence presence = World.GetScenePresence(host.OwnerID);
  2961. World.AttachmentsModule.DetachSingleAttachmentToInv(presence, host.ParentGroup);
  2962. }
  2963. }
  2964. public void llAttachToAvatar(int attachmentPoint)
  2965. {
  2966. m_host.AddScriptLPS(1);
  2967. // if (m_host.ParentGroup.RootPart.AttachmentPoint == 0)
  2968. // return;
  2969. if (m_item.PermsGranter != m_host.OwnerID)
  2970. return;
  2971. if ((m_item.PermsMask & ScriptBaseClass.PERMISSION_ATTACH) != 0)
  2972. AttachToAvatar(attachmentPoint);
  2973. }
  2974. public void llDetachFromAvatar()
  2975. {
  2976. m_host.AddScriptLPS(1);
  2977. if (m_host.ParentGroup.AttachmentPoint == 0)
  2978. return;
  2979. if (m_item.PermsGranter != m_host.OwnerID)
  2980. return;
  2981. if ((m_item.PermsMask & ScriptBaseClass.PERMISSION_ATTACH) != 0)
  2982. DetachFromAvatar();
  2983. }
  2984. public void llTakeCamera(string avatar)
  2985. {
  2986. m_host.AddScriptLPS(1);
  2987. Deprecated("llTakeCamera", "Use llSetCameraParams instead");
  2988. }
  2989. public void llReleaseCamera(string avatar)
  2990. {
  2991. m_host.AddScriptLPS(1);
  2992. Deprecated("llReleaseCamera", "Use llClearCameraParams instead");
  2993. }
  2994. public LSL_String llGetOwner()
  2995. {
  2996. m_host.AddScriptLPS(1);
  2997. return m_host.OwnerID.ToString();
  2998. }
  2999. public void llInstantMessage(string user, string message)
  3000. {
  3001. m_host.AddScriptLPS(1);
  3002. // We may be able to use ClientView.SendInstantMessage here, but we need a client instance.
  3003. // InstantMessageModule.OnInstantMessage searches through a list of scenes for a client matching the toAgent,
  3004. // but I don't think we have a list of scenes available from here.
  3005. // (We also don't want to duplicate the code in OnInstantMessage if we can avoid it.)
  3006. // user is a UUID
  3007. // TODO: figure out values for client, fromSession, and imSessionID
  3008. // client.SendInstantMessage(m_host.UUID, fromSession, message, user, imSessionID, m_host.Name, AgentManager.InstantMessageDialog.MessageFromAgent, (uint)Util.UnixTimeSinceEpoch());
  3009. UUID friendTransactionID = UUID.Random();
  3010. //m_pendingFriendRequests.Add(friendTransactionID, fromAgentID);
  3011. GridInstantMessage msg = new GridInstantMessage();
  3012. msg.fromAgentID = new Guid(m_host.UUID.ToString()); // fromAgentID.Guid;
  3013. msg.toAgentID = new Guid(user); // toAgentID.Guid;
  3014. msg.imSessionID = new Guid(friendTransactionID.ToString()); // This is the item we're mucking with here
  3015. // m_log.Debug("[Scripting IM]: From:" + msg.fromAgentID.ToString() + " To: " + msg.toAgentID.ToString() + " Session:" + msg.imSessionID.ToString() + " Message:" + message);
  3016. // m_log.Debug("[Scripting IM]: Filling Session: " + msg.imSessionID.ToString());
  3017. msg.timestamp = (uint)Util.UnixTimeSinceEpoch();// timestamp;
  3018. //if (client != null)
  3019. //{
  3020. msg.fromAgentName = m_host.Name;//client.FirstName + " " + client.LastName;// fromAgentName;
  3021. //}
  3022. //else
  3023. //{
  3024. // msg.fromAgentName = "(hippos)";// Added for posterity. This means that we can't figure out who sent it
  3025. //}
  3026. // Cap the message length at 1024.
  3027. if (message != null && message.Length > 1024)
  3028. msg.message = message.Substring(0, 1024);
  3029. else
  3030. msg.message = message;
  3031. msg.dialog = (byte)19; // messgage from script ??? // dialog;
  3032. msg.fromGroup = false;// fromGroup;
  3033. msg.offline = (byte)0; //offline;
  3034. msg.ParentEstateID = 0; //ParentEstateID;
  3035. msg.Position = new Vector3(m_host.AbsolutePosition);
  3036. msg.RegionID = World.RegionInfo.RegionID.Guid;//RegionID.Guid;
  3037. Vector3 pos = m_host.AbsolutePosition;
  3038. msg.binaryBucket
  3039. = Util.StringToBytes256(
  3040. "{0}/{1}/{2}/{3}",
  3041. World.RegionInfo.RegionName,
  3042. (int)Math.Floor(pos.X),
  3043. (int)Math.Floor(pos.Y),
  3044. (int)Math.Floor(pos.Z));
  3045. if (m_TransferModule != null)
  3046. {
  3047. m_TransferModule.SendInstantMessage(msg, delegate(bool success) {});
  3048. }
  3049. ScriptSleep(m_sleepMsOnInstantMessage);
  3050. }
  3051. public void llEmail(string address, string subject, string message)
  3052. {
  3053. m_host.AddScriptLPS(1);
  3054. IEmailModule emailModule = m_ScriptEngine.World.RequestModuleInterface<IEmailModule>();
  3055. if (emailModule == null)
  3056. {
  3057. Error("llEmail", "Email module not configured");
  3058. return;
  3059. }
  3060. //Restrict email destination to the avatars registered email address?
  3061. //The restriction only applies if the destination address is not local.
  3062. if (m_restrictEmail == true && address.Contains(m_internalObjectHost) == false)
  3063. {
  3064. UserAccount account =
  3065. World.UserAccountService.GetUserAccount(
  3066. World.RegionInfo.ScopeID,
  3067. m_host.OwnerID);
  3068. if (account == null)
  3069. {
  3070. Error("llEmail", "Can't find user account for '" + m_host.OwnerID.ToString() + "'");
  3071. return;
  3072. }
  3073. if (String.IsNullOrEmpty(account.Email))
  3074. {
  3075. Error("llEmail", "User account has not registered an email address.");
  3076. return;
  3077. }
  3078. address = account.Email;
  3079. }
  3080. emailModule.SendEmail(m_host.UUID, address, subject, message);
  3081. ScriptSleep(m_sleepMsOnEmail);
  3082. }
  3083. public void llGetNextEmail(string address, string subject)
  3084. {
  3085. m_host.AddScriptLPS(1);
  3086. IEmailModule emailModule = m_ScriptEngine.World.RequestModuleInterface<IEmailModule>();
  3087. if (emailModule == null)
  3088. {
  3089. Error("llGetNextEmail", "Email module not configured");
  3090. return;
  3091. }
  3092. Email email;
  3093. email = emailModule.GetNextEmail(m_host.UUID, address, subject);
  3094. if (email == null)
  3095. return;
  3096. m_ScriptEngine.PostObjectEvent(m_host.LocalId,
  3097. new EventParams("email",
  3098. new Object[] {
  3099. new LSL_String(email.time),
  3100. new LSL_String(email.sender),
  3101. new LSL_String(email.subject),
  3102. new LSL_String(email.message),
  3103. new LSL_Integer(email.numLeft)},
  3104. new DetectParams[0]));
  3105. }
  3106. public LSL_String llGetKey()
  3107. {
  3108. m_host.AddScriptLPS(1);
  3109. return m_host.UUID.ToString();
  3110. }
  3111. public LSL_Key llGenerateKey()
  3112. {
  3113. m_host.AddScriptLPS(1);
  3114. return UUID.Random().ToString();
  3115. }
  3116. public void llSetBuoyancy(double buoyancy)
  3117. {
  3118. m_host.AddScriptLPS(1);
  3119. if (!m_host.ParentGroup.IsDeleted)
  3120. {
  3121. m_host.ParentGroup.RootPart.SetBuoyancy((float)buoyancy);
  3122. }
  3123. }
  3124. /// <summary>
  3125. /// Attempt to clamp the object on the Z axis at the given height over tau seconds.
  3126. /// </summary>
  3127. /// <param name="height">Height to hover. Height of zero disables hover.</param>
  3128. /// <param name="water">False if height is calculated just from ground, otherwise uses ground or water depending on whichever is higher</param>
  3129. /// <param name="tau">Number of seconds over which to reach target</param>
  3130. public void llSetHoverHeight(double height, int water, double tau)
  3131. {
  3132. m_host.AddScriptLPS(1);
  3133. if (m_host.PhysActor != null)
  3134. {
  3135. PIDHoverType hoverType = PIDHoverType.Ground;
  3136. if (water != 0)
  3137. {
  3138. hoverType = PIDHoverType.GroundAndWater;
  3139. }
  3140. m_host.SetHoverHeight((float)height, hoverType, (float)tau);
  3141. }
  3142. }
  3143. public void llStopHover()
  3144. {
  3145. m_host.AddScriptLPS(1);
  3146. if (m_host.PhysActor != null)
  3147. {
  3148. m_host.SetHoverHeight(0f, PIDHoverType.Ground, 0f);
  3149. }
  3150. }
  3151. public void llMinEventDelay(double delay)
  3152. {
  3153. m_host.AddScriptLPS(1);
  3154. try
  3155. {
  3156. m_ScriptEngine.SetMinEventDelay(m_item.ItemID, delay);
  3157. }
  3158. catch (NotImplementedException)
  3159. {
  3160. // Currently not implemented in DotNetEngine only XEngine
  3161. NotImplemented("llMinEventDelay", "In DotNetEngine");
  3162. }
  3163. }
  3164. public void llSoundPreload(string sound)
  3165. {
  3166. m_host.AddScriptLPS(1);
  3167. Deprecated("llSoundPreload", "Use llPreloadSound instead");
  3168. }
  3169. public void llRotLookAt(LSL_Rotation target, double strength, double damping)
  3170. {
  3171. m_host.AddScriptLPS(1);
  3172. // Per discussion with Melanie, for non-physical objects llLookAt appears to simply
  3173. // set the rotation of the object, copy that behavior
  3174. PhysicsActor pa = m_host.PhysActor;
  3175. if (strength == 0 || pa == null || !pa.IsPhysical)
  3176. {
  3177. llSetLocalRot(target);
  3178. }
  3179. else
  3180. {
  3181. m_host.RotLookAt(target, (float)strength, (float)damping);
  3182. }
  3183. }
  3184. public LSL_Integer llStringLength(string str)
  3185. {
  3186. m_host.AddScriptLPS(1);
  3187. if (str.Length > 0)
  3188. {
  3189. return str.Length;
  3190. }
  3191. else
  3192. {
  3193. return 0;
  3194. }
  3195. }
  3196. public void llStartAnimation(string anim)
  3197. {
  3198. m_host.AddScriptLPS(1);
  3199. if (m_item.PermsGranter == UUID.Zero)
  3200. return;
  3201. if ((m_item.PermsMask & ScriptBaseClass.PERMISSION_TRIGGER_ANIMATION) != 0)
  3202. {
  3203. ScenePresence presence = World.GetScenePresence(m_item.PermsGranter);
  3204. if (presence != null)
  3205. {
  3206. // Do NOT try to parse UUID, animations cannot be triggered by ID
  3207. UUID animID = ScriptUtils.GetAssetIdFromItemName(m_host, anim, (int)AssetType.Animation);
  3208. if (animID == UUID.Zero)
  3209. presence.Animator.AddAnimation(anim, m_host.UUID);
  3210. else
  3211. presence.Animator.AddAnimation(animID, m_host.UUID);
  3212. }
  3213. }
  3214. }
  3215. public void llStopAnimation(string anim)
  3216. {
  3217. m_host.AddScriptLPS(1);
  3218. if (m_item.PermsGranter == UUID.Zero)
  3219. return;
  3220. if ((m_item.PermsMask & ScriptBaseClass.PERMISSION_TRIGGER_ANIMATION) != 0)
  3221. {
  3222. ScenePresence presence = World.GetScenePresence(m_item.PermsGranter);
  3223. if (presence != null)
  3224. {
  3225. UUID animID = ScriptUtils.GetAssetIdFromKeyOrItemName(m_host, anim);
  3226. if (animID == UUID.Zero)
  3227. presence.Animator.RemoveAnimation(anim);
  3228. else
  3229. presence.Animator.RemoveAnimation(animID, true);
  3230. }
  3231. }
  3232. }
  3233. public void llPointAt(LSL_Vector pos)
  3234. {
  3235. m_host.AddScriptLPS(1);
  3236. }
  3237. public void llStopPointAt()
  3238. {
  3239. m_host.AddScriptLPS(1);
  3240. }
  3241. public void llTargetOmega(LSL_Vector axis, double spinrate, double gain)
  3242. {
  3243. m_host.AddScriptLPS(1);
  3244. TargetOmega(m_host, axis, spinrate, gain);
  3245. }
  3246. protected void TargetOmega(SceneObjectPart part, LSL_Vector axis, double spinrate, double gain)
  3247. {
  3248. PhysicsActor pa = part.PhysActor;
  3249. if ( ( pa == null || !pa.IsPhysical ) && gain == 0.0d )
  3250. spinrate = 0.0d;
  3251. part.UpdateAngularVelocity(axis * spinrate);
  3252. }
  3253. public LSL_Integer llGetStartParameter()
  3254. {
  3255. m_host.AddScriptLPS(1);
  3256. return m_ScriptEngine.GetStartParameter(m_item.ItemID);
  3257. }
  3258. public void llRequestPermissions(string agent, int perm)
  3259. {
  3260. UUID agentID;
  3261. if (!UUID.TryParse(agent, out agentID))
  3262. return;
  3263. if (agentID == UUID.Zero || perm == 0) // Releasing permissions
  3264. {
  3265. llReleaseControls();
  3266. m_item.PermsGranter = UUID.Zero;
  3267. m_item.PermsMask = 0;
  3268. m_ScriptEngine.PostScriptEvent(m_item.ItemID, new EventParams(
  3269. "run_time_permissions", new Object[] {
  3270. new LSL_Integer(0) },
  3271. new DetectParams[0]));
  3272. return;
  3273. }
  3274. if (m_item.PermsGranter != agentID || (perm & ScriptBaseClass.PERMISSION_TAKE_CONTROLS) == 0)
  3275. llReleaseControls();
  3276. m_host.AddScriptLPS(1);
  3277. int implicitPerms = 0;
  3278. if (m_host.ParentGroup.IsAttachment && (UUID)agent == m_host.ParentGroup.AttachedAvatar)
  3279. {
  3280. // When attached, certain permissions are implicit if requested from owner
  3281. implicitPerms = ScriptBaseClass.PERMISSION_TAKE_CONTROLS |
  3282. ScriptBaseClass.PERMISSION_TRIGGER_ANIMATION |
  3283. ScriptBaseClass.PERMISSION_CONTROL_CAMERA |
  3284. ScriptBaseClass.PERMISSION_TRACK_CAMERA |
  3285. ScriptBaseClass.PERMISSION_ATTACH;
  3286. }
  3287. else
  3288. {
  3289. if (m_host.ParentGroup.GetSittingAvatars().SingleOrDefault(sp => sp.UUID == agentID) != null)
  3290. {
  3291. // When agent is sitting, certain permissions are implicit if requested from sitting agent
  3292. implicitPerms = ScriptBaseClass.PERMISSION_TRIGGER_ANIMATION |
  3293. ScriptBaseClass.PERMISSION_CONTROL_CAMERA |
  3294. ScriptBaseClass.PERMISSION_TRACK_CAMERA |
  3295. ScriptBaseClass.PERMISSION_TAKE_CONTROLS;
  3296. }
  3297. else
  3298. {
  3299. if (World.GetExtraSetting("auto_grant_attach_perms") == "true")
  3300. implicitPerms = ScriptBaseClass.PERMISSION_ATTACH;
  3301. }
  3302. }
  3303. if ((perm & (~implicitPerms)) == 0) // Requested only implicit perms
  3304. {
  3305. lock (m_host.TaskInventory)
  3306. {
  3307. m_host.TaskInventory[m_item.ItemID].PermsGranter = agentID;
  3308. m_host.TaskInventory[m_item.ItemID].PermsMask = perm;
  3309. }
  3310. m_ScriptEngine.PostScriptEvent(m_item.ItemID, new EventParams(
  3311. "run_time_permissions", new Object[] {
  3312. new LSL_Integer(perm) },
  3313. new DetectParams[0]));
  3314. return;
  3315. }
  3316. ScenePresence presence = World.GetScenePresence(agentID);
  3317. if (presence != null)
  3318. {
  3319. // If permissions are being requested from an NPC and were not implicitly granted above then
  3320. // auto grant all requested permissions if the script is owned by the NPC or the NPCs owner
  3321. INPCModule npcModule = World.RequestModuleInterface<INPCModule>();
  3322. if (npcModule != null && npcModule.IsNPC(agentID, World))
  3323. {
  3324. if (npcModule.CheckPermissions(agentID, m_host.OwnerID))
  3325. {
  3326. lock (m_host.TaskInventory)
  3327. {
  3328. m_host.TaskInventory[m_item.ItemID].PermsGranter = agentID;
  3329. m_host.TaskInventory[m_item.ItemID].PermsMask = perm;
  3330. }
  3331. m_ScriptEngine.PostScriptEvent(
  3332. m_item.ItemID,
  3333. new EventParams(
  3334. "run_time_permissions", new Object[] { new LSL_Integer(perm) }, new DetectParams[0]));
  3335. }
  3336. // it is an NPC, exit even if the permissions werent granted above, they are not going to answer
  3337. // the question!
  3338. return;
  3339. }
  3340. string ownerName = resolveName(m_host.ParentGroup.RootPart.OwnerID);
  3341. if (ownerName == String.Empty)
  3342. ownerName = "(hippos)";
  3343. if (!m_waitingForScriptAnswer)
  3344. {
  3345. lock (m_host.TaskInventory)
  3346. {
  3347. m_host.TaskInventory[m_item.ItemID].PermsGranter = agentID;
  3348. m_host.TaskInventory[m_item.ItemID].PermsMask = 0;
  3349. }
  3350. presence.ControllingClient.OnScriptAnswer += handleScriptAnswer;
  3351. m_waitingForScriptAnswer=true;
  3352. }
  3353. presence.ControllingClient.SendScriptQuestion(
  3354. m_host.UUID, m_host.ParentGroup.RootPart.Name, ownerName, m_item.ItemID, perm);
  3355. return;
  3356. }
  3357. // Requested agent is not in range, refuse perms
  3358. m_ScriptEngine.PostScriptEvent(
  3359. m_item.ItemID,
  3360. new EventParams("run_time_permissions", new Object[] { new LSL_Integer(0) }, new DetectParams[0]));
  3361. }
  3362. void handleScriptAnswer(IClientAPI client, UUID taskID, UUID itemID, int answer)
  3363. {
  3364. if (taskID != m_host.UUID)
  3365. return;
  3366. client.OnScriptAnswer -= handleScriptAnswer;
  3367. m_waitingForScriptAnswer = false;
  3368. if ((answer & ScriptBaseClass.PERMISSION_TAKE_CONTROLS) == 0)
  3369. llReleaseControls();
  3370. lock (m_host.TaskInventory)
  3371. {
  3372. m_host.TaskInventory[m_item.ItemID].PermsMask = answer;
  3373. }
  3374. m_ScriptEngine.PostScriptEvent(
  3375. m_item.ItemID,
  3376. new EventParams("run_time_permissions", new Object[] { new LSL_Integer(answer) }, new DetectParams[0]));
  3377. }
  3378. public LSL_String llGetPermissionsKey()
  3379. {
  3380. m_host.AddScriptLPS(1);
  3381. return m_item.PermsGranter.ToString();
  3382. }
  3383. public LSL_Integer llGetPermissions()
  3384. {
  3385. m_host.AddScriptLPS(1);
  3386. int perms = m_item.PermsMask;
  3387. if (m_automaticLinkPermission)
  3388. perms |= ScriptBaseClass.PERMISSION_CHANGE_LINKS;
  3389. return perms;
  3390. }
  3391. public LSL_Integer llGetLinkNumber()
  3392. {
  3393. m_host.AddScriptLPS(1);
  3394. if (m_host.ParentGroup.PrimCount > 1)
  3395. {
  3396. return m_host.LinkNum;
  3397. }
  3398. else
  3399. {
  3400. return 0;
  3401. }
  3402. }
  3403. public void llSetLinkColor(int linknumber, LSL_Vector color, int face)
  3404. {
  3405. List<SceneObjectPart> parts = GetLinkParts(linknumber);
  3406. foreach (SceneObjectPart part in parts)
  3407. part.SetFaceColorAlpha(face, color, null);
  3408. }
  3409. public void llCreateLink(string target, int parent)
  3410. {
  3411. m_host.AddScriptLPS(1);
  3412. if ((m_item.PermsMask & ScriptBaseClass.PERMISSION_CHANGE_LINKS) == 0
  3413. && !m_automaticLinkPermission)
  3414. {
  3415. Error("llCreateLink", "PERMISSION_CHANGE_LINKS permission not set");
  3416. return;
  3417. }
  3418. CreateLink(target, parent);
  3419. }
  3420. public void CreateLink(string target, int parent)
  3421. {
  3422. UUID targetID;
  3423. if (!UUID.TryParse(target, out targetID))
  3424. return;
  3425. SceneObjectPart targetPart = World.GetSceneObjectPart((UUID)targetID);
  3426. if (targetPart.ParentGroup.AttachmentPoint != 0)
  3427. return; // Fail silently if attached
  3428. if (targetPart.ParentGroup.RootPart.OwnerID != m_host.ParentGroup.RootPart.OwnerID)
  3429. return;
  3430. SceneObjectGroup parentPrim = null, childPrim = null;
  3431. if (targetPart != null)
  3432. {
  3433. if (parent != 0)
  3434. {
  3435. parentPrim = m_host.ParentGroup;
  3436. childPrim = targetPart.ParentGroup;
  3437. }
  3438. else
  3439. {
  3440. parentPrim = targetPart.ParentGroup;
  3441. childPrim = m_host.ParentGroup;
  3442. }
  3443. // Required for linking
  3444. childPrim.RootPart.ClearUpdateSchedule();
  3445. parentPrim.LinkToGroup(childPrim, true);
  3446. }
  3447. parentPrim.TriggerScriptChangedEvent(Changed.LINK);
  3448. parentPrim.RootPart.CreateSelected = true;
  3449. parentPrim.HasGroupChanged = true;
  3450. parentPrim.ScheduleGroupForFullUpdate();
  3451. IClientAPI client = null;
  3452. ScenePresence sp = World.GetScenePresence(m_host.OwnerID);
  3453. if (sp != null)
  3454. client = sp.ControllingClient;
  3455. if (client != null)
  3456. parentPrim.SendPropertiesToClient(client);
  3457. ScriptSleep(m_sleepMsOnCreateLink);
  3458. }
  3459. public void llBreakLink(int linknum)
  3460. {
  3461. m_host.AddScriptLPS(1);
  3462. if ((m_item.PermsMask & ScriptBaseClass.PERMISSION_CHANGE_LINKS) == 0
  3463. && !m_automaticLinkPermission)
  3464. {
  3465. Error("llBreakLink", "PERMISSION_CHANGE_LINKS permission not set");
  3466. return;
  3467. }
  3468. BreakLink(linknum);
  3469. }
  3470. public void BreakLink(int linknum)
  3471. {
  3472. if (linknum < ScriptBaseClass.LINK_THIS)
  3473. return;
  3474. SceneObjectGroup parentPrim = m_host.ParentGroup;
  3475. if (parentPrim.AttachmentPoint != 0)
  3476. return; // Fail silently if attached
  3477. SceneObjectPart childPrim = null;
  3478. switch (linknum)
  3479. {
  3480. case ScriptBaseClass.LINK_ROOT:
  3481. break;
  3482. case ScriptBaseClass.LINK_SET:
  3483. case ScriptBaseClass.LINK_ALL_OTHERS:
  3484. case ScriptBaseClass.LINK_ALL_CHILDREN:
  3485. case ScriptBaseClass.LINK_THIS:
  3486. foreach (SceneObjectPart part in parentPrim.Parts)
  3487. {
  3488. if (part.UUID != m_host.UUID)
  3489. {
  3490. childPrim = part;
  3491. break;
  3492. }
  3493. }
  3494. break;
  3495. default:
  3496. childPrim = parentPrim.GetLinkNumPart(linknum);
  3497. if (childPrim.UUID == m_host.UUID)
  3498. childPrim = null;
  3499. break;
  3500. }
  3501. if (linknum == ScriptBaseClass.LINK_ROOT)
  3502. {
  3503. // Restructuring Multiple Prims.
  3504. List<SceneObjectPart> parts = new List<SceneObjectPart>(parentPrim.Parts);
  3505. parts.Remove(parentPrim.RootPart);
  3506. foreach (SceneObjectPart part in parts)
  3507. {
  3508. parentPrim.DelinkFromGroup(part.LocalId, true);
  3509. }
  3510. parentPrim.HasGroupChanged = true;
  3511. parentPrim.ScheduleGroupForFullUpdate();
  3512. parentPrim.TriggerScriptChangedEvent(Changed.LINK);
  3513. if (parts.Count > 0)
  3514. {
  3515. SceneObjectPart newRoot = parts[0];
  3516. parts.Remove(newRoot);
  3517. foreach (SceneObjectPart part in parts)
  3518. {
  3519. // Required for linking
  3520. part.ClearUpdateSchedule();
  3521. newRoot.ParentGroup.LinkToGroup(part.ParentGroup);
  3522. }
  3523. newRoot.ParentGroup.HasGroupChanged = true;
  3524. newRoot.ParentGroup.ScheduleGroupForFullUpdate();
  3525. }
  3526. }
  3527. else
  3528. {
  3529. if (childPrim == null)
  3530. return;
  3531. parentPrim.DelinkFromGroup(childPrim.LocalId, true);
  3532. parentPrim.HasGroupChanged = true;
  3533. parentPrim.ScheduleGroupForFullUpdate();
  3534. parentPrim.TriggerScriptChangedEvent(Changed.LINK);
  3535. }
  3536. }
  3537. public void llBreakAllLinks()
  3538. {
  3539. m_host.AddScriptLPS(1);
  3540. if ((m_item.PermsMask & ScriptBaseClass.PERMISSION_CHANGE_LINKS) == 0
  3541. && !m_automaticLinkPermission)
  3542. {
  3543. Error("llBreakAllLinks", "PERMISSION_CHANGE_LINKS permission not set");
  3544. return;
  3545. }
  3546. BreakAllLinks();
  3547. }
  3548. public void BreakAllLinks()
  3549. {
  3550. SceneObjectGroup parentPrim = m_host.ParentGroup;
  3551. if (parentPrim.AttachmentPoint != 0)
  3552. return; // Fail silently if attached
  3553. List<SceneObjectPart> parts = new List<SceneObjectPart>(parentPrim.Parts);
  3554. parts.Remove(parentPrim.RootPart);
  3555. foreach (SceneObjectPart part in parts)
  3556. {
  3557. parentPrim.DelinkFromGroup(part.LocalId, true);
  3558. parentPrim.TriggerScriptChangedEvent(Changed.LINK);
  3559. }
  3560. parentPrim.HasGroupChanged = true;
  3561. parentPrim.ScheduleGroupForFullUpdate();
  3562. }
  3563. public LSL_String llGetLinkKey(int linknum)
  3564. {
  3565. m_host.AddScriptLPS(1);
  3566. ISceneEntity entity = GetLinkEntity(m_host, linknum);
  3567. if (entity != null)
  3568. return entity.UUID.ToString();
  3569. else
  3570. return ScriptBaseClass.NULL_KEY;
  3571. }
  3572. /// <summary>
  3573. /// Returns the name of the child prim or seated avatar matching the
  3574. /// specified link number.
  3575. /// </summary>
  3576. /// <param name="linknum">
  3577. /// The number of a link in the linkset or a link-related constant.
  3578. /// </param>
  3579. /// <returns>
  3580. /// The name determined to match the specified link number.
  3581. /// </returns>
  3582. /// <remarks>
  3583. /// The rules governing the returned name are not simple. The only
  3584. /// time a blank name is returned is if the target prim has a blank
  3585. /// name. If no prim with the given link number can be found then
  3586. /// usually NULL_KEY is returned but there are exceptions.
  3587. ///
  3588. /// In a single unlinked prim, A call with 0 returns the name, all
  3589. /// other values for link number return NULL_KEY
  3590. ///
  3591. /// In link sets it is more complicated.
  3592. ///
  3593. /// If the script is in the root prim:-
  3594. /// A zero link number returns NULL_KEY.
  3595. /// Positive link numbers return the name of the prim, or NULL_KEY
  3596. /// if a prim does not exist at that position.
  3597. /// Negative link numbers return the name of the first child prim.
  3598. ///
  3599. /// If the script is in a child prim:-
  3600. /// Link numbers 0 or 1 return the name of the root prim.
  3601. /// Positive link numbers return the name of the prim or NULL_KEY
  3602. /// if a prim does not exist at that position.
  3603. /// Negative numbers return the name of the root prim.
  3604. ///
  3605. /// References
  3606. /// http://lslwiki.net/lslwiki/wakka.php?wakka=llGetLinkName
  3607. /// Mentions NULL_KEY being returned
  3608. /// http://wiki.secondlife.com/wiki/LlGetLinkName
  3609. /// Mentions using the LINK_* constants, some of which are negative
  3610. /// </remarks>
  3611. public LSL_String llGetLinkName(int linknum)
  3612. {
  3613. m_host.AddScriptLPS(1);
  3614. ISceneEntity entity = GetLinkEntity(m_host, linknum);
  3615. if (entity != null)
  3616. return entity.Name;
  3617. else
  3618. return ScriptBaseClass.NULL_KEY;
  3619. }
  3620. public LSL_Integer llGetInventoryNumber(int type)
  3621. {
  3622. m_host.AddScriptLPS(1);
  3623. int count = 0;
  3624. lock (m_host.TaskInventory)
  3625. {
  3626. foreach (KeyValuePair<UUID, TaskInventoryItem> inv in m_host.TaskInventory)
  3627. {
  3628. if (inv.Value.Type == type || type == -1)
  3629. {
  3630. count = count + 1;
  3631. }
  3632. }
  3633. }
  3634. return count;
  3635. }
  3636. public LSL_String llGetInventoryName(int type, int number)
  3637. {
  3638. m_host.AddScriptLPS(1);
  3639. ArrayList keys = new ArrayList();
  3640. lock (m_host.TaskInventory)
  3641. {
  3642. foreach (KeyValuePair<UUID, TaskInventoryItem> inv in m_host.TaskInventory)
  3643. {
  3644. if (inv.Value.Type == type || type == -1)
  3645. {
  3646. keys.Add(inv.Value.Name);
  3647. }
  3648. }
  3649. }
  3650. if (keys.Count == 0)
  3651. {
  3652. return String.Empty;
  3653. }
  3654. keys.Sort();
  3655. if (keys.Count > number)
  3656. {
  3657. return (string)keys[number];
  3658. }
  3659. return String.Empty;
  3660. }
  3661. public LSL_Float llGetEnergy()
  3662. {
  3663. m_host.AddScriptLPS(1);
  3664. // TODO: figure out real energy value
  3665. return 1.0f;
  3666. }
  3667. public void llGiveInventory(string destination, string inventory)
  3668. {
  3669. m_host.AddScriptLPS(1);
  3670. UUID destId = UUID.Zero;
  3671. if (!UUID.TryParse(destination, out destId))
  3672. {
  3673. Error("llGiveInventory", "Can't parse destination key '" + destination + "'");
  3674. return;
  3675. }
  3676. TaskInventoryItem item = m_host.Inventory.GetInventoryItem(inventory);
  3677. if (item == null)
  3678. {
  3679. Error("llGiveInventory", "Can't find inventory object '" + inventory + "'");
  3680. return;
  3681. }
  3682. UUID objId = item.ItemID;
  3683. // check if destination is an object
  3684. if (World.GetSceneObjectPart(destId) != null)
  3685. {
  3686. // destination is an object
  3687. World.MoveTaskInventoryItem(destId, m_host, objId);
  3688. }
  3689. else
  3690. {
  3691. ScenePresence presence = World.GetScenePresence(destId);
  3692. if (presence == null)
  3693. {
  3694. UserAccount account =
  3695. World.UserAccountService.GetUserAccount(
  3696. World.RegionInfo.ScopeID,
  3697. destId);
  3698. if (account == null)
  3699. {
  3700. GridUserInfo info = World.GridUserService.GetGridUserInfo(destId.ToString());
  3701. if(info == null || info.Online == false)
  3702. {
  3703. Error("llGiveInventory", "Can't find destination '" + destId.ToString() + "'");
  3704. return;
  3705. }
  3706. }
  3707. }
  3708. // destination is an avatar
  3709. string message;
  3710. InventoryItemBase agentItem = World.MoveTaskInventoryItem(destId, UUID.Zero, m_host, objId, out message);
  3711. if (agentItem == null)
  3712. {
  3713. llSay(0, message);
  3714. return;
  3715. }
  3716. if (m_TransferModule != null)
  3717. {
  3718. byte[] bucket = new byte[1];
  3719. bucket[0] = (byte)item.Type;
  3720. GridInstantMessage msg = new GridInstantMessage(World,
  3721. m_host.OwnerID, m_host.Name, destId,
  3722. (byte)InstantMessageDialog.TaskInventoryOffered,
  3723. false, item.Name+". "+m_host.Name+" is located at "+
  3724. World.RegionInfo.RegionName+" "+
  3725. m_host.AbsolutePosition.ToString(),
  3726. agentItem.ID, true, m_host.AbsolutePosition,
  3727. bucket, true);
  3728. m_TransferModule.SendInstantMessage(msg, delegate(bool success) {});
  3729. }
  3730. ScriptSleep(m_sleepMsOnGiveInventory);
  3731. }
  3732. }
  3733. public void llRemoveInventory(string name)
  3734. {
  3735. m_host.AddScriptLPS(1);
  3736. TaskInventoryItem item = m_host.Inventory.GetInventoryItem(name);
  3737. if (item == null)
  3738. return;
  3739. if (item.ItemID == m_item.ItemID)
  3740. throw new ScriptDeleteException();
  3741. else
  3742. m_host.Inventory.RemoveInventoryItem(item.ItemID);
  3743. }
  3744. public void llSetText(string text, LSL_Vector color, double alpha)
  3745. {
  3746. m_host.AddScriptLPS(1);
  3747. Vector3 av3 = Util.Clip(color, 0.0f, 1.0f);
  3748. if (text.Length > 254)
  3749. text = text.Remove(254);
  3750. byte[] data;
  3751. do
  3752. {
  3753. data = Util.UTF8.GetBytes(text);
  3754. if (data.Length > 254)
  3755. text = text.Substring(0, text.Length - 1);
  3756. } while (data.Length > 254);
  3757. m_host.SetText(text, av3, Util.Clip((float)alpha, 0.0f, 1.0f));
  3758. //m_host.ParentGroup.HasGroupChanged = true;
  3759. //m_host.ParentGroup.ScheduleGroupForFullUpdate();
  3760. }
  3761. public LSL_Float llWater(LSL_Vector offset)
  3762. {
  3763. m_host.AddScriptLPS(1);
  3764. return World.RegionInfo.RegionSettings.WaterHeight;
  3765. }
  3766. public void llPassTouches(int pass)
  3767. {
  3768. m_host.AddScriptLPS(1);
  3769. if (pass != 0)
  3770. m_host.PassTouches = true;
  3771. else
  3772. m_host.PassTouches = false;
  3773. }
  3774. public LSL_String llRequestAgentData(string id, int data)
  3775. {
  3776. m_host.AddScriptLPS(1);
  3777. UUID uuid = (UUID)id;
  3778. PresenceInfo pinfo = null;
  3779. UserAccount account;
  3780. UserInfoCacheEntry ce;
  3781. lock (m_userInfoCache)
  3782. {
  3783. if (!m_userInfoCache.TryGetValue(uuid, out ce))
  3784. {
  3785. account = World.UserAccountService.GetUserAccount(World.RegionInfo.ScopeID, uuid);
  3786. if (account == null)
  3787. {
  3788. m_userInfoCache[uuid] = null; // Cache negative
  3789. return UUID.Zero.ToString();
  3790. }
  3791. PresenceInfo[] pinfos = World.PresenceService.GetAgents(new string[] { uuid.ToString() });
  3792. if (pinfos != null && pinfos.Length > 0)
  3793. {
  3794. foreach (PresenceInfo p in pinfos)
  3795. {
  3796. if (p.RegionID != UUID.Zero)
  3797. {
  3798. pinfo = p;
  3799. }
  3800. }
  3801. }
  3802. ce = new UserInfoCacheEntry();
  3803. ce.time = Util.EnvironmentTickCount();
  3804. ce.account = account;
  3805. ce.pinfo = pinfo;
  3806. m_userInfoCache[uuid] = ce;
  3807. }
  3808. else
  3809. {
  3810. if (ce == null)
  3811. return UUID.Zero.ToString();
  3812. account = ce.account;
  3813. if (Util.EnvironmentTickCount() < ce.time || (Util.EnvironmentTickCount() - ce.time)
  3814. >= LlRequestAgentDataCacheTimeoutMs)
  3815. {
  3816. PresenceInfo[] pinfos = World.PresenceService.GetAgents(new string[] { uuid.ToString() });
  3817. if (pinfos != null && pinfos.Length > 0)
  3818. {
  3819. foreach (PresenceInfo p in pinfos)
  3820. {
  3821. if (p.RegionID != UUID.Zero)
  3822. {
  3823. pinfo = p;
  3824. }
  3825. }
  3826. }
  3827. else
  3828. {
  3829. pinfo = null;
  3830. }
  3831. ce.time = Util.EnvironmentTickCount();
  3832. ce.pinfo = pinfo;
  3833. }
  3834. else
  3835. {
  3836. pinfo = ce.pinfo;
  3837. }
  3838. }
  3839. }
  3840. string reply = String.Empty;
  3841. switch (data)
  3842. {
  3843. case ScriptBaseClass.DATA_ONLINE:
  3844. if (pinfo != null && pinfo.RegionID != UUID.Zero)
  3845. reply = "1";
  3846. else
  3847. reply = "0";
  3848. break;
  3849. case ScriptBaseClass.DATA_NAME: // (First Last)
  3850. reply = account.FirstName + " " + account.LastName;
  3851. break;
  3852. case ScriptBaseClass.DATA_BORN: // (YYYY-MM-DD)
  3853. DateTime born = new DateTime(1970, 1, 1, 0, 0, 0, 0);
  3854. born = born.AddSeconds(account.Created);
  3855. reply = born.ToString("yyyy-MM-dd");
  3856. break;
  3857. case ScriptBaseClass.DATA_RATING: // (0,0,0,0,0,0)
  3858. reply = "0,0,0,0,0,0";
  3859. break;
  3860. case 7: // DATA_USERLEVEL (integer). This is not available in LL and so has no constant.
  3861. reply = account.UserLevel.ToString();
  3862. break;
  3863. case ScriptBaseClass.DATA_PAYINFO: // (0|1|2|3)
  3864. reply = "0";
  3865. break;
  3866. default:
  3867. return UUID.Zero.ToString(); // Raise no event
  3868. }
  3869. UUID rq = UUID.Random();
  3870. UUID tid = AsyncCommands.
  3871. DataserverPlugin.RegisterRequest(m_host.LocalId,
  3872. m_item.ItemID, rq.ToString());
  3873. AsyncCommands.
  3874. DataserverPlugin.DataserverReply(rq.ToString(), reply);
  3875. ScriptSleep(m_sleepMsOnRequestAgentData);
  3876. return tid.ToString();
  3877. }
  3878. public LSL_String llRequestInventoryData(string name)
  3879. {
  3880. m_host.AddScriptLPS(1);
  3881. foreach (TaskInventoryItem item in m_host.Inventory.GetInventoryItems())
  3882. {
  3883. if (item.Type == 3 && item.Name == name)
  3884. {
  3885. UUID tid = AsyncCommands.
  3886. DataserverPlugin.RegisterRequest(m_host.LocalId,
  3887. m_item.ItemID, item.AssetID.ToString());
  3888. Vector3 region = new Vector3(World.RegionInfo.WorldLocX, World.RegionInfo.WorldLocY, 0);
  3889. World.AssetService.Get(item.AssetID.ToString(), this,
  3890. delegate(string i, object sender, AssetBase a)
  3891. {
  3892. AssetLandmark lm = new AssetLandmark(a);
  3893. float rx = (uint)(lm.RegionHandle >> 32);
  3894. float ry = (uint)lm.RegionHandle;
  3895. region = lm.Position + new Vector3(rx, ry, 0) - region;
  3896. string reply = region.ToString();
  3897. AsyncCommands.
  3898. DataserverPlugin.DataserverReply(i.ToString(),
  3899. reply);
  3900. });
  3901. ScriptSleep(m_sleepMsOnRequestInventoryData);
  3902. return tid.ToString();
  3903. }
  3904. }
  3905. ScriptSleep(m_sleepMsOnRequestInventoryData);
  3906. return String.Empty;
  3907. }
  3908. public void llSetDamage(double damage)
  3909. {
  3910. m_host.AddScriptLPS(1);
  3911. m_host.ParentGroup.Damage = (float)damage;
  3912. }
  3913. public void llTeleportAgentHome(string agent)
  3914. {
  3915. m_host.AddScriptLPS(1);
  3916. UUID agentId = new UUID();
  3917. if (UUID.TryParse(agent, out agentId))
  3918. {
  3919. ScenePresence presence = World.GetScenePresence(agentId);
  3920. if (presence != null)
  3921. {
  3922. // agent must be over the owners land
  3923. if (m_host.OwnerID == World.LandChannel.GetLandObject(presence.AbsolutePosition).LandData.OwnerID)
  3924. {
  3925. World.TeleportClientHome(agentId, presence.ControllingClient);
  3926. }
  3927. }
  3928. }
  3929. ScriptSleep(m_sleepMsOnSetDamage);
  3930. }
  3931. public void llTeleportAgent(string agent, string destination, LSL_Vector targetPos, LSL_Vector targetLookAt)
  3932. {
  3933. m_host.AddScriptLPS(1);
  3934. UUID agentId = new UUID();
  3935. if (UUID.TryParse(agent, out agentId))
  3936. {
  3937. ScenePresence presence = World.GetScenePresence(agentId);
  3938. if (presence != null && presence.PresenceType != PresenceType.Npc)
  3939. {
  3940. // agent must not be a god
  3941. if (presence.GodLevel >= 200) return;
  3942. if (destination == String.Empty)
  3943. destination = World.RegionInfo.RegionName;
  3944. // agent must be over the owners land
  3945. if (m_host.OwnerID == World.LandChannel.GetLandObject(presence.AbsolutePosition).LandData.OwnerID)
  3946. {
  3947. DoLLTeleport(presence, destination, targetPos, targetLookAt);
  3948. }
  3949. else // or must be wearing the prim
  3950. {
  3951. if (m_host.ParentGroup.AttachmentPoint != 0 && m_host.OwnerID == presence.UUID)
  3952. {
  3953. DoLLTeleport(presence, destination, targetPos, targetLookAt);
  3954. }
  3955. }
  3956. }
  3957. }
  3958. }
  3959. public void llTeleportAgentGlobalCoords(string agent, LSL_Vector global_coords, LSL_Vector targetPos, LSL_Vector targetLookAt)
  3960. {
  3961. m_host.AddScriptLPS(1);
  3962. UUID agentId = new UUID();
  3963. ulong regionHandle = Util.RegionWorldLocToHandle((uint)global_coords.x, (uint)global_coords.y);
  3964. if (UUID.TryParse(agent, out agentId))
  3965. {
  3966. ScenePresence presence = World.GetScenePresence(agentId);
  3967. if (presence != null && presence.PresenceType != PresenceType.Npc)
  3968. {
  3969. // agent must not be a god
  3970. if (presence.GodLevel >= 200) return;
  3971. // agent must be over the owners land
  3972. if (m_host.OwnerID == World.LandChannel.GetLandObject(presence.AbsolutePosition).LandData.OwnerID)
  3973. {
  3974. World.RequestTeleportLocation(presence.ControllingClient, regionHandle, targetPos, targetLookAt, (uint)TeleportFlags.ViaLocation);
  3975. }
  3976. else // or must be wearing the prim
  3977. {
  3978. if (m_host.ParentGroup.AttachmentPoint != 0 && m_host.OwnerID == presence.UUID)
  3979. {
  3980. World.RequestTeleportLocation(presence.ControllingClient, regionHandle, targetPos, targetLookAt, (uint)TeleportFlags.ViaLocation);
  3981. }
  3982. }
  3983. }
  3984. }
  3985. }
  3986. private void DoLLTeleport(ScenePresence sp, string destination, Vector3 targetPos, Vector3 targetLookAt)
  3987. {
  3988. UUID assetID = ScriptUtils.GetAssetIdFromKeyOrItemName(m_host, destination);
  3989. // The destinaion is not an asset ID and also doesn't name a landmark.
  3990. // Use it as a sim name
  3991. if (assetID == UUID.Zero)
  3992. {
  3993. World.RequestTeleportLocation(sp.ControllingClient, destination, targetPos, targetLookAt, (uint)TeleportFlags.ViaLocation);
  3994. return;
  3995. }
  3996. AssetBase lma = World.AssetService.Get(assetID.ToString());
  3997. if (lma == null)
  3998. return;
  3999. if (lma.Type != (sbyte)AssetType.Landmark)
  4000. return;
  4001. AssetLandmark lm = new AssetLandmark(lma);
  4002. World.RequestTeleportLocation(sp.ControllingClient, lm.RegionHandle, targetPos, targetLookAt, (uint)TeleportFlags.ViaLocation);
  4003. }
  4004. public void llTextBox(string agent, string message, int chatChannel)
  4005. {
  4006. IDialogModule dm = World.RequestModuleInterface<IDialogModule>();
  4007. if (dm == null)
  4008. return;
  4009. m_host.AddScriptLPS(1);
  4010. UUID av = new UUID();
  4011. if (!UUID.TryParse(agent,out av))
  4012. {
  4013. Error("llTextBox", "First parameter must be a key");
  4014. return;
  4015. }
  4016. if (message == string.Empty)
  4017. {
  4018. Error("llTextBox", "Empty message");
  4019. }
  4020. else if (message.Length > 512)
  4021. {
  4022. Error("llTextBox", "Message more than 512 characters");
  4023. }
  4024. else
  4025. {
  4026. dm.SendTextBoxToUser(av, message, chatChannel, m_host.Name, m_host.UUID, m_host.OwnerID);
  4027. ScriptSleep(m_sleepMsOnTextBox);
  4028. }
  4029. }
  4030. public void llModifyLand(int action, int brush)
  4031. {
  4032. m_host.AddScriptLPS(1);
  4033. ITerrainModule tm = m_ScriptEngine.World.RequestModuleInterface<ITerrainModule>();
  4034. if (tm != null)
  4035. {
  4036. tm.ModifyTerrain(m_host.OwnerID, m_host.AbsolutePosition, (byte) brush, (byte) action, m_host.OwnerID);
  4037. }
  4038. }
  4039. public void llCollisionSound(string impact_sound, double impact_volume)
  4040. {
  4041. m_host.AddScriptLPS(1);
  4042. // TODO: Parameter check logic required.
  4043. m_host.CollisionSound = ScriptUtils.GetAssetIdFromKeyOrItemName(m_host, impact_sound, AssetType.Sound);
  4044. m_host.CollisionSoundVolume = (float)impact_volume;
  4045. }
  4046. public LSL_String llGetAnimation(string id)
  4047. {
  4048. // This should only return a value if the avatar is in the same region
  4049. m_host.AddScriptLPS(1);
  4050. UUID avatar = (UUID)id;
  4051. ScenePresence presence = World.GetScenePresence(avatar);
  4052. if (presence == null)
  4053. return "";
  4054. if (m_host.RegionHandle == presence.RegionHandle)
  4055. {
  4056. Dictionary<UUID, string> animationstateNames = DefaultAvatarAnimations.AnimStateNames;
  4057. if (presence != null)
  4058. {
  4059. AnimationSet currentAnims = presence.Animator.Animations;
  4060. string currentAnimationState = String.Empty;
  4061. if (animationstateNames.TryGetValue(currentAnims.ImplicitDefaultAnimation.AnimID, out currentAnimationState))
  4062. return currentAnimationState;
  4063. }
  4064. }
  4065. return String.Empty;
  4066. }
  4067. public void llMessageLinked(int linknumber, int num, string msg, string id)
  4068. {
  4069. m_host.AddScriptLPS(1);
  4070. List<SceneObjectPart> parts = GetLinkParts(linknumber);
  4071. UUID partItemID;
  4072. foreach (SceneObjectPart part in parts)
  4073. {
  4074. foreach (TaskInventoryItem item in part.Inventory.GetInventoryItems())
  4075. {
  4076. if (item.Type == ScriptBaseClass.INVENTORY_SCRIPT)
  4077. {
  4078. partItemID = item.ItemID;
  4079. int linkNumber = m_host.LinkNum;
  4080. if (m_host.ParentGroup.PrimCount == 1)
  4081. linkNumber = 0;
  4082. object[] resobj = new object[]
  4083. {
  4084. new LSL_Integer(linkNumber), new LSL_Integer(num), new LSL_String(msg), new LSL_String(id)
  4085. };
  4086. m_ScriptEngine.PostScriptEvent(partItemID,
  4087. new EventParams("link_message",
  4088. resobj, new DetectParams[0]));
  4089. }
  4090. }
  4091. }
  4092. }
  4093. public void llPushObject(string target, LSL_Vector impulse, LSL_Vector ang_impulse, int local)
  4094. {
  4095. m_host.AddScriptLPS(1);
  4096. bool pushrestricted = World.RegionInfo.RegionSettings.RestrictPushing;
  4097. bool pushAllowed = false;
  4098. bool pusheeIsAvatar = false;
  4099. UUID targetID = UUID.Zero;
  4100. if (!UUID.TryParse(target,out targetID))
  4101. return;
  4102. ScenePresence pusheeav = null;
  4103. Vector3 PusheePos = Vector3.Zero;
  4104. SceneObjectPart pusheeob = null;
  4105. ScenePresence avatar = World.GetScenePresence(targetID);
  4106. if (avatar != null)
  4107. {
  4108. pusheeIsAvatar = true;
  4109. // Pushee doesn't have a physics actor
  4110. if (avatar.PhysicsActor == null)
  4111. return;
  4112. // Pushee is in GodMode this pushing object isn't owned by them
  4113. if (avatar.GodLevel > 0 && m_host.OwnerID != targetID)
  4114. return;
  4115. pusheeav = avatar;
  4116. // Find pushee position
  4117. // Pushee Linked?
  4118. SceneObjectPart sitPart = pusheeav.ParentPart;
  4119. if (sitPart != null)
  4120. PusheePos = sitPart.AbsolutePosition;
  4121. else
  4122. PusheePos = pusheeav.AbsolutePosition;
  4123. }
  4124. if (!pusheeIsAvatar)
  4125. {
  4126. // not an avatar so push is not affected by parcel flags
  4127. pusheeob = World.GetSceneObjectPart((UUID)target);
  4128. // We can't find object
  4129. if (pusheeob == null)
  4130. return;
  4131. // Object not pushable. Not an attachment and has no physics component
  4132. if (!pusheeob.ParentGroup.IsAttachment && pusheeob.PhysActor == null)
  4133. return;
  4134. PusheePos = pusheeob.AbsolutePosition;
  4135. pushAllowed = true;
  4136. }
  4137. else
  4138. {
  4139. if (pushrestricted)
  4140. {
  4141. ILandObject targetlandObj = World.LandChannel.GetLandObject(PusheePos);
  4142. // We didn't find the parcel but region is push restricted so assume it is NOT ok
  4143. if (targetlandObj == null)
  4144. return;
  4145. // Need provisions for Group Owned here
  4146. if (m_host.OwnerID == targetlandObj.LandData.OwnerID ||
  4147. targetlandObj.LandData.IsGroupOwned || m_host.OwnerID == targetID)
  4148. {
  4149. pushAllowed = true;
  4150. }
  4151. }
  4152. else
  4153. {
  4154. ILandObject targetlandObj = World.LandChannel.GetLandObject(PusheePos);
  4155. if (targetlandObj == null)
  4156. {
  4157. // We didn't find the parcel but region isn't push restricted so assume it's ok
  4158. pushAllowed = true;
  4159. }
  4160. else
  4161. {
  4162. // Parcel push restriction
  4163. if ((targetlandObj.LandData.Flags & (uint)ParcelFlags.RestrictPushObject) == (uint)ParcelFlags.RestrictPushObject)
  4164. {
  4165. // Need provisions for Group Owned here
  4166. if (m_host.OwnerID == targetlandObj.LandData.OwnerID ||
  4167. targetlandObj.LandData.IsGroupOwned ||
  4168. m_host.OwnerID == targetID)
  4169. {
  4170. pushAllowed = true;
  4171. }
  4172. //ParcelFlags.RestrictPushObject
  4173. //pushAllowed = true;
  4174. }
  4175. else
  4176. {
  4177. // Parcel isn't push restricted
  4178. pushAllowed = true;
  4179. }
  4180. }
  4181. }
  4182. }
  4183. if (pushAllowed)
  4184. {
  4185. float distance = (PusheePos - m_host.AbsolutePosition).Length();
  4186. float distance_term = distance * distance * distance; // Script Energy
  4187. float pusher_mass = m_host.GetMass();
  4188. float PUSH_ATTENUATION_DISTANCE = 17f;
  4189. float PUSH_ATTENUATION_SCALE = 5f;
  4190. float distance_attenuation = 1f;
  4191. if (distance > PUSH_ATTENUATION_DISTANCE)
  4192. {
  4193. float normalized_units = 1f + (distance - PUSH_ATTENUATION_DISTANCE) / PUSH_ATTENUATION_SCALE;
  4194. distance_attenuation = 1f / normalized_units;
  4195. }
  4196. Vector3 applied_linear_impulse = impulse;
  4197. {
  4198. float impulse_length = applied_linear_impulse.Length();
  4199. float desired_energy = impulse_length * pusher_mass;
  4200. if (desired_energy > 0f)
  4201. desired_energy += distance_term;
  4202. float scaling_factor = 1f;
  4203. scaling_factor *= distance_attenuation;
  4204. applied_linear_impulse *= scaling_factor;
  4205. }
  4206. if (pusheeIsAvatar)
  4207. {
  4208. if (pusheeav != null)
  4209. {
  4210. PhysicsActor pa = pusheeav.PhysicsActor;
  4211. if (pa != null)
  4212. {
  4213. if (local != 0)
  4214. {
  4215. applied_linear_impulse *= m_host.GetWorldRotation();
  4216. }
  4217. pa.AddForce(applied_linear_impulse, true);
  4218. }
  4219. }
  4220. }
  4221. else
  4222. {
  4223. if (pusheeob != null)
  4224. {
  4225. if (pusheeob.PhysActor != null)
  4226. {
  4227. pusheeob.ApplyImpulse(applied_linear_impulse, local != 0);
  4228. }
  4229. }
  4230. }
  4231. }
  4232. }
  4233. public void llPassCollisions(int pass)
  4234. {
  4235. m_host.AddScriptLPS(1);
  4236. if (pass == 0)
  4237. {
  4238. m_host.PassCollisions = false;
  4239. }
  4240. else
  4241. {
  4242. m_host.PassCollisions = true;
  4243. }
  4244. }
  4245. public LSL_String llGetScriptName()
  4246. {
  4247. m_host.AddScriptLPS(1);
  4248. return m_item.Name != null ? m_item.Name : String.Empty;
  4249. }
  4250. public LSL_Integer llGetLinkNumberOfSides(int link)
  4251. {
  4252. m_host.AddScriptLPS(1);
  4253. SceneObjectPart linkedPart;
  4254. if (link == ScriptBaseClass.LINK_ROOT)
  4255. linkedPart = m_host.ParentGroup.RootPart;
  4256. else if (link == ScriptBaseClass.LINK_THIS)
  4257. linkedPart = m_host;
  4258. else
  4259. linkedPart = m_host.ParentGroup.GetLinkNumPart(link);
  4260. return GetNumberOfSides(linkedPart);
  4261. }
  4262. public LSL_Integer llGetNumberOfSides()
  4263. {
  4264. m_host.AddScriptLPS(1);
  4265. return GetNumberOfSides(m_host);
  4266. }
  4267. protected int GetNumberOfSides(SceneObjectPart part)
  4268. {
  4269. int sides = part.GetNumberOfSides();
  4270. if (part.GetPrimType() == PrimType.SPHERE && part.Shape.ProfileHollow > 0)
  4271. {
  4272. // Make up for a bug where LSL shows 4 sides rather than 2
  4273. sides += 2;
  4274. }
  4275. return sides;
  4276. }
  4277. /* The new / changed functions were tested with the following LSL script:
  4278. default
  4279. {
  4280. state_entry()
  4281. {
  4282. rotation rot = llEuler2Rot(<0,70,0> * DEG_TO_RAD);
  4283. llOwnerSay("to get here, we rotate over: "+ (string) llRot2Axis(rot));
  4284. llOwnerSay("and we rotate for: "+ (llRot2Angle(rot) * RAD_TO_DEG));
  4285. // convert back and forth between quaternion <-> vector and angle
  4286. rotation newrot = llAxisAngle2Rot(llRot2Axis(rot),llRot2Angle(rot));
  4287. llOwnerSay("Old rotation was: "+(string) rot);
  4288. llOwnerSay("re-converted rotation is: "+(string) newrot);
  4289. llSetRot(rot); // to check the parameters in the prim
  4290. }
  4291. }
  4292. */
  4293. // Xantor 29/apr/2008
  4294. // Returns rotation described by rotating angle radians about axis.
  4295. // q = cos(a/2) + i (x * sin(a/2)) + j (y * sin(a/2)) + k (z * sin(a/2))
  4296. public LSL_Rotation llAxisAngle2Rot(LSL_Vector axis, double angle)
  4297. {
  4298. m_host.AddScriptLPS(1);
  4299. double x, y, z, s, t;
  4300. s = Math.Cos(angle * 0.5);
  4301. t = Math.Sin(angle * 0.5); // temp value to avoid 2 more sin() calcs
  4302. axis = LSL_Vector.Norm(axis);
  4303. x = axis.x * t;
  4304. y = axis.y * t;
  4305. z = axis.z * t;
  4306. return new LSL_Rotation(x,y,z,s);
  4307. }
  4308. /// <summary>
  4309. /// Returns the axis of rotation for a quaternion
  4310. /// </summary>
  4311. /// <returns></returns>
  4312. /// <param name='rot'></param>
  4313. public LSL_Vector llRot2Axis(LSL_Rotation rot)
  4314. {
  4315. m_host.AddScriptLPS(1);
  4316. if (Math.Abs(rot.s) > 1) // normalization needed
  4317. rot.Normalize();
  4318. double s = Math.Sqrt(1 - rot.s * rot.s);
  4319. if (s < 0.001)
  4320. {
  4321. return new LSL_Vector(1, 0, 0);
  4322. }
  4323. else
  4324. {
  4325. double invS = 1.0 / s;
  4326. if (rot.s < 0) invS = -invS;
  4327. return new LSL_Vector(rot.x * invS, rot.y * invS, rot.z * invS);
  4328. }
  4329. }
  4330. // Returns the angle of a quaternion (see llRot2Axis for the axis)
  4331. public LSL_Float llRot2Angle(LSL_Rotation rot)
  4332. {
  4333. m_host.AddScriptLPS(1);
  4334. if (Math.Abs(rot.s) > 1) // normalization needed
  4335. rot.Normalize();
  4336. double angle = 2 * Math.Acos(rot.s);
  4337. if (angle > Math.PI)
  4338. angle = 2 * Math.PI - angle;
  4339. return angle;
  4340. }
  4341. public LSL_Float llAcos(double val)
  4342. {
  4343. m_host.AddScriptLPS(1);
  4344. return (double)Math.Acos(val);
  4345. }
  4346. public LSL_Float llAsin(double val)
  4347. {
  4348. m_host.AddScriptLPS(1);
  4349. return (double)Math.Asin(val);
  4350. }
  4351. // jcochran 5/jan/2012
  4352. public LSL_Float llAngleBetween(LSL_Rotation a, LSL_Rotation b)
  4353. {
  4354. m_host.AddScriptLPS(1);
  4355. double aa = (a.x * a.x + a.y * a.y + a.z * a.z + a.s * a.s);
  4356. double bb = (b.x * b.x + b.y * b.y + b.z * b.z + b.s * b.s);
  4357. double aa_bb = aa * bb;
  4358. if (aa_bb == 0) return 0.0;
  4359. double ab = (a.x * b.x + a.y * b.y + a.z * b.z + a.s * b.s);
  4360. double quotient = (ab * ab) / aa_bb;
  4361. if (quotient >= 1.0) return 0.0;
  4362. return Math.Acos(2 * quotient - 1);
  4363. }
  4364. public LSL_String llGetInventoryKey(string name)
  4365. {
  4366. m_host.AddScriptLPS(1);
  4367. TaskInventoryItem item = m_host.Inventory.GetInventoryItem(name);
  4368. if (item == null)
  4369. return UUID.Zero.ToString();
  4370. if ((item.CurrentPermissions
  4371. & (uint)(PermissionMask.Copy | PermissionMask.Transfer | PermissionMask.Modify))
  4372. == (uint)(PermissionMask.Copy | PermissionMask.Transfer | PermissionMask.Modify))
  4373. {
  4374. return item.AssetID.ToString();
  4375. }
  4376. return UUID.Zero.ToString();
  4377. }
  4378. public void llAllowInventoryDrop(int add)
  4379. {
  4380. m_host.AddScriptLPS(1);
  4381. if (add != 0)
  4382. m_host.ParentGroup.RootPart.AllowedDrop = true;
  4383. else
  4384. m_host.ParentGroup.RootPart.AllowedDrop = false;
  4385. // Update the object flags
  4386. m_host.ParentGroup.RootPart.aggregateScriptEvents();
  4387. }
  4388. public LSL_Vector llGetSunDirection()
  4389. {
  4390. m_host.AddScriptLPS(1);
  4391. LSL_Vector SunDoubleVector3;
  4392. Vector3 SunFloatVector3;
  4393. // sunPosition estate setting is set in OpenSim.Region.CoreModules.SunModule
  4394. // have to convert from Vector3 (float) to LSL_Vector (double)
  4395. SunFloatVector3 = World.RegionInfo.RegionSettings.SunVector;
  4396. SunDoubleVector3.x = (double)SunFloatVector3.X;
  4397. SunDoubleVector3.y = (double)SunFloatVector3.Y;
  4398. SunDoubleVector3.z = (double)SunFloatVector3.Z;
  4399. return SunDoubleVector3;
  4400. }
  4401. public LSL_Vector llGetTextureOffset(int face)
  4402. {
  4403. m_host.AddScriptLPS(1);
  4404. return GetTextureOffset(m_host, face);
  4405. }
  4406. protected LSL_Vector GetTextureOffset(SceneObjectPart part, int face)
  4407. {
  4408. Primitive.TextureEntry tex = part.Shape.Textures;
  4409. LSL_Vector offset = new LSL_Vector();
  4410. if (face == ScriptBaseClass.ALL_SIDES)
  4411. {
  4412. face = 0;
  4413. }
  4414. if (face >= 0 && face < GetNumberOfSides(part))
  4415. {
  4416. offset.x = tex.GetFace((uint)face).OffsetU;
  4417. offset.y = tex.GetFace((uint)face).OffsetV;
  4418. offset.z = 0.0;
  4419. return offset;
  4420. }
  4421. else
  4422. {
  4423. return offset;
  4424. }
  4425. }
  4426. public LSL_Vector llGetTextureScale(int side)
  4427. {
  4428. m_host.AddScriptLPS(1);
  4429. Primitive.TextureEntry tex = m_host.Shape.Textures;
  4430. LSL_Vector scale;
  4431. if (side == -1)
  4432. {
  4433. side = 0;
  4434. }
  4435. scale.x = tex.GetFace((uint)side).RepeatU;
  4436. scale.y = tex.GetFace((uint)side).RepeatV;
  4437. scale.z = 0.0;
  4438. return scale;
  4439. }
  4440. public LSL_Float llGetTextureRot(int face)
  4441. {
  4442. m_host.AddScriptLPS(1);
  4443. return GetTextureRot(m_host, face);
  4444. }
  4445. protected LSL_Float GetTextureRot(SceneObjectPart part, int face)
  4446. {
  4447. Primitive.TextureEntry tex = part.Shape.Textures;
  4448. if (face == -1)
  4449. {
  4450. face = 0;
  4451. }
  4452. if (face >= 0 && face < GetNumberOfSides(part))
  4453. {
  4454. return tex.GetFace((uint)face).Rotation;
  4455. }
  4456. else
  4457. {
  4458. return 0.0;
  4459. }
  4460. }
  4461. public LSL_Integer llSubStringIndex(string source, string pattern)
  4462. {
  4463. m_host.AddScriptLPS(1);
  4464. return source.IndexOf(pattern);
  4465. }
  4466. public LSL_String llGetOwnerKey(string id)
  4467. {
  4468. m_host.AddScriptLPS(1);
  4469. UUID key = new UUID();
  4470. if (UUID.TryParse(id, out key))
  4471. {
  4472. try
  4473. {
  4474. SceneObjectPart obj = World.GetSceneObjectPart(key);
  4475. if (obj == null)
  4476. return id; // the key is for an agent so just return the key
  4477. else
  4478. return obj.OwnerID.ToString();
  4479. }
  4480. catch (KeyNotFoundException)
  4481. {
  4482. return id; // The Object/Agent not in the region so just return the key
  4483. }
  4484. }
  4485. else
  4486. {
  4487. return UUID.Zero.ToString();
  4488. }
  4489. }
  4490. public LSL_Vector llGetCenterOfMass()
  4491. {
  4492. m_host.AddScriptLPS(1);
  4493. return new LSL_Vector(m_host.GetCenterOfMass());
  4494. }
  4495. public LSL_List llListSort(LSL_List src, int stride, int ascending)
  4496. {
  4497. m_host.AddScriptLPS(1);
  4498. if (stride <= 0)
  4499. {
  4500. stride = 1;
  4501. }
  4502. return src.Sort(stride, ascending);
  4503. }
  4504. public LSL_Integer llGetListLength(LSL_List src)
  4505. {
  4506. m_host.AddScriptLPS(1);
  4507. if (src == null)
  4508. {
  4509. return 0;
  4510. }
  4511. else
  4512. {
  4513. return src.Length;
  4514. }
  4515. }
  4516. public LSL_Integer llList2Integer(LSL_List src, int index)
  4517. {
  4518. m_host.AddScriptLPS(1);
  4519. if (index < 0)
  4520. {
  4521. index = src.Length + index;
  4522. }
  4523. if (index >= src.Length || index < 0)
  4524. {
  4525. return 0;
  4526. }
  4527. // Vectors & Rotations always return zero in SL, but
  4528. // keys don't always return zero, it seems to be a bit complex.
  4529. else if (src.Data[index] is LSL_Vector ||
  4530. src.Data[index] is LSL_Rotation)
  4531. {
  4532. return 0;
  4533. }
  4534. try
  4535. {
  4536. if (src.Data[index] is LSL_Integer)
  4537. return (LSL_Integer)src.Data[index];
  4538. else if (src.Data[index] is LSL_Float)
  4539. return Convert.ToInt32(((LSL_Float)src.Data[index]).value);
  4540. return new LSL_Integer(src.Data[index].ToString());
  4541. }
  4542. catch (FormatException)
  4543. {
  4544. return 0;
  4545. }
  4546. }
  4547. public LSL_Float llList2Float(LSL_List src, int index)
  4548. {
  4549. m_host.AddScriptLPS(1);
  4550. if (index < 0)
  4551. {
  4552. index = src.Length + index;
  4553. }
  4554. if (index >= src.Length || index < 0)
  4555. {
  4556. return 0.0;
  4557. }
  4558. // Vectors & Rotations always return zero in SL
  4559. else if (src.Data[index] is LSL_Vector ||
  4560. src.Data[index] is LSL_Rotation)
  4561. {
  4562. return 0;
  4563. }
  4564. // valid keys seem to get parsed as integers then converted to floats
  4565. else
  4566. {
  4567. UUID uuidt;
  4568. if (src.Data[index] is LSL_Key && UUID.TryParse(src.Data[index].ToString(), out uuidt))
  4569. {
  4570. return Convert.ToDouble(new LSL_Integer(src.Data[index].ToString()).value);
  4571. }
  4572. }
  4573. try
  4574. {
  4575. if (src.Data[index] is LSL_Integer)
  4576. return Convert.ToDouble(((LSL_Integer)src.Data[index]).value);
  4577. else if (src.Data[index] is LSL_Float)
  4578. return Convert.ToDouble(((LSL_Float)src.Data[index]).value);
  4579. else if (src.Data[index] is LSL_String)
  4580. return Convert.ToDouble(((LSL_String)src.Data[index]).m_string);
  4581. return Convert.ToDouble(src.Data[index]);
  4582. }
  4583. catch (FormatException)
  4584. {
  4585. return 0.0;
  4586. }
  4587. }
  4588. public LSL_String llList2String(LSL_List src, int index)
  4589. {
  4590. m_host.AddScriptLPS(1);
  4591. if (index < 0)
  4592. {
  4593. index = src.Length + index;
  4594. }
  4595. if (index >= src.Length || index < 0)
  4596. {
  4597. return String.Empty;
  4598. }
  4599. return src.Data[index].ToString();
  4600. }
  4601. public LSL_Key llList2Key(LSL_List src, int index)
  4602. {
  4603. m_host.AddScriptLPS(1);
  4604. if (index < 0)
  4605. {
  4606. index = src.Length + index;
  4607. }
  4608. if (index >= src.Length || index < 0)
  4609. {
  4610. return "";
  4611. }
  4612. // SL spits out an empty string for types other than key & string
  4613. // At the time of patching, LSL_Key is currently LSL_String,
  4614. // so the OR check may be a little redundant, but it's being done
  4615. // for completion and should LSL_Key ever be implemented
  4616. // as it's own struct
  4617. // NOTE: 3rd case is needed because a NULL_KEY comes through as
  4618. // type 'obj' and wrongly returns ""
  4619. else if (!(src.Data[index] is LSL_String ||
  4620. src.Data[index] is LSL_Key ||
  4621. src.Data[index].ToString() == "00000000-0000-0000-0000-000000000000"))
  4622. {
  4623. return "";
  4624. }
  4625. return src.Data[index].ToString();
  4626. }
  4627. public LSL_Vector llList2Vector(LSL_List src, int index)
  4628. {
  4629. m_host.AddScriptLPS(1);
  4630. if (index < 0)
  4631. {
  4632. index = src.Length + index;
  4633. }
  4634. if (index >= src.Length || index < 0)
  4635. {
  4636. return new LSL_Vector(0, 0, 0);
  4637. }
  4638. if (src.Data[index].GetType() == typeof(LSL_Vector))
  4639. {
  4640. return (LSL_Vector)src.Data[index];
  4641. }
  4642. // SL spits always out ZERO_VECTOR for anything other than
  4643. // strings or vectors. Although keys always return ZERO_VECTOR,
  4644. // it is currently difficult to make the distinction between
  4645. // a string, a key as string and a string that by coincidence
  4646. // is a string, so we're going to leave that up to the
  4647. // LSL_Vector constructor.
  4648. else if (!(src.Data[index] is LSL_String ||
  4649. src.Data[index] is LSL_Vector))
  4650. {
  4651. return new LSL_Vector(0, 0, 0);
  4652. }
  4653. else
  4654. {
  4655. return new LSL_Vector(src.Data[index].ToString());
  4656. }
  4657. }
  4658. public LSL_Rotation llList2Rot(LSL_List src, int index)
  4659. {
  4660. m_host.AddScriptLPS(1);
  4661. if (index < 0)
  4662. {
  4663. index = src.Length + index;
  4664. }
  4665. if (index >= src.Length || index < 0)
  4666. {
  4667. return new LSL_Rotation(0, 0, 0, 1);
  4668. }
  4669. // SL spits always out ZERO_ROTATION for anything other than
  4670. // strings or vectors. Although keys always return ZERO_ROTATION,
  4671. // it is currently difficult to make the distinction between
  4672. // a string, a key as string and a string that by coincidence
  4673. // is a string, so we're going to leave that up to the
  4674. // LSL_Rotation constructor.
  4675. else if (!(src.Data[index] is LSL_String ||
  4676. src.Data[index] is LSL_Rotation))
  4677. {
  4678. return new LSL_Rotation(0, 0, 0, 1);
  4679. }
  4680. else if (src.Data[index].GetType() == typeof(LSL_Rotation))
  4681. {
  4682. return (LSL_Rotation)src.Data[index];
  4683. }
  4684. else
  4685. {
  4686. return new LSL_Rotation(src.Data[index].ToString());
  4687. }
  4688. }
  4689. public LSL_List llList2List(LSL_List src, int start, int end)
  4690. {
  4691. m_host.AddScriptLPS(1);
  4692. return src.GetSublist(start, end);
  4693. }
  4694. public LSL_List llDeleteSubList(LSL_List src, int start, int end)
  4695. {
  4696. return src.DeleteSublist(start, end);
  4697. }
  4698. public LSL_Integer llGetListEntryType(LSL_List src, int index)
  4699. {
  4700. m_host.AddScriptLPS(1);
  4701. if (index < 0)
  4702. {
  4703. index = src.Length + index;
  4704. }
  4705. if (index >= src.Length)
  4706. {
  4707. return 0;
  4708. }
  4709. if (src.Data[index] is LSL_Integer || src.Data[index] is Int32)
  4710. return 1;
  4711. if (src.Data[index] is LSL_Float || src.Data[index] is Single || src.Data[index] is Double)
  4712. return 2;
  4713. if (src.Data[index] is LSL_String || src.Data[index] is String)
  4714. {
  4715. UUID tuuid;
  4716. if (UUID.TryParse(src.Data[index].ToString(), out tuuid))
  4717. {
  4718. return 4;
  4719. }
  4720. else
  4721. {
  4722. return 3;
  4723. }
  4724. }
  4725. if (src.Data[index] is LSL_Vector)
  4726. return 5;
  4727. if (src.Data[index] is LSL_Rotation)
  4728. return 6;
  4729. if (src.Data[index] is LSL_List)
  4730. return 7;
  4731. return 0;
  4732. }
  4733. /// <summary>
  4734. /// Process the supplied list and return the
  4735. /// content of the list formatted as a comma
  4736. /// separated list. There is a space after
  4737. /// each comma.
  4738. /// </summary>
  4739. public LSL_String llList2CSV(LSL_List src)
  4740. {
  4741. m_host.AddScriptLPS(1);
  4742. return string.Join(", ",
  4743. (new List<object>(src.Data)).ConvertAll<string>(o =>
  4744. {
  4745. return o.ToString();
  4746. }).ToArray());
  4747. }
  4748. /// <summary>
  4749. /// The supplied string is scanned for commas
  4750. /// and converted into a list. Commas are only
  4751. /// effective if they are encountered outside
  4752. /// of '<' '>' delimiters. Any whitespace
  4753. /// before or after an element is trimmed.
  4754. /// </summary>
  4755. public LSL_List llCSV2List(string src)
  4756. {
  4757. LSL_List result = new LSL_List();
  4758. int parens = 0;
  4759. int start = 0;
  4760. int length = 0;
  4761. m_host.AddScriptLPS(1);
  4762. for (int i = 0; i < src.Length; i++)
  4763. {
  4764. switch (src[i])
  4765. {
  4766. case '<':
  4767. parens++;
  4768. length++;
  4769. break;
  4770. case '>':
  4771. if (parens > 0)
  4772. parens--;
  4773. length++;
  4774. break;
  4775. case ',':
  4776. if (parens == 0)
  4777. {
  4778. result.Add(new LSL_String(src.Substring(start,length).Trim()));
  4779. start += length+1;
  4780. length = 0;
  4781. }
  4782. else
  4783. {
  4784. length++;
  4785. }
  4786. break;
  4787. default:
  4788. length++;
  4789. break;
  4790. }
  4791. }
  4792. result.Add(new LSL_String(src.Substring(start,length).Trim()));
  4793. return result;
  4794. }
  4795. /// <summary>
  4796. /// Randomizes the list, be arbitrarily reordering
  4797. /// sublists of stride elements. As the stride approaches
  4798. /// the size of the list, the options become very
  4799. /// limited.
  4800. /// </summary>
  4801. /// <remarks>
  4802. /// This could take a while for very large list
  4803. /// sizes.
  4804. /// </remarks>
  4805. public LSL_List llListRandomize(LSL_List src, int stride)
  4806. {
  4807. LSL_List result;
  4808. Random rand = new Random();
  4809. int chunkk;
  4810. int[] chunks;
  4811. m_host.AddScriptLPS(1);
  4812. if (stride <= 0)
  4813. {
  4814. stride = 1;
  4815. }
  4816. // Stride MUST be a factor of the list length
  4817. // If not, then return the src list. This also
  4818. // traps those cases where stride > length.
  4819. if (src.Length != stride && src.Length%stride == 0)
  4820. {
  4821. chunkk = src.Length/stride;
  4822. chunks = new int[chunkk];
  4823. for (int i = 0; i < chunkk; i++)
  4824. chunks[i] = i;
  4825. // Knuth shuffle the chunkk index
  4826. for (int i = chunkk - 1; i >= 1; i--)
  4827. {
  4828. // Elect an unrandomized chunk to swap
  4829. int index = rand.Next(i + 1);
  4830. int tmp;
  4831. // and swap position with first unrandomized chunk
  4832. tmp = chunks[i];
  4833. chunks[i] = chunks[index];
  4834. chunks[index] = tmp;
  4835. }
  4836. // Construct the randomized list
  4837. result = new LSL_List();
  4838. for (int i = 0; i < chunkk; i++)
  4839. {
  4840. for (int j = 0; j < stride; j++)
  4841. {
  4842. result.Add(src.Data[chunks[i]*stride+j]);
  4843. }
  4844. }
  4845. }
  4846. else {
  4847. object[] array = new object[src.Length];
  4848. Array.Copy(src.Data, 0, array, 0, src.Length);
  4849. result = new LSL_List(array);
  4850. }
  4851. return result;
  4852. }
  4853. /// <summary>
  4854. /// Elements in the source list starting with 0 and then
  4855. /// every i+stride. If the stride is negative then the scan
  4856. /// is backwards producing an inverted result.
  4857. /// Only those elements that are also in the specified
  4858. /// range are included in the result.
  4859. /// </summary>
  4860. public LSL_List llList2ListStrided(LSL_List src, int start, int end, int stride)
  4861. {
  4862. LSL_List result = new LSL_List();
  4863. int[] si = new int[2];
  4864. int[] ei = new int[2];
  4865. bool twopass = false;
  4866. m_host.AddScriptLPS(1);
  4867. // First step is always to deal with negative indices
  4868. if (start < 0)
  4869. start = src.Length+start;
  4870. if (end < 0)
  4871. end = src.Length+end;
  4872. // Out of bounds indices are OK, just trim them
  4873. // accordingly
  4874. if (start > src.Length)
  4875. start = src.Length;
  4876. if (end > src.Length)
  4877. end = src.Length;
  4878. if (stride == 0)
  4879. stride = 1;
  4880. // There may be one or two ranges to be considered
  4881. if (start != end)
  4882. {
  4883. if (start <= end)
  4884. {
  4885. si[0] = start;
  4886. ei[0] = end;
  4887. }
  4888. else
  4889. {
  4890. si[1] = start;
  4891. ei[1] = src.Length;
  4892. si[0] = 0;
  4893. ei[0] = end;
  4894. twopass = true;
  4895. }
  4896. // The scan always starts from the beginning of the
  4897. // source list, but members are only selected if they
  4898. // fall within the specified sub-range. The specified
  4899. // range values are inclusive.
  4900. // A negative stride reverses the direction of the
  4901. // scan producing an inverted list as a result.
  4902. if (stride > 0)
  4903. {
  4904. for (int i = 0; i < src.Length; i += stride)
  4905. {
  4906. if (i<=ei[0] && i>=si[0])
  4907. result.Add(src.Data[i]);
  4908. if (twopass && i>=si[1] && i<=ei[1])
  4909. result.Add(src.Data[i]);
  4910. }
  4911. }
  4912. else if (stride < 0)
  4913. {
  4914. for (int i = src.Length - 1; i >= 0; i += stride)
  4915. {
  4916. if (i <= ei[0] && i >= si[0])
  4917. result.Add(src.Data[i]);
  4918. if (twopass && i >= si[1] && i <= ei[1])
  4919. result.Add(src.Data[i]);
  4920. }
  4921. }
  4922. }
  4923. else
  4924. {
  4925. if (start%stride == 0)
  4926. {
  4927. result.Add(src.Data[start]);
  4928. }
  4929. }
  4930. return result;
  4931. }
  4932. public LSL_Integer llGetRegionAgentCount()
  4933. {
  4934. m_host.AddScriptLPS(1);
  4935. return new LSL_Integer(World.GetRootAgentCount());
  4936. }
  4937. public LSL_Vector llGetRegionCorner()
  4938. {
  4939. m_host.AddScriptLPS(1);
  4940. return new LSL_Vector(World.RegionInfo.WorldLocX, World.RegionInfo.WorldLocY, 0);
  4941. }
  4942. public LSL_String llGetEnv(LSL_String name)
  4943. {
  4944. m_host.AddScriptLPS(1);
  4945. if (name == "dynamic_pathfinding")
  4946. {
  4947. return "0";
  4948. }
  4949. else if (name == "estate_id")
  4950. {
  4951. return World.RegionInfo.EstateSettings.EstateID.ToString();
  4952. }
  4953. else if (name == "frame_number")
  4954. {
  4955. return World.Frame.ToString();
  4956. }
  4957. else if (name == "region_idle")
  4958. {
  4959. return "0";
  4960. }
  4961. else if (name == "sim_channel")
  4962. {
  4963. return "OpenSim";
  4964. }
  4965. else if (name == "sim_version")
  4966. {
  4967. return World.GetSimulatorVersion();
  4968. }
  4969. else
  4970. {
  4971. return "";
  4972. }
  4973. }
  4974. /// <summary>
  4975. /// Insert the list identified by <paramref name="src"/> into the
  4976. /// list designated by <paramref name="dest"/> such that the first
  4977. /// new element has the index specified by <paramref name="index"/>
  4978. /// </summary>
  4979. public LSL_List llListInsertList(LSL_List dest, LSL_List src, int index)
  4980. {
  4981. LSL_List pref = null;
  4982. LSL_List suff = null;
  4983. m_host.AddScriptLPS(1);
  4984. if (index < 0)
  4985. {
  4986. index = index+dest.Length;
  4987. if (index < 0)
  4988. {
  4989. index = 0;
  4990. }
  4991. }
  4992. if (index != 0)
  4993. {
  4994. pref = dest.GetSublist(0,index-1);
  4995. if (index < dest.Length)
  4996. {
  4997. suff = dest.GetSublist(index,-1);
  4998. return pref + src + suff;
  4999. }
  5000. else
  5001. {
  5002. return pref + src;
  5003. }
  5004. }
  5005. else
  5006. {
  5007. if (index < dest.Length)
  5008. {
  5009. suff = dest.GetSublist(index,-1);
  5010. return src + suff;
  5011. }
  5012. else
  5013. {
  5014. return src;
  5015. }
  5016. }
  5017. }
  5018. /// <summary>
  5019. /// Returns the index of the first occurrence of test
  5020. /// in src.
  5021. /// </summary>
  5022. /// <param name="src">Source list</param>
  5023. /// <param name="test">List to search for</param>
  5024. /// <returns>
  5025. /// The index number of the point in src where test was found if it was found.
  5026. /// Otherwise returns -1
  5027. /// </returns>
  5028. public LSL_Integer llListFindList(LSL_List src, LSL_List test)
  5029. {
  5030. int index = -1;
  5031. int length = src.Length - test.Length + 1;
  5032. m_host.AddScriptLPS(1);
  5033. // If either list is empty, do not match
  5034. if (src.Length != 0 && test.Length != 0)
  5035. {
  5036. for (int i = 0; i < length; i++)
  5037. {
  5038. // Why this piece of insanity? This is because most script constants are C# value types (e.g. int)
  5039. // rather than wrapped LSL types. Such a script constant does not have int.Equal(LSL_Integer) code
  5040. // and so the comparison fails even if the LSL_Integer conceptually has the same value.
  5041. // Therefore, here we test Equals on both the source and destination objects.
  5042. // However, a future better approach may be use LSL struct script constants (e.g. LSL_Integer(1)).
  5043. if (src.Data[i].Equals(test.Data[0]) || test.Data[0].Equals(src.Data[i]))
  5044. {
  5045. int j;
  5046. for (j = 1; j < test.Length; j++)
  5047. if (!(src.Data[i+j].Equals(test.Data[j]) || test.Data[j].Equals(src.Data[i+j])))
  5048. break;
  5049. if (j == test.Length)
  5050. {
  5051. index = i;
  5052. break;
  5053. }
  5054. }
  5055. }
  5056. }
  5057. return index;
  5058. }
  5059. public LSL_String llGetObjectName()
  5060. {
  5061. m_host.AddScriptLPS(1);
  5062. return m_host.Name !=null ? m_host.Name : String.Empty;
  5063. }
  5064. public void llSetObjectName(string name)
  5065. {
  5066. m_host.AddScriptLPS(1);
  5067. m_host.Name = name != null ? name : String.Empty;
  5068. }
  5069. public LSL_String llGetDate()
  5070. {
  5071. m_host.AddScriptLPS(1);
  5072. DateTime date = DateTime.Now.ToUniversalTime();
  5073. string result = date.ToString("yyyy-MM-dd");
  5074. return result;
  5075. }
  5076. public LSL_Integer llEdgeOfWorld(LSL_Vector pos, LSL_Vector dir)
  5077. {
  5078. m_host.AddScriptLPS(1);
  5079. // edge will be used to pass the Region Coordinates offset
  5080. // we want to check for a neighboring sim
  5081. LSL_Vector edge = new LSL_Vector(0, 0, 0);
  5082. if (dir.x == 0)
  5083. {
  5084. if (dir.y == 0)
  5085. {
  5086. // Direction vector is 0,0 so return
  5087. // false since we're staying in the sim
  5088. return 0;
  5089. }
  5090. else
  5091. {
  5092. // Y is the only valid direction
  5093. edge.y = dir.y / Math.Abs(dir.y);
  5094. }
  5095. }
  5096. else
  5097. {
  5098. LSL_Float mag;
  5099. if (dir.x > 0)
  5100. {
  5101. mag = (World.RegionInfo.RegionSizeX - pos.x) / dir.x;
  5102. }
  5103. else
  5104. {
  5105. mag = (pos.x/dir.x);
  5106. }
  5107. mag = Math.Abs(mag);
  5108. edge.y = pos.y + (dir.y * mag);
  5109. if (edge.y > World.RegionInfo.RegionSizeY || edge.y < 0)
  5110. {
  5111. // Y goes out of bounds first
  5112. edge.y = dir.y / Math.Abs(dir.y);
  5113. }
  5114. else
  5115. {
  5116. // X goes out of bounds first or its a corner exit
  5117. edge.y = 0;
  5118. edge.x = dir.x / Math.Abs(dir.x);
  5119. }
  5120. }
  5121. List<GridRegion> neighbors = World.GridService.GetNeighbours(World.RegionInfo.ScopeID, World.RegionInfo.RegionID);
  5122. uint neighborX = World.RegionInfo.RegionLocX + (uint)dir.x;
  5123. uint neighborY = World.RegionInfo.RegionLocY + (uint)dir.y;
  5124. foreach (GridRegion sri in neighbors)
  5125. {
  5126. if (sri.RegionCoordX == neighborX && sri.RegionCoordY == neighborY)
  5127. return 0;
  5128. }
  5129. return 1;
  5130. }
  5131. /// <summary>
  5132. /// Not fully implemented yet. Still to do:-
  5133. /// AGENT_BUSY
  5134. /// Remove as they are done
  5135. /// </summary>
  5136. public LSL_Integer llGetAgentInfo(string id)
  5137. {
  5138. m_host.AddScriptLPS(1);
  5139. UUID key = new UUID();
  5140. if (!UUID.TryParse(id, out key))
  5141. {
  5142. return 0;
  5143. }
  5144. int flags = 0;
  5145. ScenePresence agent = World.GetScenePresence(key);
  5146. if (agent == null)
  5147. {
  5148. return 0;
  5149. }
  5150. if (agent.IsChildAgent)
  5151. return 0; // Fail if they are not in the same region
  5152. // note: in OpenSim, sitting seems to cancel AGENT_ALWAYS_RUN, unlike SL
  5153. if (agent.SetAlwaysRun)
  5154. {
  5155. flags |= ScriptBaseClass.AGENT_ALWAYS_RUN;
  5156. }
  5157. if (agent.HasAttachments())
  5158. {
  5159. flags |= ScriptBaseClass.AGENT_ATTACHMENTS;
  5160. if (agent.HasScriptedAttachments())
  5161. flags |= ScriptBaseClass.AGENT_SCRIPTED;
  5162. }
  5163. if ((agent.AgentControlFlags & (uint)AgentManager.ControlFlags.AGENT_CONTROL_FLY) != 0)
  5164. {
  5165. flags |= ScriptBaseClass.AGENT_FLYING;
  5166. flags |= ScriptBaseClass.AGENT_IN_AIR; // flying always implies in-air, even if colliding with e.g. a wall
  5167. }
  5168. if ((agent.AgentControlFlags & (uint)AgentManager.ControlFlags.AGENT_CONTROL_AWAY) != 0)
  5169. {
  5170. flags |= ScriptBaseClass.AGENT_AWAY;
  5171. }
  5172. // seems to get unset, even if in mouselook, when avatar is sitting on a prim???
  5173. if ((agent.AgentControlFlags & (uint)AgentManager.ControlFlags.AGENT_CONTROL_MOUSELOOK) != 0)
  5174. {
  5175. flags |= ScriptBaseClass.AGENT_MOUSELOOK;
  5176. }
  5177. if ((agent.State & (byte)AgentState.Typing) != (byte)0)
  5178. {
  5179. flags |= ScriptBaseClass.AGENT_TYPING;
  5180. }
  5181. string agentMovementAnimation = agent.Animator.CurrentMovementAnimation;
  5182. if (agentMovementAnimation == "CROUCH")
  5183. {
  5184. flags |= ScriptBaseClass.AGENT_CROUCHING;
  5185. }
  5186. if (agentMovementAnimation == "WALK" || agentMovementAnimation == "CROUCHWALK")
  5187. {
  5188. flags |= ScriptBaseClass.AGENT_WALKING;
  5189. }
  5190. // not colliding implies in air. Note: flying also implies in-air, even if colliding (see above)
  5191. // note: AGENT_IN_AIR and AGENT_WALKING seem to be mutually exclusive states in SL.
  5192. // note: this may need some tweaking when walking downhill. you "fall down" for a brief instant
  5193. // and don't collide when walking downhill, which instantly registers as in-air, briefly. should
  5194. // there be some minimum non-collision threshold time before claiming the avatar is in-air?
  5195. if ((flags & ScriptBaseClass.AGENT_WALKING) == 0 && !agent.IsColliding )
  5196. {
  5197. flags |= ScriptBaseClass.AGENT_IN_AIR;
  5198. }
  5199. if (agent.ParentPart != null)
  5200. {
  5201. flags |= ScriptBaseClass.AGENT_ON_OBJECT;
  5202. flags |= ScriptBaseClass.AGENT_SITTING;
  5203. }
  5204. if (agent.Animator.Animations.ImplicitDefaultAnimation.AnimID
  5205. == DefaultAvatarAnimations.AnimsUUID["SIT_GROUND_CONSTRAINED"])
  5206. {
  5207. flags |= ScriptBaseClass.AGENT_SITTING;
  5208. }
  5209. return flags;
  5210. }
  5211. public LSL_String llGetAgentLanguage(string id)
  5212. {
  5213. // This should only return a value if the avatar is in the same region
  5214. //ckrinke 1-30-09 : This needs to parse the XMLRPC language field supplied
  5215. //by the client at login. Currently returning only en-us until our I18N
  5216. //effort gains momentum
  5217. m_host.AddScriptLPS(1);
  5218. return "en-us";
  5219. }
  5220. /// <summary>
  5221. /// http://wiki.secondlife.com/wiki/LlGetAgentList
  5222. /// The list of options is currently not used in SL
  5223. /// scope is one of:-
  5224. /// AGENT_LIST_REGION - all in the region
  5225. /// AGENT_LIST_PARCEL - all in the same parcel as the scripted object
  5226. /// AGENT_LIST_PARCEL_OWNER - all in any parcel owned by the owner of the
  5227. /// current parcel.
  5228. /// </summary>
  5229. public LSL_List llGetAgentList(LSL_Integer scope, LSL_List options)
  5230. {
  5231. m_host.AddScriptLPS(1);
  5232. // the constants are 1, 2 and 4 so bits are being set, but you
  5233. // get an error "INVALID_SCOPE" if it is anything but 1, 2 and 4
  5234. bool regionWide = scope == ScriptBaseClass.AGENT_LIST_REGION;
  5235. bool parcelOwned = scope == ScriptBaseClass.AGENT_LIST_PARCEL_OWNER;
  5236. bool parcel = scope == ScriptBaseClass.AGENT_LIST_PARCEL;
  5237. LSL_List result = new LSL_List();
  5238. if (!regionWide && !parcelOwned && !parcel)
  5239. {
  5240. result.Add("INVALID_SCOPE");
  5241. return result;
  5242. }
  5243. ILandObject land;
  5244. UUID id = UUID.Zero;
  5245. if (parcel || parcelOwned)
  5246. {
  5247. land = World.LandChannel.GetLandObject(m_host.ParentGroup.RootPart.GetWorldPosition());
  5248. if (land == null)
  5249. {
  5250. id = UUID.Zero;
  5251. }
  5252. else
  5253. {
  5254. if (parcelOwned)
  5255. {
  5256. id = land.LandData.OwnerID;
  5257. }
  5258. else
  5259. {
  5260. id = land.LandData.GlobalID;
  5261. }
  5262. }
  5263. }
  5264. World.ForEachRootScenePresence(
  5265. delegate (ScenePresence ssp)
  5266. {
  5267. // Gods are not listed in SL
  5268. if (!ssp.IsDeleted && ssp.GodLevel == 0.0 && !ssp.IsChildAgent)
  5269. {
  5270. if (!regionWide)
  5271. {
  5272. land = World.LandChannel.GetLandObject(ssp.AbsolutePosition);
  5273. if (land != null)
  5274. {
  5275. if (parcelOwned && land.LandData.OwnerID == id ||
  5276. parcel && land.LandData.GlobalID == id)
  5277. {
  5278. result.Add(new LSL_Key(ssp.UUID.ToString()));
  5279. }
  5280. }
  5281. }
  5282. else
  5283. {
  5284. result.Add(new LSL_Key(ssp.UUID.ToString()));
  5285. }
  5286. }
  5287. // Maximum of 100 results
  5288. if (result.Length > 99)
  5289. {
  5290. return;
  5291. }
  5292. }
  5293. );
  5294. return result;
  5295. }
  5296. public void llAdjustSoundVolume(double volume)
  5297. {
  5298. m_host.AddScriptLPS(1);
  5299. m_host.AdjustSoundGain(volume);
  5300. ScriptSleep(m_sleepMsOnAdjustSoundVolume);
  5301. }
  5302. public void llSetSoundRadius(double radius)
  5303. {
  5304. m_host.AddScriptLPS(1);
  5305. m_host.SoundRadius = radius;
  5306. }
  5307. public LSL_String llKey2Name(string id)
  5308. {
  5309. m_host.AddScriptLPS(1);
  5310. UUID key = new UUID();
  5311. if (UUID.TryParse(id,out key))
  5312. {
  5313. ScenePresence presence = World.GetScenePresence(key);
  5314. if (presence != null)
  5315. {
  5316. return presence.ControllingClient.Name;
  5317. //return presence.Name;
  5318. }
  5319. if (World.GetSceneObjectPart(key) != null)
  5320. {
  5321. return World.GetSceneObjectPart(key).Name;
  5322. }
  5323. }
  5324. return String.Empty;
  5325. }
  5326. public void llSetTextureAnim(int mode, int face, int sizex, int sizey, double start, double length, double rate)
  5327. {
  5328. m_host.AddScriptLPS(1);
  5329. SetTextureAnim(m_host, mode, face, sizex, sizey, start, length, rate);
  5330. }
  5331. public void llSetLinkTextureAnim(int linknumber, int mode, int face, int sizex, int sizey, double start, double length, double rate)
  5332. {
  5333. m_host.AddScriptLPS(1);
  5334. List<SceneObjectPart> parts = GetLinkParts(linknumber);
  5335. foreach (SceneObjectPart part in parts)
  5336. {
  5337. SetTextureAnim(part, mode, face, sizex, sizey, start, length, rate);
  5338. }
  5339. }
  5340. private void SetTextureAnim(SceneObjectPart part, int mode, int face, int sizex, int sizey, double start, double length, double rate)
  5341. {
  5342. Primitive.TextureAnimation pTexAnim = new Primitive.TextureAnimation();
  5343. pTexAnim.Flags = (Primitive.TextureAnimMode)mode;
  5344. //ALL_SIDES
  5345. if (face == ScriptBaseClass.ALL_SIDES)
  5346. face = 255;
  5347. pTexAnim.Face = (uint)face;
  5348. pTexAnim.Length = (float)length;
  5349. pTexAnim.Rate = (float)rate;
  5350. pTexAnim.SizeX = (uint)sizex;
  5351. pTexAnim.SizeY = (uint)sizey;
  5352. pTexAnim.Start = (float)start;
  5353. part.AddTextureAnimation(pTexAnim);
  5354. part.SendFullUpdateToAllClients();
  5355. part.ParentGroup.HasGroupChanged = true;
  5356. }
  5357. public void llTriggerSoundLimited(string sound, double volume, LSL_Vector top_north_east,
  5358. LSL_Vector bottom_south_west)
  5359. {
  5360. m_host.AddScriptLPS(1);
  5361. if (m_SoundModule != null)
  5362. {
  5363. m_SoundModule.TriggerSoundLimited(m_host.UUID,
  5364. ScriptUtils.GetAssetIdFromKeyOrItemName(m_host, sound, AssetType.Sound), volume,
  5365. bottom_south_west, top_north_east);
  5366. }
  5367. }
  5368. public void llEjectFromLand(string pest)
  5369. {
  5370. m_host.AddScriptLPS(1);
  5371. UUID agentID = new UUID();
  5372. if (UUID.TryParse(pest, out agentID))
  5373. {
  5374. ScenePresence presence = World.GetScenePresence(agentID);
  5375. if (presence != null)
  5376. {
  5377. // agent must be over the owners land
  5378. ILandObject land = World.LandChannel.GetLandObject(presence.AbsolutePosition);
  5379. if (land == null)
  5380. return;
  5381. if (m_host.OwnerID == land.LandData.OwnerID)
  5382. {
  5383. World.TeleportClientHome(agentID, presence.ControllingClient);
  5384. }
  5385. }
  5386. }
  5387. ScriptSleep(m_sleepMsOnEjectFromLand);
  5388. }
  5389. public LSL_Integer llOverMyLand(string id)
  5390. {
  5391. m_host.AddScriptLPS(1);
  5392. UUID key = new UUID();
  5393. if (UUID.TryParse(id, out key))
  5394. {
  5395. ScenePresence presence = World.GetScenePresence(key);
  5396. if (presence != null) // object is an avatar
  5397. {
  5398. if (m_host.OwnerID == World.LandChannel.GetLandObject(presence.AbsolutePosition).LandData.OwnerID)
  5399. return 1;
  5400. }
  5401. else // object is not an avatar
  5402. {
  5403. SceneObjectPart obj = World.GetSceneObjectPart(key);
  5404. if (obj != null)
  5405. {
  5406. if (m_host.OwnerID == World.LandChannel.GetLandObject(obj.AbsolutePosition).LandData.OwnerID)
  5407. return 1;
  5408. }
  5409. }
  5410. }
  5411. return 0;
  5412. }
  5413. public LSL_String llGetLandOwnerAt(LSL_Vector pos)
  5414. {
  5415. m_host.AddScriptLPS(1);
  5416. ILandObject land = World.LandChannel.GetLandObject((float)pos.x, (float)pos.y);
  5417. if (land == null)
  5418. return UUID.Zero.ToString();
  5419. return land.LandData.OwnerID.ToString();
  5420. }
  5421. /// <summary>
  5422. /// According to http://lslwiki.net/lslwiki/wakka.php?wakka=llGetAgentSize
  5423. /// only the height of avatars vary and that says:
  5424. /// Width (x) and depth (y) are constant. (0.45m and 0.6m respectively).
  5425. /// </summary>
  5426. public LSL_Vector llGetAgentSize(string id)
  5427. {
  5428. m_host.AddScriptLPS(1);
  5429. ScenePresence avatar = World.GetScenePresence((UUID)id);
  5430. LSL_Vector agentSize;
  5431. if (avatar == null || avatar.IsChildAgent) // Fail if not in the same region
  5432. {
  5433. agentSize = ScriptBaseClass.ZERO_VECTOR;
  5434. }
  5435. else
  5436. {
  5437. agentSize = GetAgentSize(avatar);
  5438. }
  5439. return agentSize;
  5440. }
  5441. public LSL_Integer llSameGroup(string agent)
  5442. {
  5443. m_host.AddScriptLPS(1);
  5444. UUID agentId = new UUID();
  5445. if (!UUID.TryParse(agent, out agentId))
  5446. return new LSL_Integer(0);
  5447. ScenePresence presence = World.GetScenePresence(agentId);
  5448. if (presence == null || presence.IsChildAgent) // Return flase for child agents
  5449. return new LSL_Integer(0);
  5450. IClientAPI client = presence.ControllingClient;
  5451. if (m_host.GroupID == client.ActiveGroupId)
  5452. return new LSL_Integer(1);
  5453. else
  5454. return new LSL_Integer(0);
  5455. }
  5456. public void llUnSit(string id)
  5457. {
  5458. m_host.AddScriptLPS(1);
  5459. UUID key = new UUID();
  5460. if (UUID.TryParse(id, out key))
  5461. {
  5462. ScenePresence av = World.GetScenePresence(key);
  5463. List<ScenePresence> sittingAvatars = m_host.ParentGroup.GetSittingAvatars();
  5464. if (av != null)
  5465. {
  5466. if (sittingAvatars.Contains(av))
  5467. {
  5468. // if the avatar is sitting on this object, then
  5469. // we can unsit them. We don't want random scripts unsitting random people
  5470. // Lets avoid the popcorn avatar scenario.
  5471. av.StandUp();
  5472. }
  5473. else
  5474. {
  5475. // If the object owner also owns the parcel
  5476. // or
  5477. // if the land is group owned and the object is group owned by the same group
  5478. // or
  5479. // if the object is owned by a person with estate access.
  5480. ILandObject parcel = World.LandChannel.GetLandObject(av.AbsolutePosition);
  5481. if (parcel != null)
  5482. {
  5483. if (m_host.OwnerID == parcel.LandData.OwnerID ||
  5484. (m_host.OwnerID == m_host.GroupID && m_host.GroupID == parcel.LandData.GroupID
  5485. && parcel.LandData.IsGroupOwned) || World.Permissions.IsGod(m_host.OwnerID))
  5486. {
  5487. av.StandUp();
  5488. }
  5489. }
  5490. }
  5491. }
  5492. }
  5493. }
  5494. public LSL_Vector llGroundSlope(LSL_Vector offset)
  5495. {
  5496. m_host.AddScriptLPS(1);
  5497. //Get the slope normal. This gives us the equation of the plane tangent to the slope.
  5498. LSL_Vector vsn = llGroundNormal(offset);
  5499. //Plug the x,y coordinates of the slope normal into the equation of the plane to get
  5500. //the height of that point on the plane. The resulting vector gives the slope.
  5501. Vector3 vsl = vsn;
  5502. vsl.Z = (float)(((vsn.x * vsn.x) + (vsn.y * vsn.y)) / (-1 * vsn.z));
  5503. vsl.Normalize();
  5504. //Normalization might be overkill here
  5505. vsn.x = vsl.X;
  5506. vsn.y = vsl.Y;
  5507. vsn.z = vsl.Z;
  5508. return vsn;
  5509. }
  5510. public LSL_Vector llGroundNormal(LSL_Vector offset)
  5511. {
  5512. m_host.AddScriptLPS(1);
  5513. Vector3 pos = m_host.GetWorldPosition() + (Vector3)offset;
  5514. // Clamp to valid position
  5515. if (pos.X < 0)
  5516. pos.X = 0;
  5517. else if (pos.X >= World.Heightmap.Width)
  5518. pos.X = World.Heightmap.Width - 1;
  5519. if (pos.Y < 0)
  5520. pos.Y = 0;
  5521. else if (pos.Y >= World.Heightmap.Height)
  5522. pos.Y = World.Heightmap.Height - 1;
  5523. //Find two points in addition to the position to define a plane
  5524. Vector3 p0 = new Vector3(pos.X, pos.Y,
  5525. (float)World.Heightmap[(int)pos.X, (int)pos.Y]);
  5526. Vector3 p1 = new Vector3();
  5527. Vector3 p2 = new Vector3();
  5528. if ((pos.X + 1.0f) >= World.Heightmap.Width)
  5529. p1 = new Vector3(pos.X + 1.0f, pos.Y,
  5530. (float)World.Heightmap[(int)pos.X, (int)pos.Y]);
  5531. else
  5532. p1 = new Vector3(pos.X + 1.0f, pos.Y,
  5533. (float)World.Heightmap[(int)(pos.X + 1.0f), (int)pos.Y]);
  5534. if ((pos.Y + 1.0f) >= World.Heightmap.Height)
  5535. p2 = new Vector3(pos.X, pos.Y + 1.0f,
  5536. (float)World.Heightmap[(int)pos.X, (int)pos.Y]);
  5537. else
  5538. p2 = new Vector3(pos.X, pos.Y + 1.0f,
  5539. (float)World.Heightmap[(int)pos.X, (int)(pos.Y + 1.0f)]);
  5540. //Find normalized vectors from p0 to p1 and p0 to p2
  5541. Vector3 v0 = new Vector3(p1.X - p0.X, p1.Y - p0.Y, p1.Z - p0.Z);
  5542. Vector3 v1 = new Vector3(p2.X - p0.X, p2.Y - p0.Y, p2.Z - p0.Z);
  5543. v0.Normalize();
  5544. v1.Normalize();
  5545. //Find the cross product of the vectors (the slope normal).
  5546. Vector3 vsn = new Vector3();
  5547. vsn.X = (v0.Y * v1.Z) - (v0.Z * v1.Y);
  5548. vsn.Y = (v0.Z * v1.X) - (v0.X * v1.Z);
  5549. vsn.Z = (v0.X * v1.Y) - (v0.Y * v1.X);
  5550. vsn.Normalize();
  5551. //I believe the crossproduct of two normalized vectors is a normalized vector so
  5552. //this normalization may be overkill
  5553. return new LSL_Vector(vsn);
  5554. }
  5555. public LSL_Vector llGroundContour(LSL_Vector offset)
  5556. {
  5557. m_host.AddScriptLPS(1);
  5558. LSL_Vector x = llGroundSlope(offset);
  5559. return new LSL_Vector(-x.y, x.x, 0.0);
  5560. }
  5561. public LSL_Integer llGetAttached()
  5562. {
  5563. m_host.AddScriptLPS(1);
  5564. return m_host.ParentGroup.AttachmentPoint;
  5565. }
  5566. public virtual LSL_Integer llGetFreeMemory()
  5567. {
  5568. m_host.AddScriptLPS(1);
  5569. // Make scripts designed for Mono happy
  5570. return 65536;
  5571. }
  5572. public LSL_Integer llGetFreeURLs()
  5573. {
  5574. m_host.AddScriptLPS(1);
  5575. if (m_UrlModule != null)
  5576. return new LSL_Integer(m_UrlModule.GetFreeUrls());
  5577. return new LSL_Integer(0);
  5578. }
  5579. public LSL_String llGetRegionName()
  5580. {
  5581. m_host.AddScriptLPS(1);
  5582. return World.RegionInfo.RegionName;
  5583. }
  5584. public LSL_Float llGetRegionTimeDilation()
  5585. {
  5586. m_host.AddScriptLPS(1);
  5587. return (double)World.TimeDilation;
  5588. }
  5589. /// <summary>
  5590. /// Returns the value reported in the client Statistics window
  5591. /// </summary>
  5592. public LSL_Float llGetRegionFPS()
  5593. {
  5594. m_host.AddScriptLPS(1);
  5595. return World.StatsReporter.LastReportedSimFPS;
  5596. }
  5597. /* particle system rules should be coming into this routine as doubles, that is
  5598. rule[0] should be an integer from this list and rule[1] should be the arg
  5599. for the same integer. wiki.secondlife.com has most of this mapping, but some
  5600. came from http://www.caligari-designs.com/p4u2
  5601. We iterate through the list for 'Count' elements, incrementing by two for each
  5602. iteration and set the members of Primitive.ParticleSystem, one at a time.
  5603. */
  5604. public enum PrimitiveRule : int
  5605. {
  5606. PSYS_PART_FLAGS = 0,
  5607. PSYS_PART_START_COLOR = 1,
  5608. PSYS_PART_START_ALPHA = 2,
  5609. PSYS_PART_END_COLOR = 3,
  5610. PSYS_PART_END_ALPHA = 4,
  5611. PSYS_PART_START_SCALE = 5,
  5612. PSYS_PART_END_SCALE = 6,
  5613. PSYS_PART_MAX_AGE = 7,
  5614. PSYS_SRC_ACCEL = 8,
  5615. PSYS_SRC_PATTERN = 9,
  5616. PSYS_SRC_INNERANGLE = 10,
  5617. PSYS_SRC_OUTERANGLE = 11,
  5618. PSYS_SRC_TEXTURE = 12,
  5619. PSYS_SRC_BURST_RATE = 13,
  5620. PSYS_SRC_BURST_PART_COUNT = 15,
  5621. PSYS_SRC_BURST_RADIUS = 16,
  5622. PSYS_SRC_BURST_SPEED_MIN = 17,
  5623. PSYS_SRC_BURST_SPEED_MAX = 18,
  5624. PSYS_SRC_MAX_AGE = 19,
  5625. PSYS_SRC_TARGET_KEY = 20,
  5626. PSYS_SRC_OMEGA = 21,
  5627. PSYS_SRC_ANGLE_BEGIN = 22,
  5628. PSYS_SRC_ANGLE_END = 23,
  5629. PSYS_PART_BLEND_FUNC_SOURCE = 24,
  5630. PSYS_PART_BLEND_FUNC_DEST = 25,
  5631. PSYS_PART_START_GLOW = 26,
  5632. PSYS_PART_END_GLOW = 27
  5633. }
  5634. internal Primitive.ParticleSystem.ParticleDataFlags ConvertUINTtoFlags(uint flags)
  5635. {
  5636. Primitive.ParticleSystem.ParticleDataFlags returnval = Primitive.ParticleSystem.ParticleDataFlags.None;
  5637. return returnval;
  5638. }
  5639. protected Primitive.ParticleSystem getNewParticleSystemWithSLDefaultValues()
  5640. {
  5641. Primitive.ParticleSystem ps = new Primitive.ParticleSystem();
  5642. // TODO find out about the other defaults and add them here
  5643. ps.PartStartColor = new Color4(1.0f, 1.0f, 1.0f, 1.0f);
  5644. ps.PartEndColor = new Color4(1.0f, 1.0f, 1.0f, 1.0f);
  5645. ps.PartStartScaleX = 1.0f;
  5646. ps.PartStartScaleY = 1.0f;
  5647. ps.PartEndScaleX = 1.0f;
  5648. ps.PartEndScaleY = 1.0f;
  5649. ps.BurstSpeedMin = 1.0f;
  5650. ps.BurstSpeedMax = 1.0f;
  5651. ps.BurstRate = 0.1f;
  5652. ps.PartMaxAge = 10.0f;
  5653. ps.BurstPartCount = 1;
  5654. ps.BlendFuncSource = ScriptBaseClass.PSYS_PART_BF_SOURCE_ALPHA;
  5655. ps.BlendFuncDest = ScriptBaseClass.PSYS_PART_BF_ONE_MINUS_SOURCE_ALPHA;
  5656. ps.PartStartGlow = 0.0f;
  5657. ps.PartEndGlow = 0.0f;
  5658. return ps;
  5659. }
  5660. public void llLinkParticleSystem(int linknumber, LSL_List rules)
  5661. {
  5662. m_host.AddScriptLPS(1);
  5663. List<SceneObjectPart> parts = GetLinkParts(linknumber);
  5664. foreach (SceneObjectPart part in parts)
  5665. {
  5666. SetParticleSystem(part, rules, "llLinkParticleSystem");
  5667. }
  5668. }
  5669. public void llParticleSystem(LSL_List rules)
  5670. {
  5671. m_host.AddScriptLPS(1);
  5672. SetParticleSystem(m_host, rules, "llParticleSystem");
  5673. }
  5674. private void SetParticleSystem(SceneObjectPart part, LSL_List rules, string originFunc)
  5675. {
  5676. if (rules.Length == 0)
  5677. {
  5678. part.RemoveParticleSystem();
  5679. part.ParentGroup.HasGroupChanged = true;
  5680. }
  5681. else
  5682. {
  5683. Primitive.ParticleSystem prules = getNewParticleSystemWithSLDefaultValues();
  5684. LSL_Vector tempv = new LSL_Vector();
  5685. float tempf = 0;
  5686. int tmpi = 0;
  5687. for (int i = 0; i < rules.Length; i += 2)
  5688. {
  5689. int psystype;
  5690. try
  5691. {
  5692. psystype = rules.GetLSLIntegerItem(i);
  5693. }
  5694. catch (InvalidCastException)
  5695. {
  5696. Error(originFunc, string.Format("Error running particle system params index #{0}: particle system parameter type must be integer", i));
  5697. return;
  5698. }
  5699. switch (psystype)
  5700. {
  5701. case (int)ScriptBaseClass.PSYS_PART_FLAGS:
  5702. try
  5703. {
  5704. prules.PartDataFlags = (Primitive.ParticleSystem.ParticleDataFlags)(uint)rules.GetLSLIntegerItem(i + 1);
  5705. }
  5706. catch(InvalidCastException)
  5707. {
  5708. Error(originFunc, string.Format("Error running rule PSYS_PART_FLAGS: arg #{0} - parameter 1 must be integer", i + 1));
  5709. return;
  5710. }
  5711. break;
  5712. case (int)ScriptBaseClass.PSYS_PART_START_COLOR:
  5713. try
  5714. {
  5715. tempv = rules.GetVector3Item(i + 1);
  5716. }
  5717. catch(InvalidCastException)
  5718. {
  5719. Error(originFunc, string.Format("Error running rule PSYS_PART_START_COLOR: arg #{0} - parameter 1 must be vector", i + 1));
  5720. return;
  5721. }
  5722. prules.PartStartColor.R = (float)tempv.x;
  5723. prules.PartStartColor.G = (float)tempv.y;
  5724. prules.PartStartColor.B = (float)tempv.z;
  5725. break;
  5726. case (int)ScriptBaseClass.PSYS_PART_START_ALPHA:
  5727. try
  5728. {
  5729. tempf = (float)rules.GetLSLFloatItem(i + 1);
  5730. }
  5731. catch(InvalidCastException)
  5732. {
  5733. Error(originFunc, string.Format("Error running rule PSYS_PART_START_ALPHA: arg #{0} - parameter 1 must be float", i + 1));
  5734. return;
  5735. }
  5736. prules.PartStartColor.A = tempf;
  5737. break;
  5738. case (int)ScriptBaseClass.PSYS_PART_END_COLOR:
  5739. try
  5740. {
  5741. tempv = rules.GetVector3Item(i + 1);
  5742. }
  5743. catch(InvalidCastException)
  5744. {
  5745. Error(originFunc, string.Format("Error running rule PSYS_PART_END_COLOR: arg #{0} - parameter 1 must be vector", i + 1));
  5746. return;
  5747. }
  5748. prules.PartEndColor.R = (float)tempv.x;
  5749. prules.PartEndColor.G = (float)tempv.y;
  5750. prules.PartEndColor.B = (float)tempv.z;
  5751. break;
  5752. case (int)ScriptBaseClass.PSYS_PART_END_ALPHA:
  5753. try
  5754. {
  5755. tempf = (float)rules.GetLSLFloatItem(i + 1);
  5756. }
  5757. catch(InvalidCastException)
  5758. {
  5759. Error(originFunc, string.Format("Error running rule PSYS_PART_END_ALPHA: arg #{0} - parameter 1 must be float", i + 1));
  5760. return;
  5761. }
  5762. prules.PartEndColor.A = tempf;
  5763. break;
  5764. case (int)ScriptBaseClass.PSYS_PART_START_SCALE:
  5765. try
  5766. {
  5767. tempv = rules.GetVector3Item(i + 1);
  5768. }
  5769. catch(InvalidCastException)
  5770. {
  5771. Error(originFunc, string.Format("Error running rule PSYS_PART_START_SCALE: arg #{0} - parameter 1 must be vector", i + 1));
  5772. return;
  5773. }
  5774. prules.PartStartScaleX = validParticleScale((float)tempv.x);
  5775. prules.PartStartScaleY = validParticleScale((float)tempv.y);
  5776. break;
  5777. case (int)ScriptBaseClass.PSYS_PART_END_SCALE:
  5778. try
  5779. {
  5780. tempv = rules.GetVector3Item(i + 1);
  5781. }
  5782. catch(InvalidCastException)
  5783. {
  5784. Error(originFunc, string.Format("Error running rule PSYS_PART_END_SCALE: arg #{0} - parameter 1 must be vector", i + 1));
  5785. return;
  5786. }
  5787. prules.PartEndScaleX = validParticleScale((float)tempv.x);
  5788. prules.PartEndScaleY = validParticleScale((float)tempv.y);
  5789. break;
  5790. case (int)ScriptBaseClass.PSYS_PART_MAX_AGE:
  5791. try
  5792. {
  5793. tempf = (float)rules.GetLSLFloatItem(i + 1);
  5794. }
  5795. catch(InvalidCastException)
  5796. {
  5797. Error(originFunc, string.Format("Error running rule PSYS_PART_MAX_AGE: arg #{0} - parameter 1 must be float", i + 1));
  5798. return;
  5799. }
  5800. prules.PartMaxAge = tempf;
  5801. break;
  5802. case (int)ScriptBaseClass.PSYS_SRC_ACCEL:
  5803. try
  5804. {
  5805. tempv = rules.GetVector3Item(i + 1);
  5806. }
  5807. catch(InvalidCastException)
  5808. {
  5809. Error(originFunc, string.Format("Error running rule PSYS_SRC_ACCEL: arg #{0} - parameter 1 must be vector", i + 1));
  5810. return;
  5811. }
  5812. prules.PartAcceleration.X = (float)tempv.x;
  5813. prules.PartAcceleration.Y = (float)tempv.y;
  5814. prules.PartAcceleration.Z = (float)tempv.z;
  5815. break;
  5816. case (int)ScriptBaseClass.PSYS_SRC_PATTERN:
  5817. try
  5818. {
  5819. tmpi = (int)rules.GetLSLIntegerItem(i + 1);
  5820. }
  5821. catch(InvalidCastException)
  5822. {
  5823. Error(originFunc, string.Format("Error running rule PSYS_SRC_PATTERN: arg #{0} - parameter 1 must be integer", i + 1));
  5824. return;
  5825. }
  5826. prules.Pattern = (Primitive.ParticleSystem.SourcePattern)tmpi;
  5827. break;
  5828. // PSYS_SRC_INNERANGLE and PSYS_SRC_ANGLE_BEGIN use the same variables. The
  5829. // PSYS_SRC_OUTERANGLE and PSYS_SRC_ANGLE_END also use the same variable. The
  5830. // client tells the difference between the two by looking at the 0x02 bit in
  5831. // the PartFlags variable.
  5832. case (int)ScriptBaseClass.PSYS_SRC_INNERANGLE:
  5833. try
  5834. {
  5835. tempf = (float)rules.GetLSLFloatItem(i + 1);
  5836. }
  5837. catch(InvalidCastException)
  5838. {
  5839. Error(originFunc, string.Format("Error running rule PSYS_SRC_INNERANGLE: arg #{0} - parameter 1 must be float", i + 1));
  5840. return;
  5841. }
  5842. prules.InnerAngle = (float)tempf;
  5843. prules.PartFlags &= 0xFFFFFFFD; // Make sure new angle format is off.
  5844. break;
  5845. case (int)ScriptBaseClass.PSYS_SRC_OUTERANGLE:
  5846. try
  5847. {
  5848. tempf = (float)rules.GetLSLFloatItem(i + 1);
  5849. }
  5850. catch(InvalidCastException)
  5851. {
  5852. Error(originFunc, string.Format("Error running rule PSYS_SRC_OUTERANGLE: arg #{0} - parameter 1 must be float", i + 1));
  5853. return;
  5854. }
  5855. prules.OuterAngle = (float)tempf;
  5856. prules.PartFlags &= 0xFFFFFFFD; // Make sure new angle format is off.
  5857. break;
  5858. case (int)ScriptBaseClass.PSYS_PART_BLEND_FUNC_SOURCE:
  5859. try
  5860. {
  5861. tmpi = (int)rules.GetLSLIntegerItem(i + 1);
  5862. }
  5863. catch(InvalidCastException)
  5864. {
  5865. Error(originFunc, string.Format("Error running rule PSYS_PART_BLEND_FUNC_SOURCE: arg #{0} - parameter 1 must be integer", i + 1));
  5866. return;
  5867. }
  5868. prules.BlendFuncSource = (byte)tmpi;
  5869. break;
  5870. case (int)ScriptBaseClass.PSYS_PART_BLEND_FUNC_DEST:
  5871. try
  5872. {
  5873. tmpi = (int)rules.GetLSLIntegerItem(i + 1);
  5874. }
  5875. catch(InvalidCastException)
  5876. {
  5877. Error(originFunc, string.Format("Error running rule PSYS_PART_BLEND_FUNC_DEST: arg #{0} - parameter 1 must be integer", i + 1));
  5878. return;
  5879. }
  5880. prules.BlendFuncDest = (byte)tmpi;
  5881. break;
  5882. case (int)ScriptBaseClass.PSYS_PART_START_GLOW:
  5883. try
  5884. {
  5885. tempf = (float)rules.GetLSLFloatItem(i + 1);
  5886. }
  5887. catch(InvalidCastException)
  5888. {
  5889. Error(originFunc, string.Format("Error running rule PSYS_PART_START_GLOW: arg #{0} - parameter 1 must be float", i + 1));
  5890. return;
  5891. }
  5892. prules.PartStartGlow = (float)tempf;
  5893. break;
  5894. case (int)ScriptBaseClass.PSYS_PART_END_GLOW:
  5895. try
  5896. {
  5897. tempf = (float)rules.GetLSLFloatItem(i + 1);
  5898. }
  5899. catch(InvalidCastException)
  5900. {
  5901. Error(originFunc, string.Format("Error running rule PSYS_PART_END_GLOW: arg #{0} - parameter 1 must be float", i + 1));
  5902. return;
  5903. }
  5904. prules.PartEndGlow = (float)tempf;
  5905. break;
  5906. case (int)ScriptBaseClass.PSYS_SRC_TEXTURE:
  5907. try
  5908. {
  5909. prules.Texture = ScriptUtils.GetAssetIdFromKeyOrItemName(m_host, rules.GetLSLStringItem(i + 1));
  5910. }
  5911. catch(InvalidCastException)
  5912. {
  5913. Error(originFunc, string.Format("Error running rule PSYS_SRC_TEXTURE: arg #{0} - parameter 1 must be string or key", i + 1));
  5914. return;
  5915. }
  5916. break;
  5917. case (int)ScriptBaseClass.PSYS_SRC_BURST_RATE:
  5918. try
  5919. {
  5920. tempf = (float)rules.GetLSLFloatItem(i + 1);
  5921. }
  5922. catch(InvalidCastException)
  5923. {
  5924. Error(originFunc, string.Format("Error running rule PSYS_SRC_BURST_RATE: arg #{0} - parameter 1 must be float", i + 1));
  5925. return;
  5926. }
  5927. prules.BurstRate = (float)tempf;
  5928. break;
  5929. case (int)ScriptBaseClass.PSYS_SRC_BURST_PART_COUNT:
  5930. try
  5931. {
  5932. prules.BurstPartCount = (byte)(int)rules.GetLSLIntegerItem(i + 1);
  5933. }
  5934. catch(InvalidCastException)
  5935. {
  5936. Error(originFunc, string.Format("Error running rule PSYS_SRC_BURST_PART_COUNT: arg #{0} - parameter 1 must be integer", i + 1));
  5937. return;
  5938. }
  5939. break;
  5940. case (int)ScriptBaseClass.PSYS_SRC_BURST_RADIUS:
  5941. try
  5942. {
  5943. tempf = (float)rules.GetLSLFloatItem(i + 1);
  5944. }
  5945. catch(InvalidCastException)
  5946. {
  5947. Error(originFunc, string.Format("Error running rule PSYS_SRC_BURST_RADIUS: arg #{0} - parameter 1 must be float", i + 1));
  5948. return;
  5949. }
  5950. prules.BurstRadius = (float)tempf;
  5951. break;
  5952. case (int)ScriptBaseClass.PSYS_SRC_BURST_SPEED_MIN:
  5953. try
  5954. {
  5955. tempf = (float)rules.GetLSLFloatItem(i + 1);
  5956. }
  5957. catch(InvalidCastException)
  5958. {
  5959. Error(originFunc, string.Format("Error running rule PSYS_SRC_BURST_SPEED_MIN: arg #{0} - parameter 1 must be float", i + 1));
  5960. return;
  5961. }
  5962. prules.BurstSpeedMin = (float)tempf;
  5963. break;
  5964. case (int)ScriptBaseClass.PSYS_SRC_BURST_SPEED_MAX:
  5965. try
  5966. {
  5967. tempf = (float)rules.GetLSLFloatItem(i + 1);
  5968. }
  5969. catch(InvalidCastException)
  5970. {
  5971. Error(originFunc, string.Format("Error running rule PSYS_SRC_BURST_SPEED_MAX: arg #{0} - parameter 1 must be float", i + 1));
  5972. return;
  5973. }
  5974. prules.BurstSpeedMax = (float)tempf;
  5975. break;
  5976. case (int)ScriptBaseClass.PSYS_SRC_MAX_AGE:
  5977. try
  5978. {
  5979. tempf = (float)rules.GetLSLFloatItem(i + 1);
  5980. }
  5981. catch(InvalidCastException)
  5982. {
  5983. Error(originFunc, string.Format("Error running rule PSYS_SRC_MAX_AGE: arg #{0} - parameter 1 must be float", i + 1));
  5984. return;
  5985. }
  5986. prules.MaxAge = (float)tempf;
  5987. break;
  5988. case (int)ScriptBaseClass.PSYS_SRC_TARGET_KEY:
  5989. UUID key = UUID.Zero;
  5990. if (UUID.TryParse(rules.Data[i + 1].ToString(), out key))
  5991. {
  5992. prules.Target = key;
  5993. }
  5994. else
  5995. {
  5996. prules.Target = part.UUID;
  5997. }
  5998. break;
  5999. case (int)ScriptBaseClass.PSYS_SRC_OMEGA:
  6000. // AL: This is an assumption, since it is the only thing that would match.
  6001. try
  6002. {
  6003. tempv = rules.GetVector3Item(i + 1);
  6004. }
  6005. catch(InvalidCastException)
  6006. {
  6007. Error(originFunc, string.Format("Error running rule PSYS_SRC_OMEGA: arg #{0} - parameter 1 must be vector", i + 1));
  6008. return;
  6009. }
  6010. prules.AngularVelocity.X = (float)tempv.x;
  6011. prules.AngularVelocity.Y = (float)tempv.y;
  6012. prules.AngularVelocity.Z = (float)tempv.z;
  6013. break;
  6014. case (int)ScriptBaseClass.PSYS_SRC_ANGLE_BEGIN:
  6015. try
  6016. {
  6017. tempf = (float)rules.GetLSLFloatItem(i + 1);
  6018. }
  6019. catch(InvalidCastException)
  6020. {
  6021. Error(originFunc, string.Format("Error running rule PSYS_SRC_ANGLE_BEGIN: arg #{0} - parameter 1 must be float", i + 1));
  6022. return;
  6023. }
  6024. prules.InnerAngle = (float)tempf;
  6025. prules.PartFlags |= 0x02; // Set new angle format.
  6026. break;
  6027. case (int)ScriptBaseClass.PSYS_SRC_ANGLE_END:
  6028. try
  6029. {
  6030. tempf = (float)rules.GetLSLFloatItem(i + 1);
  6031. }
  6032. catch (InvalidCastException)
  6033. {
  6034. Error(originFunc, string.Format("Error running rule PSYS_SRC_ANGLE_END: arg #{0} - parameter 1 must be float", i + 1));
  6035. return;
  6036. }
  6037. prules.OuterAngle = (float)tempf;
  6038. prules.PartFlags |= 0x02; // Set new angle format.
  6039. break;
  6040. }
  6041. }
  6042. prules.CRC = 1;
  6043. part.AddNewParticleSystem(prules);
  6044. part.ParentGroup.HasGroupChanged = true;
  6045. }
  6046. part.SendFullUpdateToAllClients();
  6047. }
  6048. private float validParticleScale(float value)
  6049. {
  6050. if (value > 4.0f) return 4.0f;
  6051. return value;
  6052. }
  6053. public void llGroundRepel(double height, int water, double tau)
  6054. {
  6055. m_host.AddScriptLPS(1);
  6056. if (m_host.PhysActor != null)
  6057. {
  6058. float ground = (float)llGround(new LSL_Types.Vector3(0, 0, 0));
  6059. float waterLevel = (float)llWater(new LSL_Types.Vector3(0, 0, 0));
  6060. PIDHoverType hoverType = PIDHoverType.Ground;
  6061. if (water != 0)
  6062. {
  6063. hoverType = PIDHoverType.GroundAndWater;
  6064. if (ground < waterLevel)
  6065. height += waterLevel;
  6066. else
  6067. height += ground;
  6068. }
  6069. else
  6070. {
  6071. height += ground;
  6072. }
  6073. m_host.SetHoverHeight((float)height, hoverType, (float)tau);
  6074. }
  6075. }
  6076. public void llGiveInventoryList(string destination, string category, LSL_List inventory)
  6077. {
  6078. m_host.AddScriptLPS(1);
  6079. UUID destID;
  6080. if (!UUID.TryParse(destination, out destID))
  6081. return;
  6082. List<UUID> itemList = new List<UUID>();
  6083. foreach (Object item in inventory.Data)
  6084. {
  6085. string rawItemString = item.ToString();
  6086. UUID itemID;
  6087. if (UUID.TryParse(rawItemString, out itemID))
  6088. {
  6089. itemList.Add(itemID);
  6090. }
  6091. else
  6092. {
  6093. TaskInventoryItem taskItem = m_host.Inventory.GetInventoryItem(rawItemString);
  6094. if (taskItem != null)
  6095. itemList.Add(taskItem.ItemID);
  6096. }
  6097. }
  6098. if (itemList.Count == 0)
  6099. return;
  6100. UUID folderID = m_ScriptEngine.World.MoveTaskInventoryItems(destID, category, m_host, itemList);
  6101. if (folderID == UUID.Zero)
  6102. return;
  6103. if (m_TransferModule != null)
  6104. {
  6105. byte[] bucket = new byte[] { (byte)AssetType.Folder };
  6106. Vector3 pos = m_host.AbsolutePosition;
  6107. GridInstantMessage msg = new GridInstantMessage(World,
  6108. m_host.OwnerID, m_host.Name, destID,
  6109. (byte)InstantMessageDialog.TaskInventoryOffered,
  6110. false, string.Format("'{0}'", category),
  6111. // We won't go so far as to add a SLURL, but this is the format used by LL as of 2012-10-06
  6112. // false, string.Format("'{0}' ( http://slurl.com/secondlife/{1}/{2}/{3}/{4} )", category, World.Name, (int)pos.X, (int)pos.Y, (int)pos.Z),
  6113. folderID, false, pos,
  6114. bucket, false);
  6115. m_TransferModule.SendInstantMessage(msg, delegate(bool success) {});
  6116. }
  6117. }
  6118. public void llSetVehicleType(int type)
  6119. {
  6120. m_host.AddScriptLPS(1);
  6121. if (!m_host.ParentGroup.IsDeleted)
  6122. {
  6123. m_host.ParentGroup.RootPart.SetVehicleType(type);
  6124. }
  6125. }
  6126. //CFK 9/28: Most, but not all of the underlying plumbing between here and the physics modules is in
  6127. //CFK 9/28: so these are not complete yet.
  6128. public void llSetVehicleFloatParam(int param, LSL_Float value)
  6129. {
  6130. m_host.AddScriptLPS(1);
  6131. if (!m_host.ParentGroup.IsDeleted)
  6132. {
  6133. m_host.ParentGroup.RootPart.SetVehicleFloatParam(param, (float)value);
  6134. }
  6135. }
  6136. //CFK 9/28: Most, but not all of the underlying plumbing between here and the physics modules is in
  6137. //CFK 9/28: so these are not complete yet.
  6138. public void llSetVehicleVectorParam(int param, LSL_Vector vec)
  6139. {
  6140. m_host.AddScriptLPS(1);
  6141. if (!m_host.ParentGroup.IsDeleted)
  6142. {
  6143. m_host.ParentGroup.RootPart.SetVehicleVectorParam(param, vec);
  6144. }
  6145. }
  6146. //CFK 9/28: Most, but not all of the underlying plumbing between here and the physics modules is in
  6147. //CFK 9/28: so these are not complete yet.
  6148. public void llSetVehicleRotationParam(int param, LSL_Rotation rot)
  6149. {
  6150. m_host.AddScriptLPS(1);
  6151. if (!m_host.ParentGroup.IsDeleted)
  6152. {
  6153. m_host.ParentGroup.RootPart.SetVehicleRotationParam(param, rot);
  6154. }
  6155. }
  6156. public void llSetVehicleFlags(int flags)
  6157. {
  6158. m_host.AddScriptLPS(1);
  6159. if (!m_host.ParentGroup.IsDeleted)
  6160. {
  6161. m_host.ParentGroup.RootPart.SetVehicleFlags(flags, false);
  6162. }
  6163. }
  6164. public void llRemoveVehicleFlags(int flags)
  6165. {
  6166. m_host.AddScriptLPS(1);
  6167. if (!m_host.ParentGroup.IsDeleted)
  6168. {
  6169. m_host.ParentGroup.RootPart.SetVehicleFlags(flags, true);
  6170. }
  6171. }
  6172. protected void SitTarget(SceneObjectPart part, LSL_Vector offset, LSL_Rotation rot)
  6173. {
  6174. part.SitTargetPosition = offset;
  6175. part.SitTargetOrientation = rot;
  6176. part.ParentGroup.HasGroupChanged = true;
  6177. }
  6178. public void llSitTarget(LSL_Vector offset, LSL_Rotation rot)
  6179. {
  6180. m_host.AddScriptLPS(1);
  6181. SitTarget(m_host, offset, rot);
  6182. }
  6183. public void llLinkSitTarget(LSL_Integer link, LSL_Vector offset, LSL_Rotation rot)
  6184. {
  6185. m_host.AddScriptLPS(1);
  6186. if (link == ScriptBaseClass.LINK_ROOT)
  6187. SitTarget(m_host.ParentGroup.RootPart, offset, rot);
  6188. else if (link == ScriptBaseClass.LINK_THIS)
  6189. SitTarget(m_host, offset, rot);
  6190. else
  6191. {
  6192. SceneObjectPart part = m_host.ParentGroup.GetLinkNumPart(link);
  6193. if (null != part)
  6194. {
  6195. SitTarget(part, offset, rot);
  6196. }
  6197. }
  6198. }
  6199. public LSL_String llAvatarOnSitTarget()
  6200. {
  6201. m_host.AddScriptLPS(1);
  6202. return m_host.SitTargetAvatar.ToString();
  6203. }
  6204. // http://wiki.secondlife.com/wiki/LlAvatarOnLinkSitTarget
  6205. public LSL_String llAvatarOnLinkSitTarget(int linknum)
  6206. {
  6207. m_host.AddScriptLPS(1);
  6208. if(linknum == ScriptBaseClass.LINK_SET ||
  6209. linknum == ScriptBaseClass.LINK_ALL_CHILDREN ||
  6210. linknum == ScriptBaseClass.LINK_ALL_OTHERS) return UUID.Zero.ToString();
  6211. List<SceneObjectPart> parts = GetLinkParts(linknum);
  6212. if (parts.Count == 0) return UUID.Zero.ToString();
  6213. return parts[0].SitTargetAvatar.ToString();
  6214. }
  6215. public void llAddToLandPassList(string avatar, double hours)
  6216. {
  6217. m_host.AddScriptLPS(1);
  6218. UUID key;
  6219. ILandObject land = World.LandChannel.GetLandObject(m_host.AbsolutePosition);
  6220. if (World.Permissions.CanEditParcelProperties(m_host.OwnerID, land, GroupPowers.LandManageBanned))
  6221. {
  6222. int expires = 0;
  6223. if (hours != 0)
  6224. expires = Util.UnixTimeSinceEpoch() + (int)(3600.0 * hours);
  6225. if (UUID.TryParse(avatar, out key))
  6226. {
  6227. int idx = land.LandData.ParcelAccessList.FindIndex(
  6228. delegate(LandAccessEntry e)
  6229. {
  6230. if (e.AgentID == key && e.Flags == AccessList.Access)
  6231. return true;
  6232. return false;
  6233. });
  6234. if (idx != -1 && (land.LandData.ParcelAccessList[idx].Expires == 0 || (expires != 0 && expires < land.LandData.ParcelAccessList[idx].Expires)))
  6235. return;
  6236. if (idx != -1)
  6237. land.LandData.ParcelAccessList.RemoveAt(idx);
  6238. LandAccessEntry entry = new LandAccessEntry();
  6239. entry.AgentID = key;
  6240. entry.Flags = AccessList.Access;
  6241. entry.Expires = expires;
  6242. land.LandData.ParcelAccessList.Add(entry);
  6243. World.EventManager.TriggerLandObjectUpdated((uint)land.LandData.LocalID, land);
  6244. }
  6245. }
  6246. ScriptSleep(m_sleepMsOnAddToLandPassList);
  6247. }
  6248. public void llSetTouchText(string text)
  6249. {
  6250. m_host.AddScriptLPS(1);
  6251. m_host.TouchName = text;
  6252. }
  6253. public void llSetSitText(string text)
  6254. {
  6255. m_host.AddScriptLPS(1);
  6256. m_host.SitName = text;
  6257. }
  6258. public void llSetCameraEyeOffset(LSL_Vector offset)
  6259. {
  6260. m_host.AddScriptLPS(1);
  6261. m_host.SetCameraEyeOffset(offset);
  6262. if (m_host.ParentGroup.RootPart.GetCameraEyeOffset() == Vector3.Zero)
  6263. m_host.ParentGroup.RootPart.SetCameraEyeOffset(offset);
  6264. }
  6265. public void llSetCameraAtOffset(LSL_Vector offset)
  6266. {
  6267. m_host.AddScriptLPS(1);
  6268. m_host.SetCameraAtOffset(offset);
  6269. if (m_host.ParentGroup.RootPart.GetCameraAtOffset() == Vector3.Zero)
  6270. m_host.ParentGroup.RootPart.SetCameraAtOffset(offset);
  6271. }
  6272. public void llSetLinkCamera(LSL_Integer link, LSL_Vector eye, LSL_Vector at)
  6273. {
  6274. m_host.AddScriptLPS(1);
  6275. if (link == ScriptBaseClass.LINK_SET ||
  6276. link == ScriptBaseClass.LINK_ALL_CHILDREN ||
  6277. link == ScriptBaseClass.LINK_ALL_OTHERS) return;
  6278. SceneObjectPart part = null;
  6279. switch (link)
  6280. {
  6281. case ScriptBaseClass.LINK_ROOT:
  6282. part = m_host.ParentGroup.RootPart;
  6283. break;
  6284. case ScriptBaseClass.LINK_THIS:
  6285. part = m_host;
  6286. break;
  6287. default:
  6288. part = m_host.ParentGroup.GetLinkNumPart(link);
  6289. break;
  6290. }
  6291. if (null != part)
  6292. {
  6293. part.SetCameraEyeOffset(eye);
  6294. part.SetCameraAtOffset(at);
  6295. }
  6296. }
  6297. public LSL_String llDumpList2String(LSL_List src, string seperator)
  6298. {
  6299. m_host.AddScriptLPS(1);
  6300. if (src.Length == 0)
  6301. {
  6302. return String.Empty;
  6303. }
  6304. string ret = String.Empty;
  6305. foreach (object o in src.Data)
  6306. {
  6307. ret = ret + o.ToString() + seperator;
  6308. }
  6309. ret = ret.Substring(0, ret.Length - seperator.Length);
  6310. return ret;
  6311. }
  6312. public LSL_Integer llScriptDanger(LSL_Vector pos)
  6313. {
  6314. m_host.AddScriptLPS(1);
  6315. bool result = World.ScriptDanger(m_host.LocalId, pos);
  6316. if (result)
  6317. {
  6318. return 1;
  6319. }
  6320. else
  6321. {
  6322. return 0;
  6323. }
  6324. }
  6325. public void llDialog(string avatar, string message, LSL_List buttons, int chat_channel)
  6326. {
  6327. IDialogModule dm = World.RequestModuleInterface<IDialogModule>();
  6328. if (dm == null)
  6329. return;
  6330. m_host.AddScriptLPS(1);
  6331. UUID av = new UUID();
  6332. if (!UUID.TryParse(avatar,out av))
  6333. {
  6334. Error("llDialog", "First parameter must be a key");
  6335. return;
  6336. }
  6337. if (buttons.Length < 1)
  6338. {
  6339. Error("llDialog", "At least 1 button must be shown");
  6340. return;
  6341. }
  6342. if (buttons.Length > 12)
  6343. {
  6344. Error("llDialog", "No more than 12 buttons can be shown");
  6345. return;
  6346. }
  6347. string[] buts = new string[buttons.Length];
  6348. for (int i = 0; i < buttons.Length; i++)
  6349. {
  6350. if (buttons.Data[i].ToString() == String.Empty)
  6351. {
  6352. Error("llDialog", "Button label cannot be blank");
  6353. return;
  6354. }
  6355. if (buttons.Data[i].ToString().Length > 24)
  6356. {
  6357. Error("llDialog", "Button label cannot be longer than 24 characters");
  6358. return;
  6359. }
  6360. buts[i] = buttons.Data[i].ToString();
  6361. }
  6362. dm.SendDialogToUser(
  6363. av, m_host.Name, m_host.UUID, m_host.OwnerID,
  6364. message, new UUID("00000000-0000-2222-3333-100000001000"), chat_channel, buts);
  6365. ScriptSleep(m_sleepMsOnDialog);
  6366. }
  6367. public void llVolumeDetect(int detect)
  6368. {
  6369. m_host.AddScriptLPS(1);
  6370. if (!m_host.ParentGroup.IsDeleted)
  6371. m_host.ParentGroup.ScriptSetVolumeDetect(detect != 0);
  6372. }
  6373. public void llRemoteLoadScript(string target, string name, int running, int start_param)
  6374. {
  6375. m_host.AddScriptLPS(1);
  6376. Deprecated("llRemoteLoadScript", "Use llRemoteLoadScriptPin instead");
  6377. ScriptSleep(m_sleepMsOnRemoteLoadScript);
  6378. }
  6379. public void llSetRemoteScriptAccessPin(int pin)
  6380. {
  6381. m_host.AddScriptLPS(1);
  6382. m_host.ScriptAccessPin = pin;
  6383. }
  6384. public void llRemoteLoadScriptPin(string target, string name, int pin, int running, int start_param)
  6385. {
  6386. m_host.AddScriptLPS(1);
  6387. UUID destId = UUID.Zero;
  6388. if (!UUID.TryParse(target, out destId))
  6389. {
  6390. Error("llRemoteLoadScriptPin", "Can't parse key '" + target + "'");
  6391. return;
  6392. }
  6393. // target must be a different prim than the one containing the script
  6394. if (m_host.UUID == destId)
  6395. {
  6396. return;
  6397. }
  6398. // copy the first script found with this inventory name
  6399. TaskInventoryItem item = m_host.Inventory.GetInventoryItem(name);
  6400. // make sure the object is a script
  6401. if (item == null || item.Type != 10)
  6402. {
  6403. Error("llRemoteLoadScriptPin", "Can't find script '" + name + "'");
  6404. return;
  6405. }
  6406. // the rest of the permission checks are done in RezScript, so check the pin there as well
  6407. World.RezScriptFromPrim(item.ItemID, m_host, destId, pin, running, start_param);
  6408. // this will cause the delay even if the script pin or permissions were wrong - seems ok
  6409. ScriptSleep(m_sleepMsOnRemoteLoadScriptPin);
  6410. }
  6411. public void llOpenRemoteDataChannel()
  6412. {
  6413. m_host.AddScriptLPS(1);
  6414. IXMLRPC xmlrpcMod = m_ScriptEngine.World.RequestModuleInterface<IXMLRPC>();
  6415. if (xmlrpcMod != null && xmlrpcMod.IsEnabled())
  6416. {
  6417. UUID channelID = xmlrpcMod.OpenXMLRPCChannel(m_host.LocalId, m_item.ItemID, UUID.Zero);
  6418. IXmlRpcRouter xmlRpcRouter = m_ScriptEngine.World.RequestModuleInterface<IXmlRpcRouter>();
  6419. if (xmlRpcRouter != null)
  6420. {
  6421. string ExternalHostName = m_ScriptEngine.World.RegionInfo.ExternalHostName;
  6422. xmlRpcRouter.RegisterNewReceiver(m_ScriptEngine.ScriptModule, channelID, m_host.UUID,
  6423. m_item.ItemID, String.Format("http://{0}:{1}/", ExternalHostName,
  6424. xmlrpcMod.Port.ToString()));
  6425. }
  6426. object[] resobj = new object[]
  6427. {
  6428. new LSL_Integer(1),
  6429. new LSL_String(channelID.ToString()),
  6430. new LSL_String(UUID.Zero.ToString()),
  6431. new LSL_String(String.Empty),
  6432. new LSL_Integer(0),
  6433. new LSL_String(String.Empty)
  6434. };
  6435. m_ScriptEngine.PostScriptEvent(m_item.ItemID, new EventParams("remote_data", resobj,
  6436. new DetectParams[0]));
  6437. }
  6438. ScriptSleep(m_sleepMsOnOpenRemoteDataChannel);
  6439. }
  6440. public LSL_String llSendRemoteData(string channel, string dest, int idata, string sdata)
  6441. {
  6442. m_host.AddScriptLPS(1);
  6443. IXMLRPC xmlrpcMod = m_ScriptEngine.World.RequestModuleInterface<IXMLRPC>();
  6444. ScriptSleep(m_sleepMsOnSendRemoteData);
  6445. if (xmlrpcMod == null)
  6446. return "";
  6447. return (xmlrpcMod.SendRemoteData(m_host.LocalId, m_item.ItemID, channel, dest, idata, sdata)).ToString();
  6448. }
  6449. public void llRemoteDataReply(string channel, string message_id, string sdata, int idata)
  6450. {
  6451. m_host.AddScriptLPS(1);
  6452. IXMLRPC xmlrpcMod = m_ScriptEngine.World.RequestModuleInterface<IXMLRPC>();
  6453. if (xmlrpcMod != null)
  6454. xmlrpcMod.RemoteDataReply(channel, message_id, sdata, idata);
  6455. ScriptSleep(m_sleepMsOnRemoteDataReply);
  6456. }
  6457. public void llCloseRemoteDataChannel(string channel)
  6458. {
  6459. m_host.AddScriptLPS(1);
  6460. IXmlRpcRouter xmlRpcRouter = m_ScriptEngine.World.RequestModuleInterface<IXmlRpcRouter>();
  6461. if (xmlRpcRouter != null)
  6462. {
  6463. xmlRpcRouter.UnRegisterReceiver(channel, m_item.ItemID);
  6464. }
  6465. IXMLRPC xmlrpcMod = m_ScriptEngine.World.RequestModuleInterface<IXMLRPC>();
  6466. if (xmlrpcMod != null)
  6467. xmlrpcMod.CloseXMLRPCChannel((UUID)channel);
  6468. ScriptSleep(m_sleepMsOnCloseRemoteDataChannel);
  6469. }
  6470. public LSL_String llMD5String(string src, int nonce)
  6471. {
  6472. m_host.AddScriptLPS(1);
  6473. return Util.Md5Hash(String.Format("{0}:{1}", src, nonce.ToString()));
  6474. }
  6475. public LSL_String llSHA1String(string src)
  6476. {
  6477. m_host.AddScriptLPS(1);
  6478. return Util.SHA1Hash(src).ToLower();
  6479. }
  6480. protected ObjectShapePacket.ObjectDataBlock SetPrimitiveBlockShapeParams(SceneObjectPart part, int holeshape, LSL_Vector cut, float hollow, LSL_Vector twist, byte profileshape, byte pathcurve)
  6481. {
  6482. float tempFloat; // Use in float expressions below to avoid byte cast precision issues.
  6483. ObjectShapePacket.ObjectDataBlock shapeBlock = new ObjectShapePacket.ObjectDataBlock();
  6484. if (holeshape != (int)ScriptBaseClass.PRIM_HOLE_DEFAULT &&
  6485. holeshape != (int)ScriptBaseClass.PRIM_HOLE_CIRCLE &&
  6486. holeshape != (int)ScriptBaseClass.PRIM_HOLE_SQUARE &&
  6487. holeshape != (int)ScriptBaseClass.PRIM_HOLE_TRIANGLE)
  6488. {
  6489. holeshape = (int)ScriptBaseClass.PRIM_HOLE_DEFAULT;
  6490. }
  6491. shapeBlock.PathCurve = pathcurve;
  6492. shapeBlock.ProfileCurve = (byte)holeshape; // Set the hole shape.
  6493. shapeBlock.ProfileCurve += profileshape; // Add in the profile shape.
  6494. if (cut.x < 0f)
  6495. {
  6496. cut.x = 0f;
  6497. }
  6498. if (cut.x > 1f)
  6499. {
  6500. cut.x = 1f;
  6501. }
  6502. if (cut.y < 0f)
  6503. {
  6504. cut.y = 0f;
  6505. }
  6506. if (cut.y > 1f)
  6507. {
  6508. cut.y = 1f;
  6509. }
  6510. if (cut.y - cut.x < 0.02f)
  6511. {
  6512. cut.x = cut.y - 0.02f;
  6513. if (cut.x < 0.0f)
  6514. {
  6515. cut.x = 0.0f;
  6516. cut.y = 0.02f;
  6517. }
  6518. }
  6519. shapeBlock.ProfileBegin = (ushort)(50000 * cut.x);
  6520. shapeBlock.ProfileEnd = (ushort)(50000 * (1 - cut.y));
  6521. if (hollow < 0f)
  6522. {
  6523. hollow = 0f;
  6524. }
  6525. // If the prim is a Cylinder, Prism, Sphere, Torus or Ring (or not a
  6526. // Box or Tube) and the hole shape is a square, hollow is limited to
  6527. // a max of 70%. The viewer performs its own check on this value but
  6528. // we need to do it here also so llGetPrimitiveParams can have access
  6529. // to the correct value.
  6530. if (profileshape != (byte)ProfileCurve.Square &&
  6531. holeshape == (int)ScriptBaseClass.PRIM_HOLE_SQUARE)
  6532. {
  6533. if (hollow > 0.70f)
  6534. {
  6535. hollow = 0.70f;
  6536. }
  6537. }
  6538. // Otherwise, hollow is limited to 99%.
  6539. else
  6540. {
  6541. if (hollow > 0.99f)
  6542. {
  6543. hollow = 0.99f;
  6544. }
  6545. }
  6546. shapeBlock.ProfileHollow = (ushort)(50000 * hollow);
  6547. if (twist.x < -1.0f)
  6548. {
  6549. twist.x = -1.0f;
  6550. }
  6551. if (twist.x > 1.0f)
  6552. {
  6553. twist.x = 1.0f;
  6554. }
  6555. if (twist.y < -1.0f)
  6556. {
  6557. twist.y = -1.0f;
  6558. }
  6559. if (twist.y > 1.0f)
  6560. {
  6561. twist.y = 1.0f;
  6562. }
  6563. // A fairly large precision error occurs for some calculations,
  6564. // if a float or double is directly cast to a byte or sbyte
  6565. // variable, in both .Net and Mono. In .Net, coding
  6566. // "(sbyte)(float)(some expression)" corrects the precision
  6567. // errors. But this does not work for Mono. This longer coding
  6568. // form of creating a tempoary float variable from the
  6569. // expression first, then casting that variable to a byte or
  6570. // sbyte, works for both .Net and Mono. These types of
  6571. // assignments occur in SetPrimtiveBlockShapeParams and
  6572. // SetPrimitiveShapeParams in support of llSetPrimitiveParams.
  6573. tempFloat = (float)(100.0d * twist.x);
  6574. shapeBlock.PathTwistBegin = (sbyte)tempFloat;
  6575. tempFloat = (float)(100.0d * twist.y);
  6576. shapeBlock.PathTwist = (sbyte)tempFloat;
  6577. shapeBlock.ObjectLocalID = part.LocalId;
  6578. part.Shape.SculptEntry = false;
  6579. return shapeBlock;
  6580. }
  6581. // Prim type box, cylinder and prism.
  6582. 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)
  6583. {
  6584. float tempFloat; // Use in float expressions below to avoid byte cast precision issues.
  6585. ObjectShapePacket.ObjectDataBlock shapeBlock;
  6586. shapeBlock = SetPrimitiveBlockShapeParams(part, holeshape, cut, hollow, twist, profileshape, pathcurve);
  6587. if (taper_b.x < 0f)
  6588. {
  6589. taper_b.x = 0f;
  6590. }
  6591. if (taper_b.x > 2f)
  6592. {
  6593. taper_b.x = 2f;
  6594. }
  6595. if (taper_b.y < 0f)
  6596. {
  6597. taper_b.y = 0f;
  6598. }
  6599. if (taper_b.y > 2f)
  6600. {
  6601. taper_b.y = 2f;
  6602. }
  6603. tempFloat = (float)(100.0d * (2.0d - taper_b.x));
  6604. shapeBlock.PathScaleX = (byte)tempFloat;
  6605. tempFloat = (float)(100.0d * (2.0d - taper_b.y));
  6606. shapeBlock.PathScaleY = (byte)tempFloat;
  6607. if (topshear.x < -0.5f)
  6608. {
  6609. topshear.x = -0.5f;
  6610. }
  6611. if (topshear.x > 0.5f)
  6612. {
  6613. topshear.x = 0.5f;
  6614. }
  6615. if (topshear.y < -0.5f)
  6616. {
  6617. topshear.y = -0.5f;
  6618. }
  6619. if (topshear.y > 0.5f)
  6620. {
  6621. topshear.y = 0.5f;
  6622. }
  6623. tempFloat = (float)(100.0d * topshear.x);
  6624. shapeBlock.PathShearX = (byte)tempFloat;
  6625. tempFloat = (float)(100.0d * topshear.y);
  6626. shapeBlock.PathShearY = (byte)tempFloat;
  6627. part.Shape.SculptEntry = false;
  6628. part.UpdateShape(shapeBlock);
  6629. }
  6630. // Prim type sphere.
  6631. protected void SetPrimitiveShapeParams(SceneObjectPart part, int holeshape, LSL_Vector cut, float hollow, LSL_Vector twist, LSL_Vector dimple, byte profileshape, byte pathcurve)
  6632. {
  6633. ObjectShapePacket.ObjectDataBlock shapeBlock;
  6634. shapeBlock = SetPrimitiveBlockShapeParams(part, holeshape, cut, hollow, twist, profileshape, pathcurve);
  6635. // profile/path swapped for a sphere
  6636. shapeBlock.PathBegin = shapeBlock.ProfileBegin;
  6637. shapeBlock.PathEnd = shapeBlock.ProfileEnd;
  6638. shapeBlock.PathScaleX = 100;
  6639. shapeBlock.PathScaleY = 100;
  6640. if (dimple.x < 0f)
  6641. {
  6642. dimple.x = 0f;
  6643. }
  6644. if (dimple.x > 1f)
  6645. {
  6646. dimple.x = 1f;
  6647. }
  6648. if (dimple.y < 0f)
  6649. {
  6650. dimple.y = 0f;
  6651. }
  6652. if (dimple.y > 1f)
  6653. {
  6654. dimple.y = 1f;
  6655. }
  6656. if (dimple.y - dimple.x < 0.02f)
  6657. {
  6658. dimple.x = dimple.y - 0.02f;
  6659. if (dimple.x < 0.0f)
  6660. {
  6661. dimple.x = 0.0f;
  6662. dimple.y = 0.02f;
  6663. }
  6664. }
  6665. shapeBlock.ProfileBegin = (ushort)(50000 * dimple.x);
  6666. shapeBlock.ProfileEnd = (ushort)(50000 * (1 - dimple.y));
  6667. part.Shape.SculptEntry = false;
  6668. part.UpdateShape(shapeBlock);
  6669. }
  6670. // Prim type torus, tube and ring.
  6671. 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)
  6672. {
  6673. float tempFloat; // Use in float expressions below to avoid byte cast precision issues.
  6674. ObjectShapePacket.ObjectDataBlock shapeBlock;
  6675. shapeBlock = SetPrimitiveBlockShapeParams(part, holeshape, cut, hollow, twist, profileshape, pathcurve);
  6676. // profile/path swapped for a torrus, tube, ring
  6677. shapeBlock.PathBegin = shapeBlock.ProfileBegin;
  6678. shapeBlock.PathEnd = shapeBlock.ProfileEnd;
  6679. if (holesize.x < 0.01f)
  6680. {
  6681. holesize.x = 0.01f;
  6682. }
  6683. if (holesize.x > 1f)
  6684. {
  6685. holesize.x = 1f;
  6686. }
  6687. if (holesize.y < 0.01f)
  6688. {
  6689. holesize.y = 0.01f;
  6690. }
  6691. if (holesize.y > 0.5f)
  6692. {
  6693. holesize.y = 0.5f;
  6694. }
  6695. tempFloat = (float)(100.0d * (2.0d - holesize.x));
  6696. shapeBlock.PathScaleX = (byte)tempFloat;
  6697. tempFloat = (float)(100.0d * (2.0d - holesize.y));
  6698. shapeBlock.PathScaleY = (byte)tempFloat;
  6699. if (topshear.x < -0.5f)
  6700. {
  6701. topshear.x = -0.5f;
  6702. }
  6703. if (topshear.x > 0.5f)
  6704. {
  6705. topshear.x = 0.5f;
  6706. }
  6707. if (topshear.y < -0.5f)
  6708. {
  6709. topshear.y = -0.5f;
  6710. }
  6711. if (topshear.y > 0.5f)
  6712. {
  6713. topshear.y = 0.5f;
  6714. }
  6715. tempFloat = (float)(100.0d * topshear.x);
  6716. shapeBlock.PathShearX = (byte)tempFloat;
  6717. tempFloat = (float)(100.0d * topshear.y);
  6718. shapeBlock.PathShearY = (byte)tempFloat;
  6719. if (profilecut.x < 0f)
  6720. {
  6721. profilecut.x = 0f;
  6722. }
  6723. if (profilecut.x > 1f)
  6724. {
  6725. profilecut.x = 1f;
  6726. }
  6727. if (profilecut.y < 0f)
  6728. {
  6729. profilecut.y = 0f;
  6730. }
  6731. if (profilecut.y > 1f)
  6732. {
  6733. profilecut.y = 1f;
  6734. }
  6735. if (profilecut.y - profilecut.x < 0.02f)
  6736. {
  6737. profilecut.x = profilecut.y - 0.02f;
  6738. if (profilecut.x < 0.0f)
  6739. {
  6740. profilecut.x = 0.0f;
  6741. profilecut.y = 0.02f;
  6742. }
  6743. }
  6744. shapeBlock.ProfileBegin = (ushort)(50000 * profilecut.x);
  6745. shapeBlock.ProfileEnd = (ushort)(50000 * (1 - profilecut.y));
  6746. if (taper_a.x < -1f)
  6747. {
  6748. taper_a.x = -1f;
  6749. }
  6750. if (taper_a.x > 1f)
  6751. {
  6752. taper_a.x = 1f;
  6753. }
  6754. if (taper_a.y < -1f)
  6755. {
  6756. taper_a.y = -1f;
  6757. }
  6758. if (taper_a.y > 1f)
  6759. {
  6760. taper_a.y = 1f;
  6761. }
  6762. tempFloat = (float)(100.0d * taper_a.x);
  6763. shapeBlock.PathTaperX = (sbyte)tempFloat;
  6764. tempFloat = (float)(100.0d * taper_a.y);
  6765. shapeBlock.PathTaperY = (sbyte)tempFloat;
  6766. if (revolutions < 1f)
  6767. {
  6768. revolutions = 1f;
  6769. }
  6770. if (revolutions > 4f)
  6771. {
  6772. revolutions = 4f;
  6773. }
  6774. tempFloat = 66.66667f * (revolutions - 1.0f);
  6775. shapeBlock.PathRevolutions = (byte)tempFloat;
  6776. // limits on radiusoffset depend on revolutions and hole size (how?) seems like the maximum range is 0 to 1
  6777. if (radiusoffset < 0f)
  6778. {
  6779. radiusoffset = 0f;
  6780. }
  6781. if (radiusoffset > 1f)
  6782. {
  6783. radiusoffset = 1f;
  6784. }
  6785. tempFloat = 100.0f * radiusoffset;
  6786. shapeBlock.PathRadiusOffset = (sbyte)tempFloat;
  6787. if (skew < -0.95f)
  6788. {
  6789. skew = -0.95f;
  6790. }
  6791. if (skew > 0.95f)
  6792. {
  6793. skew = 0.95f;
  6794. }
  6795. tempFloat = 100.0f * skew;
  6796. shapeBlock.PathSkew = (sbyte)tempFloat;
  6797. part.Shape.SculptEntry = false;
  6798. part.UpdateShape(shapeBlock);
  6799. }
  6800. // Prim type sculpt.
  6801. protected void SetPrimitiveShapeParams(SceneObjectPart part, string map, int type, byte pathcurve)
  6802. {
  6803. ObjectShapePacket.ObjectDataBlock shapeBlock = new ObjectShapePacket.ObjectDataBlock();
  6804. UUID sculptId;
  6805. if (!UUID.TryParse(map, out sculptId))
  6806. sculptId = ScriptUtils.GetAssetIdFromItemName(m_host, map, (int)AssetType.Texture);
  6807. if (sculptId == UUID.Zero)
  6808. return;
  6809. shapeBlock.PathCurve = pathcurve;
  6810. shapeBlock.ObjectLocalID = part.LocalId;
  6811. shapeBlock.PathScaleX = 100;
  6812. shapeBlock.PathScaleY = 150;
  6813. int flag = type & (ScriptBaseClass.PRIM_SCULPT_FLAG_INVERT | ScriptBaseClass.PRIM_SCULPT_FLAG_MIRROR);
  6814. if (type != (ScriptBaseClass.PRIM_SCULPT_TYPE_CYLINDER | flag) &&
  6815. type != (ScriptBaseClass.PRIM_SCULPT_TYPE_PLANE | flag) &&
  6816. type != (ScriptBaseClass.PRIM_SCULPT_TYPE_SPHERE | flag) &&
  6817. type != (ScriptBaseClass.PRIM_SCULPT_TYPE_TORUS | flag))
  6818. {
  6819. // default
  6820. type = (int)ScriptBaseClass.PRIM_SCULPT_TYPE_SPHERE;
  6821. }
  6822. part.Shape.SetSculptProperties((byte)type, sculptId);
  6823. part.Shape.SculptEntry = true;
  6824. part.UpdateShape(shapeBlock);
  6825. }
  6826. public void llSetPrimitiveParams(LSL_List rules)
  6827. {
  6828. m_host.AddScriptLPS(1);
  6829. SetLinkPrimParams(ScriptBaseClass.LINK_THIS, rules, "llSetPrimitiveParams");
  6830. ScriptSleep(m_sleepMsOnSetPrimitiveParams);
  6831. }
  6832. public void llSetLinkPrimitiveParams(int linknumber, LSL_List rules)
  6833. {
  6834. m_host.AddScriptLPS(1);
  6835. SetLinkPrimParams(linknumber, rules, "llSetLinkPrimitiveParams");
  6836. ScriptSleep(m_sleepMsOnSetLinkPrimitiveParams);
  6837. }
  6838. public void llSetLinkPrimitiveParamsFast(int linknumber, LSL_List rules)
  6839. {
  6840. m_host.AddScriptLPS(1);
  6841. SetLinkPrimParams(linknumber, rules, "llSetLinkPrimitiveParamsFast");
  6842. }
  6843. protected void SetLinkPrimParams(int linknumber, LSL_List rules, string originFunc)
  6844. {
  6845. SetEntityParams(GetLinkEntities(linknumber), rules, originFunc);
  6846. }
  6847. protected void SetEntityParams(List<ISceneEntity> entities, LSL_List rules, string originFunc)
  6848. {
  6849. LSL_List remaining = null;
  6850. uint rulesParsed = 0;
  6851. foreach (ISceneEntity entity in entities)
  6852. {
  6853. if (entity is SceneObjectPart)
  6854. remaining = SetPrimParams((SceneObjectPart)entity, rules, originFunc, ref rulesParsed);
  6855. else
  6856. remaining = SetAgentParams((ScenePresence)entity, rules, originFunc, ref rulesParsed);
  6857. }
  6858. while (remaining != null && remaining.Length > 2)
  6859. {
  6860. int linknumber;
  6861. try
  6862. {
  6863. linknumber = remaining.GetLSLIntegerItem(0);
  6864. }
  6865. catch(InvalidCastException)
  6866. {
  6867. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_LINK_TARGET: parameter 2 must be integer", rulesParsed));
  6868. return;
  6869. }
  6870. rules = remaining.GetSublist(1, -1);
  6871. entities = GetLinkEntities(linknumber);
  6872. foreach (ISceneEntity entity in entities)
  6873. {
  6874. if (entity is SceneObjectPart)
  6875. remaining = SetPrimParams((SceneObjectPart)entity, rules, originFunc, ref rulesParsed);
  6876. else
  6877. remaining = SetAgentParams((ScenePresence)entity, rules, originFunc, ref rulesParsed);
  6878. }
  6879. }
  6880. }
  6881. public void llSetKeyframedMotion(LSL_List frames, LSL_List options)
  6882. {
  6883. SceneObjectGroup group = m_host.ParentGroup;
  6884. if (group.RootPart.PhysActor != null && group.RootPart.PhysActor.IsPhysical)
  6885. return;
  6886. if (group.IsAttachment)
  6887. return;
  6888. if (frames.Data.Length > 0) // We are getting a new motion
  6889. {
  6890. if (group.RootPart.KeyframeMotion != null)
  6891. group.RootPart.KeyframeMotion.Delete();
  6892. group.RootPart.KeyframeMotion = null;
  6893. int idx = 0;
  6894. KeyframeMotion.PlayMode mode = KeyframeMotion.PlayMode.Forward;
  6895. KeyframeMotion.DataFormat data = KeyframeMotion.DataFormat.Translation | KeyframeMotion.DataFormat.Rotation;
  6896. while (idx < options.Data.Length)
  6897. {
  6898. int option = (int)options.GetLSLIntegerItem(idx++);
  6899. int remain = options.Data.Length - idx;
  6900. switch (option)
  6901. {
  6902. case ScriptBaseClass.KFM_MODE:
  6903. if (remain < 1)
  6904. break;
  6905. int modeval = (int)options.GetLSLIntegerItem(idx++);
  6906. switch(modeval)
  6907. {
  6908. case ScriptBaseClass.KFM_FORWARD:
  6909. mode = KeyframeMotion.PlayMode.Forward;
  6910. break;
  6911. case ScriptBaseClass.KFM_REVERSE:
  6912. mode = KeyframeMotion.PlayMode.Reverse;
  6913. break;
  6914. case ScriptBaseClass.KFM_LOOP:
  6915. mode = KeyframeMotion.PlayMode.Loop;
  6916. break;
  6917. case ScriptBaseClass.KFM_PING_PONG:
  6918. mode = KeyframeMotion.PlayMode.PingPong;
  6919. break;
  6920. }
  6921. break;
  6922. case ScriptBaseClass.KFM_DATA:
  6923. if (remain < 1)
  6924. break;
  6925. int dataval = (int)options.GetLSLIntegerItem(idx++);
  6926. data = (KeyframeMotion.DataFormat)dataval;
  6927. break;
  6928. }
  6929. }
  6930. group.RootPart.KeyframeMotion = new KeyframeMotion(group, mode, data);
  6931. idx = 0;
  6932. int elemLength = 2;
  6933. if (data == (KeyframeMotion.DataFormat.Translation | KeyframeMotion.DataFormat.Rotation))
  6934. elemLength = 3;
  6935. List<KeyframeMotion.Keyframe> keyframes = new List<KeyframeMotion.Keyframe>();
  6936. while (idx < frames.Data.Length)
  6937. {
  6938. int remain = frames.Data.Length - idx;
  6939. if (remain < elemLength)
  6940. break;
  6941. KeyframeMotion.Keyframe frame = new KeyframeMotion.Keyframe();
  6942. frame.Position = null;
  6943. frame.Rotation = null;
  6944. if ((data & KeyframeMotion.DataFormat.Translation) != 0)
  6945. {
  6946. LSL_Types.Vector3 tempv = frames.GetVector3Item(idx++);
  6947. frame.Position = new Vector3((float)tempv.x, (float)tempv.y, (float)tempv.z);
  6948. }
  6949. if ((data & KeyframeMotion.DataFormat.Rotation) != 0)
  6950. {
  6951. LSL_Types.Quaternion tempq = frames.GetQuaternionItem(idx++);
  6952. Quaternion q = new Quaternion((float)tempq.x, (float)tempq.y, (float)tempq.z, (float)tempq.s);
  6953. q.Normalize();
  6954. frame.Rotation = q;
  6955. }
  6956. float tempf = (float)frames.GetLSLFloatItem(idx++);
  6957. frame.TimeMS = (int)(tempf * 1000.0f);
  6958. keyframes.Add(frame);
  6959. }
  6960. group.RootPart.KeyframeMotion.SetKeyframes(keyframes.ToArray());
  6961. group.RootPart.KeyframeMotion.Start();
  6962. }
  6963. else
  6964. {
  6965. if (group.RootPart.KeyframeMotion == null)
  6966. return;
  6967. if (options.Data.Length == 0)
  6968. {
  6969. group.RootPart.KeyframeMotion.Stop();
  6970. return;
  6971. }
  6972. int idx = 0;
  6973. while (idx < options.Data.Length)
  6974. {
  6975. int option = (int)options.GetLSLIntegerItem(idx++);
  6976. switch (option)
  6977. {
  6978. case ScriptBaseClass.KFM_COMMAND:
  6979. int cmd = (int)options.GetLSLIntegerItem(idx++);
  6980. switch (cmd)
  6981. {
  6982. case ScriptBaseClass.KFM_CMD_PLAY:
  6983. group.RootPart.KeyframeMotion.Start();
  6984. break;
  6985. case ScriptBaseClass.KFM_CMD_STOP:
  6986. group.RootPart.KeyframeMotion.Stop();
  6987. break;
  6988. case ScriptBaseClass.KFM_CMD_PAUSE:
  6989. group.RootPart.KeyframeMotion.Pause();
  6990. break;
  6991. }
  6992. break;
  6993. }
  6994. }
  6995. }
  6996. }
  6997. protected LSL_List SetPrimParams(SceneObjectPart part, LSL_List rules, string originFunc, ref uint rulesParsed)
  6998. {
  6999. int idx = 0;
  7000. int idxStart = 0;
  7001. bool positionChanged = false;
  7002. LSL_Vector currentPosition = GetPartLocalPos(part);
  7003. try
  7004. {
  7005. while (idx < rules.Length)
  7006. {
  7007. ++rulesParsed;
  7008. int code = rules.GetLSLIntegerItem(idx++);
  7009. int remain = rules.Length - idx;
  7010. idxStart = idx;
  7011. int face;
  7012. LSL_Vector v;
  7013. switch (code)
  7014. {
  7015. case ScriptBaseClass.PRIM_POSITION:
  7016. case ScriptBaseClass.PRIM_POS_LOCAL:
  7017. if (remain < 1)
  7018. return null;
  7019. try
  7020. {
  7021. v = rules.GetVector3Item(idx++);
  7022. }
  7023. catch(InvalidCastException)
  7024. {
  7025. if(code == ScriptBaseClass.PRIM_POSITION)
  7026. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_POSITION: arg #{1} - parameter 1 must be vector", rulesParsed, idx - idxStart - 1));
  7027. else
  7028. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_POS_LOCAL: arg #{1} - parameter 1 must be vector", rulesParsed, idx - idxStart - 1));
  7029. return null;
  7030. }
  7031. positionChanged = true;
  7032. currentPosition = GetSetPosTarget(part, v, currentPosition);
  7033. break;
  7034. case ScriptBaseClass.PRIM_SIZE:
  7035. if (remain < 1)
  7036. return null;
  7037. v=rules.GetVector3Item(idx++);
  7038. SetScale(part, v);
  7039. break;
  7040. case ScriptBaseClass.PRIM_ROTATION:
  7041. if (remain < 1)
  7042. return null;
  7043. LSL_Rotation q;
  7044. try
  7045. {
  7046. q = rules.GetQuaternionItem(idx++);
  7047. }
  7048. catch(InvalidCastException)
  7049. {
  7050. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_ROTATION: arg #{1} - parameter 1 must be rotation", rulesParsed, idx - idxStart - 1));
  7051. return null;
  7052. }
  7053. // try to let this work as in SL...
  7054. if (part.ParentID == 0)
  7055. {
  7056. // special case: If we are root, rotate complete SOG to new rotation
  7057. SetRot(part, q);
  7058. }
  7059. else
  7060. {
  7061. // we are a child. The rotation values will be set to the one of root modified by rot, as in SL. Don't ask.
  7062. SceneObjectPart rootPart = part.ParentGroup.RootPart;
  7063. SetRot(part, rootPart.RotationOffset * (Quaternion)q);
  7064. }
  7065. break;
  7066. case ScriptBaseClass.PRIM_TYPE:
  7067. if (remain < 3)
  7068. return null;
  7069. try
  7070. {
  7071. code = (int)rules.GetLSLIntegerItem(idx++);
  7072. }
  7073. catch(InvalidCastException)
  7074. {
  7075. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TYPE: arg #{1} - parameter 1 must be integer", rulesParsed, idx - idxStart - 1));
  7076. return null;
  7077. }
  7078. remain = rules.Length - idx;
  7079. float hollow;
  7080. LSL_Vector twist;
  7081. LSL_Vector taper_b;
  7082. LSL_Vector topshear;
  7083. float revolutions;
  7084. float radiusoffset;
  7085. float skew;
  7086. LSL_Vector holesize;
  7087. LSL_Vector profilecut;
  7088. switch (code)
  7089. {
  7090. case ScriptBaseClass.PRIM_TYPE_BOX:
  7091. if (remain < 6)
  7092. return null;
  7093. try
  7094. {
  7095. face = (int)rules.GetLSLIntegerItem(idx++);
  7096. }
  7097. catch(InvalidCastException)
  7098. {
  7099. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TYPE, PRIM_TYPE_BOX: arg #{1} - parameter 2 must be integer", rulesParsed, idx - idxStart - 1));
  7100. return null;
  7101. }
  7102. try
  7103. {
  7104. v = rules.GetVector3Item(idx++); // cut
  7105. }
  7106. catch(InvalidCastException)
  7107. {
  7108. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TYPE, PRIM_TYPE_BOX: arg #{1} - parameter 3 must be vector", rulesParsed, idx - idxStart - 1));
  7109. return null;
  7110. }
  7111. try
  7112. {
  7113. hollow = (float)rules.GetLSLFloatItem(idx++);
  7114. }
  7115. catch(InvalidCastException)
  7116. {
  7117. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TYPE, PRIM_TYPE_BOX: arg #{1} - parameter 4 must be float", rulesParsed, idx - idxStart - 1));
  7118. return null;
  7119. }
  7120. try
  7121. {
  7122. twist = rules.GetVector3Item(idx++);
  7123. }
  7124. catch(InvalidCastException)
  7125. {
  7126. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TYPE, PRIM_TYPE_BOX: arg #{1} - parameter 5 must be vector", rulesParsed, idx - idxStart - 1));
  7127. return null;
  7128. }
  7129. try
  7130. {
  7131. taper_b = rules.GetVector3Item(idx++);
  7132. }
  7133. catch(InvalidCastException)
  7134. {
  7135. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TYPE, PRIM_TYPE_BOX: arg #{1} - parameter 6 must be vector", rulesParsed, idx - idxStart - 1));
  7136. return null;
  7137. }
  7138. try
  7139. {
  7140. topshear = rules.GetVector3Item(idx++);
  7141. }
  7142. catch(InvalidCastException)
  7143. {
  7144. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TYPE, PRIM_TYPE_BOX: arg #{1} - parameter 7 must be vector", rulesParsed, idx - idxStart - 1));
  7145. return null;
  7146. }
  7147. SetPrimitiveShapeParams(part, face, v, hollow, twist, taper_b, topshear,
  7148. (byte)ProfileShape.Square, (byte)Extrusion.Straight);
  7149. break;
  7150. case ScriptBaseClass.PRIM_TYPE_CYLINDER:
  7151. if (remain < 6)
  7152. return null;
  7153. try
  7154. {
  7155. face = (int)rules.GetLSLIntegerItem(idx++); // holeshape
  7156. }
  7157. catch(InvalidCastException)
  7158. {
  7159. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TYPE, PRIM_TYPE_CYLINDER: arg #{1} - parameter 3 must be integer", rulesParsed, idx - idxStart - 1));
  7160. return null;
  7161. }
  7162. try
  7163. {
  7164. v = rules.GetVector3Item(idx++); // cut
  7165. }
  7166. catch(InvalidCastException)
  7167. {
  7168. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TYPE, PRIM_TYPE_CYLINDER: arg #{1} - parameter 4 must be vector", rulesParsed, idx - idxStart - 1));
  7169. return null;
  7170. }
  7171. try
  7172. {
  7173. hollow = (float)rules.GetLSLFloatItem(idx++);
  7174. }
  7175. catch(InvalidCastException)
  7176. {
  7177. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TYPE, PRIM_TYPE_CYLINDER: arg #{1} - parameter 5 must be float", rulesParsed, idx - idxStart - 1));
  7178. return null;
  7179. }
  7180. try
  7181. {
  7182. twist = rules.GetVector3Item(idx++);
  7183. }
  7184. catch(InvalidCastException)
  7185. {
  7186. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TYPE, PRIM_TYPE_CYLINDER: arg #{1} - parameter 6 must be vector", rulesParsed, idx - idxStart - 1));
  7187. return null;
  7188. }
  7189. try
  7190. {
  7191. taper_b = rules.GetVector3Item(idx++);
  7192. }
  7193. catch(InvalidCastException)
  7194. {
  7195. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TYPE, PRIM_TYPE_CYLINDER: arg #{1} - parameter 7 must be vector", rulesParsed, idx - idxStart - 1));
  7196. return null;
  7197. }
  7198. try
  7199. {
  7200. topshear = rules.GetVector3Item(idx++);
  7201. }
  7202. catch(InvalidCastException)
  7203. {
  7204. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TYPE, PRIM_TYPE_CYLINDER: arg #{1} - parameter 8 must be vector", rulesParsed, idx - idxStart - 1));
  7205. return null;
  7206. }
  7207. SetPrimitiveShapeParams(part, face, v, hollow, twist, taper_b, topshear,
  7208. (byte)ProfileShape.Circle, (byte)Extrusion.Straight);
  7209. break;
  7210. case ScriptBaseClass.PRIM_TYPE_PRISM:
  7211. if (remain < 6)
  7212. return null;
  7213. try
  7214. {
  7215. face = (int)rules.GetLSLIntegerItem(idx++); // holeshape
  7216. }
  7217. catch(InvalidCastException)
  7218. {
  7219. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TYPE, PRIM_TYPE_PRISM: arg #{1} - parameter 3 must be integer", rulesParsed, idx - idxStart - 1));
  7220. return null;
  7221. }
  7222. try
  7223. {
  7224. v = rules.GetVector3Item(idx++); //cut
  7225. }
  7226. catch(InvalidCastException)
  7227. {
  7228. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TYPE, PRIM_TYPE_PRISM: arg #{1} - parameter 4 must be vector", rulesParsed, idx - idxStart - 1));
  7229. return null;
  7230. }
  7231. try
  7232. {
  7233. hollow = (float)rules.GetLSLFloatItem(idx++);
  7234. }
  7235. catch(InvalidCastException)
  7236. {
  7237. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TYPE, PRIM_TYPE_PRISM: arg #{1} - parameter 5 must be float", rulesParsed, idx - idxStart - 1));
  7238. return null;
  7239. }
  7240. try
  7241. {
  7242. twist = rules.GetVector3Item(idx++);
  7243. }
  7244. catch(InvalidCastException)
  7245. {
  7246. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TYPE, PRIM_TYPE_PRISM: arg #{1} - parameter 6 must be vector", rulesParsed, idx - idxStart - 1));
  7247. return null;
  7248. }
  7249. try
  7250. {
  7251. taper_b = rules.GetVector3Item(idx++);
  7252. }
  7253. catch(InvalidCastException)
  7254. {
  7255. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TYPE, PRIM_TYPE_PRISM: arg #{1} - parameter 7 must be vector", rulesParsed, idx - idxStart - 1));
  7256. return null;
  7257. }
  7258. try
  7259. {
  7260. topshear = rules.GetVector3Item(idx++);
  7261. }
  7262. catch(InvalidCastException)
  7263. {
  7264. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TYPE, PRIM_TYPE_PRISM: arg #{1} - parameter 8 must be vector", rulesParsed, idx - idxStart - 1));
  7265. return null;
  7266. }
  7267. SetPrimitiveShapeParams(part, face, v, hollow, twist, taper_b, topshear,
  7268. (byte)ProfileShape.EquilateralTriangle, (byte)Extrusion.Straight);
  7269. break;
  7270. case ScriptBaseClass.PRIM_TYPE_SPHERE:
  7271. if (remain < 5)
  7272. return null;
  7273. try
  7274. {
  7275. face = (int)rules.GetLSLIntegerItem(idx++); // holeshape
  7276. }
  7277. catch(InvalidCastException)
  7278. {
  7279. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TYPE, PRIM_TYPE_SPHERE: arg #{1} - parameter 3 must be integer", rulesParsed, idx - idxStart - 1));
  7280. return null;
  7281. }
  7282. try
  7283. {
  7284. v = rules.GetVector3Item(idx++); // cut
  7285. }
  7286. catch(InvalidCastException)
  7287. {
  7288. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TYPE, PRIM_TYPE_SPHERE: arg #{1} - parameter 4 must be vector", rulesParsed, idx - idxStart - 1));
  7289. return null;
  7290. }
  7291. try
  7292. {
  7293. hollow = (float)rules.GetLSLFloatItem(idx++);
  7294. }
  7295. catch(InvalidCastException)
  7296. {
  7297. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TYPE, PRIM_TYPE_SPHERE: arg #{1} - parameter 5 must be float", rulesParsed, idx - idxStart - 1));
  7298. return null;
  7299. }
  7300. try
  7301. {
  7302. twist = rules.GetVector3Item(idx++);
  7303. }
  7304. catch(InvalidCastException)
  7305. {
  7306. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TYPE, PRIM_TYPE_SPHERE: arg #{1} - parameter 6 must be vector", rulesParsed, idx - idxStart - 1));
  7307. return null;
  7308. }
  7309. try
  7310. {
  7311. taper_b = rules.GetVector3Item(idx++); // dimple
  7312. }
  7313. catch(InvalidCastException)
  7314. {
  7315. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TYPE, PRIM_TYPE_SPHERE: arg #{1} - parameter 7 must be vector", rulesParsed, idx - idxStart - 1));
  7316. return null;
  7317. }
  7318. SetPrimitiveShapeParams(part, face, v, hollow, twist, taper_b,
  7319. (byte)ProfileShape.HalfCircle, (byte)Extrusion.Curve1);
  7320. break;
  7321. case ScriptBaseClass.PRIM_TYPE_TORUS:
  7322. if (remain < 11)
  7323. return null;
  7324. try
  7325. {
  7326. face = (int)rules.GetLSLIntegerItem(idx++); // holeshape
  7327. }
  7328. catch(InvalidCastException)
  7329. {
  7330. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TYPE, PRIM_TYPE_TORUS: arg #{1} - parameter 3 must be integer", rulesParsed, idx - idxStart - 1));
  7331. return null;
  7332. }
  7333. try
  7334. {
  7335. v = rules.GetVector3Item(idx++); //cut
  7336. }
  7337. catch(InvalidCastException)
  7338. {
  7339. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TYPE, PRIM_TYPE_TORUS: arg #{1} - parameter 4 must be vector", rulesParsed, idx - idxStart - 1));
  7340. return null;
  7341. }
  7342. try
  7343. {
  7344. hollow = (float)rules.GetLSLFloatItem(idx++);
  7345. }
  7346. catch(InvalidCastException)
  7347. {
  7348. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TYPE, PRIM_TYPE_TORUS: arg #{1} - parameter 5 must be float", rulesParsed, idx - idxStart - 1));
  7349. return null;
  7350. }
  7351. try
  7352. {
  7353. twist = rules.GetVector3Item(idx++);
  7354. }
  7355. catch(InvalidCastException)
  7356. {
  7357. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TYPE, PRIM_TYPE_TORUS: arg #{1} - parameter 6 must be vector", rulesParsed, idx - idxStart - 1));
  7358. return null;
  7359. }
  7360. try
  7361. {
  7362. holesize = rules.GetVector3Item(idx++);
  7363. }
  7364. catch(InvalidCastException)
  7365. {
  7366. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TYPE, PRIM_TYPE_TORUS: arg #{1} - parameter 7 must be vector", rulesParsed, idx - idxStart - 1));
  7367. return null;
  7368. }
  7369. try
  7370. {
  7371. topshear = rules.GetVector3Item(idx++);
  7372. }
  7373. catch(InvalidCastException)
  7374. {
  7375. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TYPE, PRIM_TYPE_TORUS: arg #{1} - parameter 8 must be vector", rulesParsed, idx - idxStart - 1));
  7376. return null;
  7377. }
  7378. try
  7379. {
  7380. profilecut = rules.GetVector3Item(idx++);
  7381. }
  7382. catch(InvalidCastException)
  7383. {
  7384. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TYPE, PRIM_TYPE_TORUS: arg #{1} - parameter 9 must be vector", rulesParsed, idx - idxStart - 1));
  7385. return null;
  7386. }
  7387. try
  7388. {
  7389. taper_b = rules.GetVector3Item(idx++); // taper_a
  7390. }
  7391. catch(InvalidCastException)
  7392. {
  7393. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TYPE, PRIM_TYPE_TORUS: arg #{1} - parameter 10 must be vector", rulesParsed, idx - idxStart - 1));
  7394. return null;
  7395. }
  7396. try
  7397. {
  7398. revolutions = (float)rules.GetLSLFloatItem(idx++);
  7399. }
  7400. catch(InvalidCastException)
  7401. {
  7402. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TYPE, PRIM_TYPE_TORUS: arg #{1} - parameter 11 must be float", rulesParsed, idx - idxStart - 1));
  7403. return null;
  7404. }
  7405. try
  7406. {
  7407. radiusoffset = (float)rules.GetLSLFloatItem(idx++);
  7408. }
  7409. catch(InvalidCastException)
  7410. {
  7411. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TYPE, PRIM_TYPE_TORUS: arg #{1} - parameter 12 must be float", rulesParsed, idx - idxStart - 1));
  7412. return null;
  7413. }
  7414. try
  7415. {
  7416. skew = (float)rules.GetLSLFloatItem(idx++);
  7417. }
  7418. catch(InvalidCastException)
  7419. {
  7420. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TYPE, PRIM_TYPE_TORUS: arg #{1} - parameter 13 must be vector", rulesParsed, idx - idxStart - 1));
  7421. return null;
  7422. }
  7423. SetPrimitiveShapeParams(part, face, v, hollow, twist, holesize, topshear, profilecut, taper_b,
  7424. revolutions, radiusoffset, skew, (byte)ProfileShape.Circle, (byte)Extrusion.Curve1);
  7425. break;
  7426. case ScriptBaseClass.PRIM_TYPE_TUBE:
  7427. if (remain < 11)
  7428. return null;
  7429. try
  7430. {
  7431. face = (int)rules.GetLSLIntegerItem(idx++); // holeshape
  7432. }
  7433. catch(InvalidCastException)
  7434. {
  7435. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TYPE, PRIM_TYPE_TUBE: arg #{1} - parameter 3 must be integer", rulesParsed, idx - idxStart - 1));
  7436. return null;
  7437. }
  7438. try
  7439. {
  7440. v = rules.GetVector3Item(idx++); //cut
  7441. }
  7442. catch(InvalidCastException)
  7443. {
  7444. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TYPE, PRIM_TYPE_TUBE: arg #{1} - parameter 4 must be vector", rulesParsed, idx - idxStart - 1));
  7445. return null;
  7446. }
  7447. try
  7448. {
  7449. hollow = (float)rules.GetLSLFloatItem(idx++);
  7450. }
  7451. catch(InvalidCastException)
  7452. {
  7453. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TYPE, PRIM_TYPE_TUBE: arg #{1} - parameter 5 must be float", rulesParsed, idx - idxStart - 1));
  7454. return null;
  7455. }
  7456. try
  7457. {
  7458. twist = rules.GetVector3Item(idx++);
  7459. }
  7460. catch(InvalidCastException)
  7461. {
  7462. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TYPE, PRIM_TYPE_TUBE: arg #{1} - parameter 6 must be vector", rulesParsed, idx - idxStart - 1));
  7463. return null;
  7464. }
  7465. try
  7466. {
  7467. holesize = rules.GetVector3Item(idx++);
  7468. }
  7469. catch(InvalidCastException)
  7470. {
  7471. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TYPE, PRIM_TYPE_TUBE: arg #{1} - parameter 7 must be vector", rulesParsed, idx - idxStart - 1));
  7472. return null;
  7473. }
  7474. try
  7475. {
  7476. topshear = rules.GetVector3Item(idx++);
  7477. }
  7478. catch(InvalidCastException)
  7479. {
  7480. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TYPE, PRIM_TYPE_TUBE: arg #{1} - parameter 8 must be vector", rulesParsed, idx - idxStart - 1));
  7481. return null;
  7482. }
  7483. try
  7484. {
  7485. profilecut = rules.GetVector3Item(idx++);
  7486. }
  7487. catch(InvalidCastException)
  7488. {
  7489. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TYPE, PRIM_TYPE_TUBE: arg #{1} - parameter 9 must be vector", rulesParsed, idx - idxStart - 1));
  7490. return null;
  7491. }
  7492. try
  7493. {
  7494. taper_b = rules.GetVector3Item(idx++); // taper_a
  7495. }
  7496. catch(InvalidCastException)
  7497. {
  7498. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TYPE, PRIM_TYPE_TUBE: arg #{1} - parameter 10 must be vector", rulesParsed, idx - idxStart - 1));
  7499. return null;
  7500. }
  7501. try
  7502. {
  7503. revolutions = (float)rules.GetLSLFloatItem(idx++);
  7504. }
  7505. catch(InvalidCastException)
  7506. {
  7507. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TYPE, PRIM_TYPE_TUBE: arg #{1} - parameter 11 must be float", rulesParsed, idx - idxStart - 1));
  7508. return null;
  7509. }
  7510. try
  7511. {
  7512. radiusoffset = (float)rules.GetLSLFloatItem(idx++);
  7513. }
  7514. catch(InvalidCastException)
  7515. {
  7516. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TYPE, PRIM_TYPE_TUBE: arg #{1} - parameter 12 must be float", rulesParsed, idx - idxStart - 1));
  7517. return null;
  7518. }
  7519. try
  7520. {
  7521. skew = (float)rules.GetLSLFloatItem(idx++);
  7522. }
  7523. catch(InvalidCastException)
  7524. {
  7525. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TYPE, PRIM_TYPE_TUBE: arg #{1} - parameter 13 must be float", rulesParsed, idx - idxStart - 1));
  7526. return null;
  7527. }
  7528. SetPrimitiveShapeParams(part, face, v, hollow, twist, holesize, topshear, profilecut, taper_b,
  7529. revolutions, radiusoffset, skew, (byte)ProfileShape.Square, (byte)Extrusion.Curve1);
  7530. break;
  7531. case ScriptBaseClass.PRIM_TYPE_RING:
  7532. if (remain < 11)
  7533. return null;
  7534. try
  7535. {
  7536. face = (int)rules.GetLSLIntegerItem(idx++); // holeshape
  7537. }
  7538. catch(InvalidCastException)
  7539. {
  7540. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TYPE, PRIM_TYPE_RING: arg #{1} - parameter 3 must be integer", rulesParsed, idx - idxStart - 1));
  7541. return null;
  7542. }
  7543. try
  7544. {
  7545. v = rules.GetVector3Item(idx++); //cut
  7546. }
  7547. catch(InvalidCastException)
  7548. {
  7549. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TYPE, PRIM_TYPE_RING: arg #{1} - parameter 4 must be vector", rulesParsed, idx - idxStart - 1));
  7550. return null;
  7551. }
  7552. try
  7553. {
  7554. hollow = (float)rules.GetLSLFloatItem(idx++);
  7555. }
  7556. catch(InvalidCastException)
  7557. {
  7558. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TYPE, PRIM_TYPE_RING: arg #{1} - parameter 5 must be float", rulesParsed, idx - idxStart - 1));
  7559. return null;
  7560. }
  7561. try
  7562. {
  7563. twist = rules.GetVector3Item(idx++);
  7564. }
  7565. catch(InvalidCastException)
  7566. {
  7567. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TYPE, PRIM_TYPE_RING: arg #{1} - parameter 6 must be vector", rulesParsed, idx - idxStart - 1));
  7568. return null;
  7569. }
  7570. try
  7571. {
  7572. holesize = rules.GetVector3Item(idx++);
  7573. }
  7574. catch(InvalidCastException)
  7575. {
  7576. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TYPE, PRIM_TYPE_RING: arg #{1} - parameter 7 must be vector", rulesParsed, idx - idxStart - 1));
  7577. return null;
  7578. }
  7579. try
  7580. {
  7581. topshear = rules.GetVector3Item(idx++);
  7582. }
  7583. catch(InvalidCastException)
  7584. {
  7585. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TYPE, PRIM_TYPE_RING: arg #{1} - parameter 8 must be vector", rulesParsed, idx - idxStart - 1));
  7586. return null;
  7587. }
  7588. try
  7589. {
  7590. profilecut = rules.GetVector3Item(idx++);
  7591. }
  7592. catch(InvalidCastException)
  7593. {
  7594. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TYPE, PRIM_TYPE_RING: arg #{1} - parameter 9 must be vector", rulesParsed, idx - idxStart - 1));
  7595. return null;
  7596. }
  7597. try
  7598. {
  7599. taper_b = rules.GetVector3Item(idx++); // taper_a
  7600. }
  7601. catch(InvalidCastException)
  7602. {
  7603. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TYPE, PRIM_TYPE_RING: arg #{1} - parameter 10 must be vector", rulesParsed, idx - idxStart - 1));
  7604. return null;
  7605. }
  7606. try
  7607. {
  7608. revolutions = (float)rules.GetLSLFloatItem(idx++);
  7609. }
  7610. catch(InvalidCastException)
  7611. {
  7612. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TYPE, PRIM_TYPE_RING: arg #{1} - parameter 11 must be float", rulesParsed, idx - idxStart - 1));
  7613. return null;
  7614. }
  7615. try
  7616. {
  7617. radiusoffset = (float)rules.GetLSLFloatItem(idx++);
  7618. }
  7619. catch(InvalidCastException)
  7620. {
  7621. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TYPE, PRIM_TYPE_RING: arg #{1} - parameter 12 must be float", rulesParsed, idx - idxStart - 1));
  7622. return null;
  7623. }
  7624. try
  7625. {
  7626. skew = (float)rules.GetLSLFloatItem(idx++);
  7627. }
  7628. catch(InvalidCastException)
  7629. {
  7630. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TYPE, PRIM_TYPE_RING: arg #{1} - parameter 13 must be float", rulesParsed, idx - idxStart - 1));
  7631. return null;
  7632. }
  7633. SetPrimitiveShapeParams(part, face, v, hollow, twist, holesize, topshear, profilecut, taper_b,
  7634. revolutions, radiusoffset, skew, (byte)ProfileShape.EquilateralTriangle, (byte)Extrusion.Curve1);
  7635. break;
  7636. case ScriptBaseClass.PRIM_TYPE_SCULPT:
  7637. if (remain < 2)
  7638. return null;
  7639. string map = rules.Data[idx++].ToString();
  7640. try
  7641. {
  7642. face = (int)rules.GetLSLIntegerItem(idx++); // type
  7643. }
  7644. catch(InvalidCastException)
  7645. {
  7646. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TYPE, PRIM_TYPE_SCULPT: arg #{1} - parameter 4 must be integer", rulesParsed, idx - idxStart - 1));
  7647. return null;
  7648. }
  7649. SetPrimitiveShapeParams(part, map, face, (byte)Extrusion.Curve1);
  7650. break;
  7651. }
  7652. break;
  7653. case ScriptBaseClass.PRIM_TEXTURE:
  7654. if (remain < 5)
  7655. return null;
  7656. face=(int)rules.GetLSLIntegerItem(idx++);
  7657. string tex;
  7658. LSL_Vector repeats;
  7659. LSL_Vector offsets;
  7660. double rotation;
  7661. tex = rules.Data[idx++].ToString();
  7662. try
  7663. {
  7664. repeats = rules.GetVector3Item(idx++);
  7665. }
  7666. catch(InvalidCastException)
  7667. {
  7668. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TEXTURE: arg #{1} - parameter 3 must be vector", rulesParsed, idx - idxStart - 1));
  7669. return null;
  7670. }
  7671. try
  7672. {
  7673. offsets = rules.GetVector3Item(idx++);
  7674. }
  7675. catch(InvalidCastException)
  7676. {
  7677. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TEXTURE: arg #{1} - parameter 4 must be vector", rulesParsed, idx - idxStart - 1));
  7678. return null;
  7679. }
  7680. try
  7681. {
  7682. rotation = (double)rules.GetLSLFloatItem(idx++);
  7683. }
  7684. catch(InvalidCastException)
  7685. {
  7686. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TEXTURE: arg #{1} - parameter 5 must be float", rulesParsed, idx - idxStart - 1));
  7687. return null;
  7688. }
  7689. SetTexture(part, tex, face);
  7690. ScaleTexture(part, repeats.x, repeats.y, face);
  7691. OffsetTexture(part, offsets.x, offsets.y, face);
  7692. RotateTexture(part, rotation, face);
  7693. break;
  7694. case ScriptBaseClass.PRIM_COLOR:
  7695. if (remain < 3)
  7696. return null;
  7697. LSL_Vector color;
  7698. double alpha;
  7699. try
  7700. {
  7701. face = (int)rules.GetLSLIntegerItem(idx++);
  7702. }
  7703. catch(InvalidCastException)
  7704. {
  7705. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_COLOR: arg #{1} - parameter 2 must be integer", rulesParsed, idx - idxStart - 1));
  7706. return null;
  7707. }
  7708. try
  7709. {
  7710. color = rules.GetVector3Item(idx++);
  7711. }
  7712. catch(InvalidCastException)
  7713. {
  7714. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_COLOR: arg #{1} - parameter 3 must be vector", rulesParsed, idx - idxStart - 1));
  7715. return null;
  7716. }
  7717. try
  7718. {
  7719. alpha = (double)rules.GetLSLFloatItem(idx++);
  7720. }
  7721. catch(InvalidCastException)
  7722. {
  7723. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_COLOR: arg #{1} - parameter 4 must be float", rulesParsed, idx - idxStart - 1));
  7724. return null;
  7725. }
  7726. part.SetFaceColorAlpha(face, color, alpha);
  7727. break;
  7728. case ScriptBaseClass.PRIM_FLEXIBLE:
  7729. if (remain < 7)
  7730. return null;
  7731. bool flexi;
  7732. int softness;
  7733. float gravity;
  7734. float friction;
  7735. float wind;
  7736. float tension;
  7737. LSL_Vector force;
  7738. try
  7739. {
  7740. flexi = rules.GetLSLIntegerItem(idx++);
  7741. }
  7742. catch(InvalidCastException)
  7743. {
  7744. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_FLEXIBLE: arg #{1} - parameter 2 must be integer", rulesParsed, idx - idxStart - 1));
  7745. return null;
  7746. }
  7747. try
  7748. {
  7749. softness = rules.GetLSLIntegerItem(idx++);
  7750. }
  7751. catch(InvalidCastException)
  7752. {
  7753. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_FLEXIBLE: arg #{1} - parameter 3 must be integer", rulesParsed, idx - idxStart - 1));
  7754. return null;
  7755. }
  7756. try
  7757. {
  7758. gravity = (float)rules.GetLSLFloatItem(idx++);
  7759. }
  7760. catch(InvalidCastException)
  7761. {
  7762. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_FLEXIBLE: arg #{1} - parameter 4 must be float", rulesParsed, idx - idxStart - 1));
  7763. return null;
  7764. }
  7765. try
  7766. {
  7767. friction = (float)rules.GetLSLFloatItem(idx++);
  7768. }
  7769. catch(InvalidCastException)
  7770. {
  7771. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_FLEXIBLE: arg #{1} - parameter 5 must be float", rulesParsed, idx - idxStart - 1));
  7772. return null;
  7773. }
  7774. try
  7775. {
  7776. wind = (float)rules.GetLSLFloatItem(idx++);
  7777. }
  7778. catch(InvalidCastException)
  7779. {
  7780. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_FLEXIBLE: arg #{1} - parameter 6 must be float", rulesParsed, idx - idxStart - 1));
  7781. return null;
  7782. }
  7783. try
  7784. {
  7785. tension = (float)rules.GetLSLFloatItem(idx++);
  7786. }
  7787. catch(InvalidCastException)
  7788. {
  7789. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_FLEXIBLE: arg #{1} - parameter 7 must be float", rulesParsed, idx - idxStart - 1));
  7790. return null;
  7791. }
  7792. try
  7793. {
  7794. force = rules.GetVector3Item(idx++);
  7795. }
  7796. catch(InvalidCastException)
  7797. {
  7798. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_FLEXIBLE: arg #{1} - parameter 8 must be vector", rulesParsed, idx - idxStart - 1));
  7799. return null;
  7800. }
  7801. SetFlexi(part, flexi, softness, gravity, friction, wind, tension, force);
  7802. break;
  7803. case ScriptBaseClass.PRIM_POINT_LIGHT:
  7804. if (remain < 5)
  7805. return null;
  7806. bool light;
  7807. LSL_Vector lightcolor;
  7808. float intensity;
  7809. float radius;
  7810. float falloff;
  7811. try
  7812. {
  7813. light = rules.GetLSLIntegerItem(idx++);
  7814. }
  7815. catch(InvalidCastException)
  7816. {
  7817. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_POINT_LIGHT: arg #{1} - parameter 2 must be integer", rulesParsed, idx - idxStart - 1));
  7818. return null;
  7819. }
  7820. try
  7821. {
  7822. lightcolor = rules.GetVector3Item(idx++);
  7823. }
  7824. catch(InvalidCastException)
  7825. {
  7826. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_POINT_LIGHT: arg #{1} - parameter 3 must be vector", rulesParsed, idx - idxStart - 1));
  7827. return null;
  7828. }
  7829. try
  7830. {
  7831. intensity = (float)rules.GetLSLFloatItem(idx++);
  7832. }
  7833. catch(InvalidCastException)
  7834. {
  7835. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_POINT_LIGHT: arg #{1} - parameter 4 must be float", rulesParsed, idx - idxStart - 1));
  7836. return null;
  7837. }
  7838. try
  7839. {
  7840. radius = (float)rules.GetLSLFloatItem(idx++);
  7841. }
  7842. catch(InvalidCastException)
  7843. {
  7844. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_POINT_LIGHT: arg #{1} - parameter 5 must be float", rulesParsed, idx - idxStart - 1));
  7845. return null;
  7846. }
  7847. try
  7848. {
  7849. falloff = (float)rules.GetLSLFloatItem(idx++);
  7850. }
  7851. catch(InvalidCastException)
  7852. {
  7853. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_POINT_LIGHT: arg #{1} - parameter 6 must be float", rulesParsed, idx - idxStart - 1));
  7854. return null;
  7855. }
  7856. SetPointLight(part, light, lightcolor, intensity, radius, falloff);
  7857. break;
  7858. case ScriptBaseClass.PRIM_GLOW:
  7859. if (remain < 2)
  7860. return null;
  7861. float glow;
  7862. try
  7863. {
  7864. face = rules.GetLSLIntegerItem(idx++);
  7865. }
  7866. catch(InvalidCastException)
  7867. {
  7868. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_GLOW: arg #{1} - parameter 2 must be integer", rulesParsed, idx - idxStart - 1));
  7869. return null;
  7870. }
  7871. try
  7872. {
  7873. glow = (float)rules.GetLSLFloatItem(idx++);
  7874. }
  7875. catch(InvalidCastException)
  7876. {
  7877. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_GLOW: arg #{1} - parameter 3 must be float", rulesParsed, idx - idxStart - 1));
  7878. return null;
  7879. }
  7880. SetGlow(part, face, glow);
  7881. break;
  7882. case ScriptBaseClass.PRIM_BUMP_SHINY:
  7883. if (remain < 3)
  7884. return null;
  7885. int shiny;
  7886. Bumpiness bump;
  7887. try
  7888. {
  7889. face = (int)rules.GetLSLIntegerItem(idx++);
  7890. }
  7891. catch(InvalidCastException)
  7892. {
  7893. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_BUMP_SHINY: arg #{1} - parameter 2 must be integer", rulesParsed, idx - idxStart - 1));
  7894. return null;
  7895. }
  7896. try
  7897. {
  7898. shiny = (int)rules.GetLSLIntegerItem(idx++);
  7899. }
  7900. catch(InvalidCastException)
  7901. {
  7902. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_BUMP_SHINY: arg #{1} - parameter 3 must be integer", rulesParsed, idx - idxStart - 1));
  7903. return null;
  7904. }
  7905. try
  7906. {
  7907. bump = (Bumpiness)(int)rules.GetLSLIntegerItem(idx++);
  7908. }
  7909. catch(InvalidCastException)
  7910. {
  7911. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_BUMP_SHINY: arg #{1} - parameter 4 must be integer", rulesParsed, idx - idxStart - 1));
  7912. return null;
  7913. }
  7914. SetShiny(part, face, shiny, bump);
  7915. break;
  7916. case ScriptBaseClass.PRIM_FULLBRIGHT:
  7917. if (remain < 2)
  7918. return null;
  7919. bool st;
  7920. try
  7921. {
  7922. face = rules.GetLSLIntegerItem(idx++);
  7923. }
  7924. catch(InvalidCastException)
  7925. {
  7926. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_FULLBRIGHT: arg #{1} - parameter 2 must be integer", rulesParsed, idx - idxStart - 1));
  7927. return null;
  7928. }
  7929. try
  7930. {
  7931. st = rules.GetLSLIntegerItem(idx++);
  7932. }
  7933. catch(InvalidCastException)
  7934. {
  7935. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_FULLBRIGHT: arg #{1} - parameter 4 must be integer", rulesParsed, idx - idxStart - 1));
  7936. return null;
  7937. }
  7938. SetFullBright(part, face , st);
  7939. break;
  7940. case ScriptBaseClass.PRIM_MATERIAL:
  7941. if (remain < 1)
  7942. return null;
  7943. int mat;
  7944. try
  7945. {
  7946. mat = rules.GetLSLIntegerItem(idx++);
  7947. }
  7948. catch(InvalidCastException)
  7949. {
  7950. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_MATERIAL: arg #{1} - parameter 2 must be integer", rulesParsed, idx - idxStart - 1));
  7951. return null;
  7952. }
  7953. if (mat < 0 || mat > 7)
  7954. return null;
  7955. part.Material = Convert.ToByte(mat);
  7956. break;
  7957. case ScriptBaseClass.PRIM_PHANTOM:
  7958. if (remain < 1)
  7959. return null;
  7960. string ph = rules.Data[idx++].ToString();
  7961. part.ParentGroup.ScriptSetPhantomStatus(ph.Equals("1"));
  7962. break;
  7963. case ScriptBaseClass.PRIM_PHYSICS:
  7964. if (remain < 1)
  7965. return null;
  7966. string phy = rules.Data[idx++].ToString();
  7967. part.ScriptSetPhysicsStatus(phy.Equals("1"));
  7968. break;
  7969. case ScriptBaseClass.PRIM_PHYSICS_SHAPE_TYPE:
  7970. if (remain < 1)
  7971. return null;
  7972. int shape_type;
  7973. try
  7974. {
  7975. shape_type = rules.GetLSLIntegerItem(idx++);
  7976. }
  7977. catch(InvalidCastException)
  7978. {
  7979. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_PHYSICS_SHAPE_TYPE: arg #{1} - parameter 2 must be integer", rulesParsed, idx - idxStart - 1));
  7980. return null;
  7981. }
  7982. ExtraPhysicsData physdata = new ExtraPhysicsData();
  7983. physdata.Density = part.Density;
  7984. physdata.Bounce = part.Restitution;
  7985. physdata.GravitationModifier = part.GravityModifier;
  7986. physdata.PhysShapeType = (PhysShapeType)shape_type;
  7987. part.UpdateExtraPhysics(physdata);
  7988. break;
  7989. case ScriptBaseClass.PRIM_TEMP_ON_REZ:
  7990. if (remain < 1)
  7991. return null;
  7992. string temp = rules.Data[idx++].ToString();
  7993. part.ParentGroup.ScriptSetTemporaryStatus(temp.Equals("1"));
  7994. break;
  7995. case ScriptBaseClass.PRIM_TEXGEN:
  7996. if (remain < 2)
  7997. return null;
  7998. //face,type
  7999. int style;
  8000. try
  8001. {
  8002. face = rules.GetLSLIntegerItem(idx++);
  8003. }
  8004. catch(InvalidCastException)
  8005. {
  8006. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TEXGEN: arg #{1} - parameter 2 must be integer", rulesParsed, idx - idxStart - 1));
  8007. return null;
  8008. }
  8009. try
  8010. {
  8011. style = rules.GetLSLIntegerItem(idx++);
  8012. }
  8013. catch(InvalidCastException)
  8014. {
  8015. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TEXGEN: arg #{1} - parameter 3 must be integer", rulesParsed, idx - idxStart - 1));
  8016. return null;
  8017. }
  8018. SetTexGen(part, face, style);
  8019. break;
  8020. case ScriptBaseClass.PRIM_TEXT:
  8021. if (remain < 3)
  8022. return null;
  8023. string primText;
  8024. LSL_Vector primTextColor;
  8025. LSL_Float primTextAlpha;
  8026. try
  8027. {
  8028. primText = rules.GetLSLStringItem(idx++);
  8029. }
  8030. catch(InvalidCastException)
  8031. {
  8032. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TEXT: arg #{1} - parameter 2 must be string", rulesParsed, idx - idxStart - 1));
  8033. return null;
  8034. }
  8035. try
  8036. {
  8037. primTextColor = rules.GetVector3Item(idx++);
  8038. }
  8039. catch(InvalidCastException)
  8040. {
  8041. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TEXT: arg #{1} - parameter 3 must be vector", rulesParsed, idx - idxStart - 1));
  8042. return null;
  8043. }
  8044. try
  8045. {
  8046. primTextAlpha = rules.GetLSLFloatItem(idx++);
  8047. }
  8048. catch(InvalidCastException)
  8049. {
  8050. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TEXT: arg #{1} - parameter 4 must be float", rulesParsed, idx - idxStart - 1));
  8051. return null;
  8052. }
  8053. Vector3 av3 = Util.Clip(primTextColor, 0.0f, 1.0f);
  8054. part.SetText(primText, av3, Util.Clip((float)primTextAlpha, 0.0f, 1.0f));
  8055. break;
  8056. case ScriptBaseClass.PRIM_NAME:
  8057. if (remain < 1)
  8058. return null;
  8059. try
  8060. {
  8061. string primName = rules.GetLSLStringItem(idx++);
  8062. part.Name = primName;
  8063. }
  8064. catch(InvalidCastException)
  8065. {
  8066. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_NAME: arg #{1} - parameter 2 must be string", rulesParsed, idx - idxStart - 1));
  8067. return null;
  8068. }
  8069. break;
  8070. case ScriptBaseClass.PRIM_DESC:
  8071. if (remain < 1)
  8072. return null;
  8073. try
  8074. {
  8075. string primDesc = rules.GetLSLStringItem(idx++);
  8076. part.Description = primDesc;
  8077. }
  8078. catch(InvalidCastException)
  8079. {
  8080. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_DESC: arg #{1} - parameter 2 must be string", rulesParsed, idx - idxStart - 1));
  8081. return null;
  8082. }
  8083. break;
  8084. case ScriptBaseClass.PRIM_ROT_LOCAL:
  8085. if (remain < 1)
  8086. return null;
  8087. LSL_Rotation rot;
  8088. try
  8089. {
  8090. rot = rules.GetQuaternionItem(idx++);
  8091. }
  8092. catch(InvalidCastException)
  8093. {
  8094. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_ROT_LOCAL: arg #{1} - parameter 2 must be rotation", rulesParsed, idx - idxStart - 1));
  8095. return null;
  8096. }
  8097. SetRot(part, rot);
  8098. break;
  8099. case ScriptBaseClass.PRIM_OMEGA:
  8100. if (remain < 3)
  8101. return null;
  8102. LSL_Vector axis;
  8103. LSL_Float spinrate;
  8104. LSL_Float gain;
  8105. try
  8106. {
  8107. axis = rules.GetVector3Item(idx++);
  8108. }
  8109. catch(InvalidCastException)
  8110. {
  8111. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_OMEGA: arg #{1} - parameter 2 must be vector", rulesParsed, idx - idxStart - 1));
  8112. return null;
  8113. }
  8114. try
  8115. {
  8116. spinrate = rules.GetLSLFloatItem(idx++);
  8117. }
  8118. catch(InvalidCastException)
  8119. {
  8120. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_OMEGA: arg #{1} - parameter 3 must be float", rulesParsed, idx - idxStart - 1));
  8121. return null;
  8122. }
  8123. try
  8124. {
  8125. gain = rules.GetLSLFloatItem(idx++);
  8126. }
  8127. catch(InvalidCastException)
  8128. {
  8129. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_OMEGA: arg #{1} - parameter 4 must be float", rulesParsed, idx - idxStart - 1));
  8130. return null;
  8131. }
  8132. TargetOmega(part, axis, (double)spinrate, (double)gain);
  8133. break;
  8134. case ScriptBaseClass.PRIM_SLICE:
  8135. if (remain < 1)
  8136. return null;
  8137. LSL_Vector slice;
  8138. try
  8139. {
  8140. slice = rules.GetVector3Item(idx++);
  8141. }
  8142. catch(InvalidCastException)
  8143. {
  8144. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_SLICE: arg #{1} - parameter 2 must be vector", rulesParsed, idx - idxStart - 1));
  8145. return null;
  8146. }
  8147. part.UpdateSlice((float)slice.x, (float)slice.y);
  8148. break;
  8149. case ScriptBaseClass.PRIM_LINK_TARGET:
  8150. if (remain < 3) // setting to 3 on the basis that parsing any usage of PRIM_LINK_TARGET that has nothing following it is pointless.
  8151. return null;
  8152. return rules.GetSublist(idx, -1);
  8153. default:
  8154. Error(originFunc, string.Format("Error running rule #{0}: arg #{1} - unsupported parameter", rulesParsed, idx - idxStart));
  8155. return null;
  8156. }
  8157. }
  8158. }
  8159. catch (InvalidCastException e)
  8160. {
  8161. Error(originFunc, string.Format("Error running rule #{0}: arg #{1} - ", rulesParsed, idx - idxStart) + e.Message);
  8162. }
  8163. finally
  8164. {
  8165. if (positionChanged)
  8166. {
  8167. if (part.ParentGroup.RootPart == part)
  8168. {
  8169. SceneObjectGroup parent = part.ParentGroup;
  8170. parent.UpdateGroupPosition(currentPosition);
  8171. }
  8172. else
  8173. {
  8174. part.OffsetPosition = currentPosition;
  8175. SceneObjectGroup parent = part.ParentGroup;
  8176. parent.HasGroupChanged = true;
  8177. parent.ScheduleGroupForTerseUpdate();
  8178. }
  8179. }
  8180. }
  8181. return null;
  8182. }
  8183. protected LSL_List SetAgentParams(ScenePresence sp, LSL_List rules, string originFunc, ref uint rulesParsed)
  8184. {
  8185. int idx = 0;
  8186. int idxStart = 0;
  8187. try
  8188. {
  8189. while (idx < rules.Length)
  8190. {
  8191. ++rulesParsed;
  8192. int code = rules.GetLSLIntegerItem(idx++);
  8193. int remain = rules.Length - idx;
  8194. idxStart = idx;
  8195. switch (code)
  8196. {
  8197. case ScriptBaseClass.PRIM_POSITION:
  8198. case ScriptBaseClass.PRIM_POS_LOCAL:
  8199. if (remain < 1)
  8200. return null;
  8201. try
  8202. {
  8203. sp.OffsetPosition = rules.GetVector3Item(idx++);
  8204. }
  8205. catch(InvalidCastException)
  8206. {
  8207. if (code == ScriptBaseClass.PRIM_POSITION)
  8208. {
  8209. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_POSITION: arg #{1} - parameter 2 must be vector", rulesParsed, idx - idxStart - 1));
  8210. }
  8211. else
  8212. {
  8213. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_POS_LOCAL: arg #{1} - parameter 2 must be vector", rulesParsed, idx - idxStart - 1));
  8214. }
  8215. return null;
  8216. }
  8217. break;
  8218. case ScriptBaseClass.PRIM_ROTATION:
  8219. if (remain < 1)
  8220. return null;
  8221. Quaternion inRot;
  8222. try
  8223. {
  8224. inRot = rules.GetQuaternionItem(idx++);
  8225. }
  8226. catch(InvalidCastException)
  8227. {
  8228. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_ROTATION: arg #{1} - parameter 2 must be rotation", rulesParsed, idx - idxStart - 1));
  8229. return null;
  8230. }
  8231. SceneObjectPart parentPart = sp.ParentPart;
  8232. if (parentPart != null)
  8233. sp.Rotation = m_host.GetWorldRotation() * inRot;
  8234. break;
  8235. case ScriptBaseClass.PRIM_ROT_LOCAL:
  8236. if (remain < 1)
  8237. return null;
  8238. try
  8239. {
  8240. sp.Rotation = rules.GetQuaternionItem(idx++);
  8241. }
  8242. catch(InvalidCastException)
  8243. {
  8244. Error(originFunc, string.Format("Error running rule #{0} -> PRIM_ROT_LOCAL: arg #{1} - parameter 2 must be rotation", rulesParsed, idx - idxStart - 1));
  8245. return null;
  8246. }
  8247. break;
  8248. case ScriptBaseClass.PRIM_TYPE:
  8249. Error(originFunc, "PRIM_TYPE disallowed on agent");
  8250. return null;
  8251. case ScriptBaseClass.PRIM_OMEGA:
  8252. Error(originFunc, "PRIM_OMEGA disallowed on agent");
  8253. return null;
  8254. case ScriptBaseClass.PRIM_LINK_TARGET:
  8255. if (remain < 3) // setting to 3 on the basis that parsing any usage of PRIM_LINK_TARGET that has nothing following it is pointless.
  8256. return null;
  8257. return rules.GetSublist(idx, -1);
  8258. default:
  8259. Error(originFunc,
  8260. string.Format("Error running rule #{0} on agent: arg #{1} - disallowed on agent", rulesParsed, idx - idxStart));
  8261. return null;
  8262. }
  8263. }
  8264. }
  8265. catch (InvalidCastException e)
  8266. {
  8267. Error(
  8268. originFunc,
  8269. string.Format("Error running rule #{0}: arg #{1} - ", rulesParsed, idx - idxStart) + e.Message);
  8270. }
  8271. return null;
  8272. }
  8273. public LSL_String llStringToBase64(string str)
  8274. {
  8275. m_host.AddScriptLPS(1);
  8276. try
  8277. {
  8278. byte[] encData_byte;
  8279. encData_byte = Util.UTF8.GetBytes(str);
  8280. string encodedData = Convert.ToBase64String(encData_byte);
  8281. return encodedData;
  8282. }
  8283. catch
  8284. {
  8285. Error("llBase64ToString", "Error encoding string");
  8286. return String.Empty;
  8287. }
  8288. }
  8289. public LSL_String llBase64ToString(string str)
  8290. {
  8291. m_host.AddScriptLPS(1);
  8292. try
  8293. {
  8294. byte[] b = Convert.FromBase64String(str);
  8295. return Encoding.UTF8.GetString(b);
  8296. }
  8297. catch
  8298. {
  8299. Error("llBase64ToString", "Error decoding string");
  8300. return String.Empty;
  8301. }
  8302. }
  8303. public LSL_String llXorBase64Strings(string str1, string str2)
  8304. {
  8305. m_host.AddScriptLPS(1);
  8306. Deprecated("llXorBase64Strings", "Use llXorBase64 instead");
  8307. ScriptSleep(m_sleepMsOnXorBase64Strings);
  8308. return String.Empty;
  8309. }
  8310. public void llRemoteDataSetRegion()
  8311. {
  8312. m_host.AddScriptLPS(1);
  8313. Deprecated("llRemoteDataSetRegion", "Use llOpenRemoteDataChannel instead");
  8314. }
  8315. public LSL_Float llLog10(double val)
  8316. {
  8317. m_host.AddScriptLPS(1);
  8318. return (double)Math.Log10(val);
  8319. }
  8320. public LSL_Float llLog(double val)
  8321. {
  8322. m_host.AddScriptLPS(1);
  8323. return (double)Math.Log(val);
  8324. }
  8325. public LSL_List llGetAnimationList(string id)
  8326. {
  8327. m_host.AddScriptLPS(1);
  8328. LSL_List l = new LSL_List();
  8329. ScenePresence av = World.GetScenePresence((UUID)id);
  8330. if (av == null || av.IsChildAgent) // only if in the region
  8331. return l;
  8332. UUID[] anims;
  8333. anims = av.Animator.GetAnimationArray();
  8334. foreach (UUID foo in anims)
  8335. l.Add(new LSL_Key(foo.ToString()));
  8336. return l;
  8337. }
  8338. public void llSetParcelMusicURL(string url)
  8339. {
  8340. m_host.AddScriptLPS(1);
  8341. ILandObject land = World.LandChannel.GetLandObject(m_host.AbsolutePosition);
  8342. if (land.LandData.OwnerID != m_host.OwnerID)
  8343. return;
  8344. land.SetMusicUrl(url);
  8345. ScriptSleep(m_sleepMsOnSetParcelMusicURL);
  8346. }
  8347. public LSL_String llGetParcelMusicURL()
  8348. {
  8349. m_host.AddScriptLPS(1);
  8350. ILandObject land = World.LandChannel.GetLandObject(m_host.AbsolutePosition);
  8351. if (land.LandData.OwnerID != m_host.OwnerID)
  8352. return String.Empty;
  8353. return land.GetMusicUrl();
  8354. }
  8355. public LSL_Vector llGetRootPosition()
  8356. {
  8357. m_host.AddScriptLPS(1);
  8358. return new LSL_Vector(m_host.ParentGroup.AbsolutePosition);
  8359. }
  8360. /// <summary>
  8361. /// http://lslwiki.net/lslwiki/wakka.php?wakka=llGetRot
  8362. /// http://lslwiki.net/lslwiki/wakka.php?wakka=ChildRotation
  8363. /// Also tested in sl in regards to the behaviour in attachments/mouselook
  8364. /// In the root prim:-
  8365. /// Returns the object rotation if not attached
  8366. /// Returns the avatars rotation if attached
  8367. /// Returns the camera rotation if attached and the avatar is in mouselook
  8368. /// </summary>
  8369. public LSL_Rotation llGetRootRotation()
  8370. {
  8371. m_host.AddScriptLPS(1);
  8372. Quaternion q;
  8373. if (m_host.ParentGroup.AttachmentPoint != 0)
  8374. {
  8375. ScenePresence avatar = World.GetScenePresence(m_host.ParentGroup.AttachedAvatar);
  8376. if (avatar != null)
  8377. if ((avatar.AgentControlFlags & (uint)AgentManager.ControlFlags.AGENT_CONTROL_MOUSELOOK) != 0)
  8378. q = avatar.CameraRotation; // Mouselook
  8379. else
  8380. q = avatar.GetWorldRotation(); // Currently infrequently updated so may be inaccurate
  8381. else
  8382. q = m_host.ParentGroup.GroupRotation; // Likely never get here but just in case
  8383. }
  8384. else
  8385. q = m_host.ParentGroup.GroupRotation; // just the group rotation
  8386. return new LSL_Rotation(q);
  8387. }
  8388. public LSL_String llGetObjectDesc()
  8389. {
  8390. return m_host.Description!=null?m_host.Description:String.Empty;
  8391. }
  8392. public void llSetObjectDesc(string desc)
  8393. {
  8394. m_host.AddScriptLPS(1);
  8395. m_host.Description = desc!=null?desc:String.Empty;
  8396. }
  8397. public LSL_String llGetCreator()
  8398. {
  8399. m_host.AddScriptLPS(1);
  8400. return m_host.CreatorID.ToString();
  8401. }
  8402. public LSL_String llGetTimestamp()
  8403. {
  8404. m_host.AddScriptLPS(1);
  8405. return DateTime.Now.ToUniversalTime().ToString("yyyy-MM-ddTHH:mm:ss.fffffffZ");
  8406. }
  8407. public LSL_Integer llGetNumberOfPrims()
  8408. {
  8409. m_host.AddScriptLPS(1);
  8410. return m_host.ParentGroup.PrimCount + m_host.ParentGroup.GetSittingAvatarsCount();
  8411. }
  8412. /// <summary>
  8413. /// Full implementation of llGetBoundingBox according to SL 2015-04-15.
  8414. /// http://wiki.secondlife.com/wiki/LlGetBoundingBox
  8415. /// http://lslwiki.net/lslwiki/wakka.php?wakka=llGetBoundingBox
  8416. /// Returns local bounding box of avatar without attachments
  8417. /// if target is non-seated avatar or prim/mesh in avatar attachment.
  8418. /// Returns local bounding box of object including seated avatars
  8419. /// if target is seated avatar or prim/mesh in object.
  8420. /// Uses meshing of prims for high accuracy
  8421. /// or less accurate box models for speed.
  8422. /// </summary>
  8423. public LSL_List llGetBoundingBox(string obj)
  8424. {
  8425. m_host.AddScriptLPS(1);
  8426. // Get target avatar if non-seated avatar or attachment, or prim and object
  8427. UUID objID = UUID.Zero;
  8428. UUID.TryParse(obj, out objID);
  8429. ScenePresence agent = World.GetScenePresence(objID);
  8430. if (agent != null)
  8431. {
  8432. if (agent.ParentPart != null)
  8433. {
  8434. objID = agent.ParentPart.UUID;
  8435. agent = null;
  8436. }
  8437. }
  8438. SceneObjectGroup group = null;
  8439. SceneObjectPart target = World.GetSceneObjectPart(objID);
  8440. if (target != null)
  8441. {
  8442. group = target.ParentGroup;
  8443. if (group.IsAttachment) {
  8444. objID = group.AttachedAvatar;
  8445. agent = World.GetScenePresence(objID);
  8446. group = null;
  8447. target = null;
  8448. }
  8449. }
  8450. // Initialize but break if no target
  8451. LSL_List result = new LSL_List();
  8452. int groupCount = 0;
  8453. int partCount = 0;
  8454. int vertexCount = 0;
  8455. if (target == null && agent == null)
  8456. {
  8457. result.Add(new LSL_Vector());
  8458. result.Add(new LSL_Vector());
  8459. if (m_addStatsInGetBoundingBox)
  8460. result.Add(new LSL_Vector((float)groupCount, (float)partCount, (float)vertexCount));
  8461. return result;
  8462. }
  8463. Vector3 minPosition = new Vector3(float.MaxValue, float.MaxValue, float.MaxValue);
  8464. Vector3 maxPosition = new Vector3(float.MinValue, float.MinValue, float.MinValue);
  8465. // Try to get a mesher
  8466. IRendering primMesher = null;
  8467. List<string> renderers = RenderingLoader.ListRenderers(Util.ExecutingDirectory());
  8468. if (renderers.Count > 0)
  8469. primMesher = RenderingLoader.LoadRenderer(renderers[0]);
  8470. // Get bounding box of just avatar, seated or not
  8471. if (agent != null)
  8472. {
  8473. bool hasParent = false;
  8474. Vector3 lower;
  8475. Vector3 upper;
  8476. BoundingBoxOfScenePresence(agent, out lower, out upper);
  8477. Vector3 offset = Vector3.Zero;
  8478. // Since local bounding box unrotated and untilted, keep it simple
  8479. AddBoundingBoxOfSimpleBox(lower, upper, offset, agent.Rotation, hasParent, ref minPosition, ref maxPosition, ref vertexCount);
  8480. partCount++;
  8481. groupCount++;
  8482. // Return lower and upper bounding box corners
  8483. result.Add(new LSL_Vector(minPosition));
  8484. result.Add(new LSL_Vector(maxPosition));
  8485. if (m_addStatsInGetBoundingBox)
  8486. result.Add(new LSL_Vector((float)groupCount, (float)partCount, (float)vertexCount));
  8487. return result;
  8488. }
  8489. // Get bounding box of object including seated avatars
  8490. else if (group != null)
  8491. {
  8492. // Merge bounding boxes of all parts (prims and mesh)
  8493. foreach (SceneObjectPart part in group.Parts)
  8494. {
  8495. bool hasParent = (!part.IsRoot);
  8496. // When requested or if no mesher, keep it simple
  8497. if (m_useSimpleBoxesInGetBoundingBox || primMesher == null)
  8498. {
  8499. AddBoundingBoxOfSimpleBox(part.Scale * -0.5f, part.Scale * 0.5f, part.OffsetPosition, part.RotationOffset, hasParent, ref minPosition, ref maxPosition, ref vertexCount);
  8500. }
  8501. // Do the full mounty
  8502. else
  8503. {
  8504. Primitive omvPrim = part.Shape.ToOmvPrimitive(part.OffsetPosition, part.RotationOffset);
  8505. byte[] sculptAsset = null;
  8506. if (omvPrim.Sculpt != null)
  8507. sculptAsset = World.AssetService.GetData(omvPrim.Sculpt.SculptTexture.ToString());
  8508. // When part is mesh
  8509. // Quirk: Only imports as incompletely populated faceted mesh object, so needs an own handler.
  8510. if (omvPrim.Sculpt != null && omvPrim.Sculpt.Type == SculptType.Mesh && sculptAsset != null)
  8511. {
  8512. AssetMesh meshAsset = new AssetMesh(omvPrim.Sculpt.SculptTexture, sculptAsset);
  8513. FacetedMesh mesh = null;
  8514. FacetedMesh.TryDecodeFromAsset(omvPrim, meshAsset, DetailLevel.Highest, out mesh);
  8515. meshAsset = null;
  8516. if (mesh != null)
  8517. {
  8518. AddBoundingBoxOfFacetedMesh(mesh, omvPrim, hasParent, ref minPosition, ref maxPosition, ref vertexCount);
  8519. mesh = null;
  8520. }
  8521. }
  8522. // When part is sculpt
  8523. // Quirk: Generated sculpt mesh is about 2.8% smaller in X and Y than visual sculpt.
  8524. else if (omvPrim.Sculpt != null && omvPrim.Sculpt.Type != SculptType.Mesh && sculptAsset != null)
  8525. {
  8526. IJ2KDecoder imgDecoder = World.RequestModuleInterface<IJ2KDecoder>();
  8527. if (imgDecoder != null)
  8528. {
  8529. Image sculpt = imgDecoder.DecodeToImage(sculptAsset);
  8530. if (sculpt != null)
  8531. {
  8532. SimpleMesh mesh = primMesher.GenerateSimpleSculptMesh(omvPrim, (Bitmap)sculpt, DetailLevel.Medium);
  8533. sculpt.Dispose();
  8534. if (mesh != null)
  8535. {
  8536. AddBoundingBoxOfSimpleMesh(mesh, omvPrim, hasParent, ref minPosition, ref maxPosition, ref vertexCount);
  8537. mesh = null;
  8538. }
  8539. }
  8540. }
  8541. }
  8542. // When part is prim
  8543. else if (omvPrim.Sculpt == null)
  8544. {
  8545. SimpleMesh mesh = primMesher.GenerateSimpleMesh(omvPrim, DetailLevel.Medium);
  8546. if (mesh != null)
  8547. {
  8548. AddBoundingBoxOfSimpleMesh(mesh, omvPrim, hasParent, ref minPosition, ref maxPosition, ref vertexCount);
  8549. mesh = null;
  8550. }
  8551. }
  8552. // When all else fails, try fallback to simple box
  8553. else
  8554. {
  8555. AddBoundingBoxOfSimpleBox(part.Scale * -0.5f, part.Scale * 0.5f, part.OffsetPosition, part.RotationOffset, hasParent, ref minPosition, ref maxPosition, ref vertexCount);
  8556. }
  8557. }
  8558. partCount++;
  8559. }
  8560. }
  8561. // Merge bounding boxes of seated avatars
  8562. foreach (ScenePresence sp in group.GetSittingAvatars())
  8563. {
  8564. Vector3 lower;
  8565. Vector3 upper;
  8566. BoundingBoxOfScenePresence(sp, out lower, out upper);
  8567. Vector3 offset = sp.OffsetPosition;
  8568. bool hasParent = true;
  8569. // When requested or if no mesher, keep it simple
  8570. if (m_useSimpleBoxesInGetBoundingBox || primMesher == null)
  8571. {
  8572. AddBoundingBoxOfSimpleBox(lower, upper, offset, sp.Rotation, hasParent, ref minPosition, ref maxPosition, ref vertexCount);
  8573. }
  8574. // Do the full mounty
  8575. else
  8576. {
  8577. // Prim shapes don't do center offsets, so add it here.
  8578. offset = offset + (lower + upper) * 0.5f * sp.Rotation;
  8579. Primitive omvPrim = MakeOpenMetaversePrim(upper - lower, offset, sp.Rotation, ScriptBaseClass.PRIM_TYPE_SPHERE);
  8580. SimpleMesh mesh = primMesher.GenerateSimpleMesh(omvPrim, DetailLevel.Medium);
  8581. AddBoundingBoxOfSimpleMesh(mesh, omvPrim, hasParent, ref minPosition, ref maxPosition, ref vertexCount);
  8582. mesh = null;
  8583. }
  8584. partCount++;
  8585. }
  8586. groupCount++;
  8587. // Return lower and upper bounding box corners
  8588. result.Add(new LSL_Vector(minPosition));
  8589. result.Add(new LSL_Vector(maxPosition));
  8590. if (m_addStatsInGetBoundingBox)
  8591. result.Add(new LSL_Vector((float)groupCount, (float)partCount, (float)vertexCount));
  8592. primMesher = null;
  8593. return result;
  8594. }
  8595. /// <summary>
  8596. /// Helper to calculate bounding box of an avatar.
  8597. /// </summary>
  8598. private void BoundingBoxOfScenePresence(ScenePresence sp, out Vector3 lower, out Vector3 upper)
  8599. {
  8600. // Adjust from OS model
  8601. // avatar height = visual height - 0.2, bounding box height = visual height
  8602. // to SL model
  8603. // avatar height = visual height, bounding box height = visual height + 0.2
  8604. float height = sp.Appearance.AvatarHeight + m_avatarHeightCorrection;
  8605. // According to avatar bounding box in SL 2015-04-18:
  8606. // standing = <-0.275,-0.35,-0.1-0.5*h> : <0.275,0.35,0.1+0.5*h>
  8607. // groundsitting = <-0.3875,-0.5,-0.05-0.375*h> : <0.3875,0.5,0.5>
  8608. // sitting = <-0.5875,-0.35,-0.35-0.375*h> : <0.1875,0.35,-0.25+0.25*h>
  8609. // When avatar is sitting
  8610. if (sp.ParentPart != null)
  8611. {
  8612. lower = new Vector3(m_lABB1SitX0, m_lABB1SitY0, m_lABB1SitZ0 + m_lABB1SitZ1 * height);
  8613. upper = new Vector3(m_lABB2SitX0, m_lABB2SitY0, m_lABB2SitZ0 + m_lABB2SitZ1 * height);
  8614. }
  8615. // When avatar is groundsitting
  8616. else if (sp.Animator.Animations.ImplicitDefaultAnimation.AnimID == DefaultAvatarAnimations.AnimsUUID["SIT_GROUND_CONSTRAINED"])
  8617. {
  8618. lower = new Vector3(m_lABB1GrsX0, m_lABB1GrsY0, m_lABB1GrsZ0 + m_lABB1GrsZ1 * height);
  8619. upper = new Vector3(m_lABB2GrsX0, m_lABB2GrsY0, m_lABB2GrsZ0 + m_lABB2GrsZ1 * height);
  8620. }
  8621. // When avatar is standing or flying
  8622. else
  8623. {
  8624. lower = new Vector3(m_lABB1StdX0, m_lABB1StdY0, m_lABB1StdZ0 + m_lABB1StdZ1 * height);
  8625. upper = new Vector3(m_lABB2StdX0, m_lABB2StdY0, m_lABB2StdZ0 + m_lABB2StdZ1 * height);
  8626. }
  8627. }
  8628. /// <summary>
  8629. /// Helper to approximate a part with a simple box.
  8630. /// </summary>
  8631. private void AddBoundingBoxOfSimpleBox(Vector3 corner1, Vector3 corner2, Vector3 offset, Quaternion rotation, bool hasParent, ref Vector3 lower, ref Vector3 upper, ref int count)
  8632. {
  8633. // Parse the 8 box corners
  8634. for (int i = 0; i < 8; i++)
  8635. {
  8636. // Calculate each box corner
  8637. Vector3 position = corner1;
  8638. if ((i & 1) != 0)
  8639. position.X = corner2.X;
  8640. if ((i & 2) != 0)
  8641. position.Y = corner2.Y;
  8642. if ((i & 4) != 0)
  8643. position.Z = corner2.Z;
  8644. // Rotate part unless part is root
  8645. if (hasParent)
  8646. position = position * rotation;
  8647. position = position + offset;
  8648. // Adjust lower and upper bounding box corners if needed
  8649. lower = Vector3.Min(lower, position);
  8650. upper = Vector3.Max(upper, position);
  8651. count++;
  8652. }
  8653. }
  8654. /// <summary>
  8655. /// Helper to parse a meshed prim and needed especially
  8656. /// for accuracy with tortured prims and sculpts.
  8657. /// </summary>
  8658. private void AddBoundingBoxOfSimpleMesh(SimpleMesh mesh, Primitive prim, bool hasParent, ref Vector3 lower, ref Vector3 upper, ref int count)
  8659. {
  8660. // Quirk: A meshed box contains 10 instead of the 8 necessary vertices.
  8661. if (mesh != null)
  8662. {
  8663. // Parse each vertex in mesh
  8664. foreach (Vertex vertex in mesh.Vertices)
  8665. {
  8666. Vector3 position = vertex.Position;
  8667. position = position * prim.Scale;
  8668. // Rotate part unless part is root
  8669. if (hasParent)
  8670. position = position * prim.Rotation;
  8671. position = position + prim.Position;
  8672. // Adjust lower and upper bounding box corners if needed
  8673. lower = Vector3.Min(lower, position);
  8674. upper = Vector3.Max(upper, position);
  8675. count++;
  8676. }
  8677. }
  8678. }
  8679. /// <summary>
  8680. /// Helper to parse mesh because no method exists
  8681. /// to parse mesh assets to SimpleMesh.
  8682. /// </summary>
  8683. private void AddBoundingBoxOfFacetedMesh(FacetedMesh mesh, Primitive prim, bool hasParent, ref Vector3 lower, ref Vector3 upper, ref int count)
  8684. {
  8685. if (mesh != null)
  8686. {
  8687. // Parse each face in mesh
  8688. // since vertex array isn't populated.
  8689. // This parses each unique vertex 3-6 times.
  8690. foreach (Face face in mesh.Faces)
  8691. {
  8692. // Parse each vertex in face
  8693. foreach (Vertex vertex in face.Vertices)
  8694. {
  8695. Vector3 position = vertex.Position;
  8696. position = position * prim.Scale;
  8697. // Rotate part unless part is root
  8698. if (hasParent)
  8699. position = position * prim.Rotation;
  8700. position = position + prim.Position;
  8701. // Adjust lower and upper bounding box corners if needed
  8702. lower = Vector3.Min(lower, position);
  8703. upper = Vector3.Max(upper, position);
  8704. count++;
  8705. }
  8706. }
  8707. }
  8708. }
  8709. /// <summary>
  8710. /// Helper to make up an OpenMetaverse prim
  8711. /// needed to create mesh from parts.
  8712. /// </summary>
  8713. private Primitive MakeOpenMetaversePrim(Vector3 scale, Vector3 position, Quaternion rotation, int primType)
  8714. {
  8715. // Initialize and set common parameters
  8716. Primitive prim = new OpenMetaverse.Primitive();
  8717. prim.Scale = scale;
  8718. prim.Position = position;
  8719. prim.Rotation = rotation;
  8720. prim.PrimData.PathShearX = 0.0f;
  8721. prim.PrimData.PathShearY = 0.0f;
  8722. prim.PrimData.PathBegin = 0.0f;
  8723. prim.PrimData.PathEnd = 1.0f;
  8724. prim.PrimData.PathScaleX = 1.0f;
  8725. prim.PrimData.PathScaleY = 1.0f;
  8726. prim.PrimData.PathTaperX = 0.0f;
  8727. prim.PrimData.PathTaperY = 0.0f;
  8728. prim.PrimData.PathTwistBegin = 0.0f;
  8729. prim.PrimData.PathTwist = 0.0f;
  8730. prim.PrimData.ProfileBegin = 0.0f;
  8731. prim.PrimData.ProfileEnd = 1.0f;
  8732. prim.PrimData.ProfileHollow = 0.0f;
  8733. prim.PrimData.ProfileCurve = (ProfileCurve)1;
  8734. prim.PrimData.ProfileHole = (HoleType)0;
  8735. prim.PrimData.PathCurve = (PathCurve)16;
  8736. prim.PrimData.PathRadiusOffset = 0.0f;
  8737. prim.PrimData.PathRevolutions = 1.0f;
  8738. prim.PrimData.PathSkew = 0.0f;
  8739. prim.PrimData.PCode = OpenMetaverse.PCode.Prim;
  8740. prim.PrimData.State = (byte)0;
  8741. // Set type specific parameters
  8742. switch (primType)
  8743. {
  8744. // Set specific parameters for box
  8745. case ScriptBaseClass.PRIM_TYPE_BOX:
  8746. prim.PrimData.PathScaleY = 1.0f;
  8747. prim.PrimData.ProfileCurve = (ProfileCurve)1;
  8748. prim.PrimData.PathCurve = (PathCurve)16;
  8749. break;
  8750. // Set specific parameters for cylinder
  8751. case ScriptBaseClass.PRIM_TYPE_CYLINDER:
  8752. prim.PrimData.PathScaleY = 1.0f;
  8753. prim.PrimData.ProfileCurve = (ProfileCurve)0;
  8754. prim.PrimData.PathCurve = (PathCurve)16;
  8755. break;
  8756. // Set specific parameters for prism
  8757. case ScriptBaseClass.PRIM_TYPE_PRISM:
  8758. prim.PrimData.PathScaleY = 1.0f;
  8759. prim.PrimData.ProfileCurve = (ProfileCurve)3;
  8760. prim.PrimData.PathCurve = (PathCurve)16;
  8761. break;
  8762. // Set specific parameters for sphere
  8763. case ScriptBaseClass.PRIM_TYPE_SPHERE:
  8764. prim.PrimData.PathScaleY = 1.0f;
  8765. prim.PrimData.ProfileCurve = (ProfileCurve)5;
  8766. prim.PrimData.PathCurve = (PathCurve)32;
  8767. break;
  8768. // Set specific parameters for torus
  8769. case ScriptBaseClass.PRIM_TYPE_TORUS:
  8770. prim.PrimData.PathScaleY = 0.5f;
  8771. prim.PrimData.ProfileCurve = (ProfileCurve)0;
  8772. prim.PrimData.PathCurve = (PathCurve)32;
  8773. break;
  8774. // Set specific parameters for tube
  8775. case ScriptBaseClass.PRIM_TYPE_TUBE:
  8776. prim.PrimData.PathScaleY = 0.5f;
  8777. prim.PrimData.ProfileCurve = (ProfileCurve)1;
  8778. prim.PrimData.PathCurve = (PathCurve)32;
  8779. break;
  8780. // Set specific parameters for ring
  8781. case ScriptBaseClass.PRIM_TYPE_RING:
  8782. prim.PrimData.PathScaleY = 0.5f;
  8783. prim.PrimData.ProfileCurve = (ProfileCurve)3;
  8784. prim.PrimData.PathCurve = (PathCurve)32;
  8785. break;
  8786. // Set specific parameters for sculpt
  8787. case ScriptBaseClass.PRIM_TYPE_SCULPT:
  8788. prim.PrimData.PathScaleY = 1.0f;
  8789. prim.PrimData.ProfileCurve = (ProfileCurve)5;
  8790. prim.PrimData.PathCurve = (PathCurve)32;
  8791. break;
  8792. // Default to specific parameters for box
  8793. default:
  8794. prim.PrimData.PathScaleY = 1.0f;
  8795. prim.PrimData.ProfileCurve = (ProfileCurve)1;
  8796. prim.PrimData.PathCurve = (PathCurve)16;
  8797. break;
  8798. }
  8799. return prim;
  8800. }
  8801. /// <summary>
  8802. /// Implementation of llGetGeometricCenter according to SL 2015-04-30.
  8803. /// http://wiki.secondlife.com/wiki/LlGetGeometricCenter
  8804. /// Returns the average position offset of all linked parts,
  8805. /// including the root prim and seated avatars,
  8806. /// relative to the root prim in local coordinates.
  8807. /// </summary>
  8808. public LSL_Vector llGetGeometricCenter()
  8809. {
  8810. // Subtract whatever position the root prim has to make it zero
  8811. Vector3 offset = m_host.ParentGroup.RootPart.OffsetPosition * -1.0f;
  8812. // Add all prim/part position offsets
  8813. foreach (SceneObjectPart part in m_host.ParentGroup.Parts)
  8814. offset = offset + part.OffsetPosition;
  8815. // Add all avatar/scene presence position offsets
  8816. foreach (ScenePresence sp in m_host.ParentGroup.GetSittingAvatars())
  8817. offset = offset + sp.OffsetPosition;
  8818. // Calculate and return the average offset
  8819. offset = offset / (float)(m_host.ParentGroup.PrimCount + m_host.ParentGroup.GetSittingAvatarsCount());
  8820. return new LSL_Vector(offset);
  8821. }
  8822. public LSL_List GetEntityParams(ISceneEntity entity, LSL_List rules)
  8823. {
  8824. LSL_List result = new LSL_List();
  8825. LSL_List remaining = null;
  8826. while (true)
  8827. {
  8828. // m_log.DebugFormat(
  8829. // "[LSL API]: GetEntityParams has {0} rules with scene entity named {1}",
  8830. // rules.Length, entity != null ? entity.Name : "NULL");
  8831. if (entity == null)
  8832. return result;
  8833. if (entity is SceneObjectPart)
  8834. remaining = GetPrimParams((SceneObjectPart)entity, rules, ref result);
  8835. else
  8836. remaining = GetAgentParams((ScenePresence)entity, rules, ref result);
  8837. if (remaining == null || remaining.Length < 2)
  8838. return result;
  8839. int linknumber = remaining.GetLSLIntegerItem(0);
  8840. rules = remaining.GetSublist(1, -1);
  8841. entity = GetLinkEntity(m_host, linknumber);
  8842. }
  8843. }
  8844. public LSL_List llGetPrimitiveParams(LSL_List rules)
  8845. {
  8846. m_host.AddScriptLPS(1);
  8847. return GetEntityParams(m_host, rules);
  8848. }
  8849. public LSL_List llGetLinkPrimitiveParams(int linknumber, LSL_List rules)
  8850. {
  8851. m_host.AddScriptLPS(1);
  8852. return GetEntityParams(GetLinkEntity(m_host, linknumber), rules);
  8853. }
  8854. public LSL_Vector GetAgentSize(ScenePresence sp)
  8855. {
  8856. return new LSL_Vector(0.45, 0.6, sp.Appearance.AvatarHeight);
  8857. }
  8858. /// <summary>
  8859. /// Gets params for a seated avatar in a linkset.
  8860. /// </summary>
  8861. /// <returns></returns>
  8862. /// <param name='sp'></param>
  8863. /// <param name='rules'></param>
  8864. /// <param name='res'></param>
  8865. public LSL_List GetAgentParams(ScenePresence sp, LSL_List rules, ref LSL_List res)
  8866. {
  8867. int idx = 0;
  8868. while (idx < rules.Length)
  8869. {
  8870. int code = (int)rules.GetLSLIntegerItem(idx++);
  8871. int remain = rules.Length-idx;
  8872. switch (code)
  8873. {
  8874. case (int)ScriptBaseClass.PRIM_MATERIAL:
  8875. res.Add(new LSL_Integer(ScriptBaseClass.PRIM_MATERIAL_FLESH));
  8876. break;
  8877. case (int)ScriptBaseClass.PRIM_PHYSICS:
  8878. res.Add(ScriptBaseClass.FALSE);
  8879. break;
  8880. case (int)ScriptBaseClass.PRIM_TEMP_ON_REZ:
  8881. res.Add(ScriptBaseClass.FALSE);
  8882. break;
  8883. case (int)ScriptBaseClass.PRIM_PHANTOM:
  8884. res.Add(ScriptBaseClass.FALSE);
  8885. break;
  8886. case (int)ScriptBaseClass.PRIM_POSITION:
  8887. res.Add(new LSL_Vector(sp.AbsolutePosition));
  8888. break;
  8889. case (int)ScriptBaseClass.PRIM_SIZE:
  8890. res.Add(GetAgentSize(sp));
  8891. break;
  8892. case (int)ScriptBaseClass.PRIM_ROTATION:
  8893. res.Add(sp.GetWorldRotation());
  8894. break;
  8895. case (int)ScriptBaseClass.PRIM_TYPE:
  8896. res.Add(new LSL_Integer(ScriptBaseClass.PRIM_TYPE_BOX));
  8897. res.Add(new LSL_Integer(ScriptBaseClass.PRIM_HOLE_DEFAULT));
  8898. res.Add(new LSL_Vector(0, 1, 0));
  8899. res.Add(new LSL_Float(0));
  8900. res.Add(new LSL_Vector(0, 0, 0));
  8901. res.Add(new LSL_Vector(1, 1, 0));
  8902. res.Add(new LSL_Vector(0, 0, 0));
  8903. break;
  8904. case (int)ScriptBaseClass.PRIM_TEXTURE:
  8905. if (remain < 1)
  8906. return null;
  8907. int face = (int)rules.GetLSLIntegerItem(idx++);
  8908. if (face > 21)
  8909. break;
  8910. res.Add(new LSL_String(""));
  8911. res.Add(ScriptBaseClass.ZERO_VECTOR);
  8912. res.Add(ScriptBaseClass.ZERO_VECTOR);
  8913. res.Add(new LSL_Float(0));
  8914. break;
  8915. case (int)ScriptBaseClass.PRIM_COLOR:
  8916. if (remain < 1)
  8917. return null;
  8918. face = (int)rules.GetLSLIntegerItem(idx++);
  8919. if (face > 21)
  8920. break;
  8921. res.Add(ScriptBaseClass.ZERO_VECTOR);
  8922. res.Add(new LSL_Float(0));
  8923. break;
  8924. case (int)ScriptBaseClass.PRIM_BUMP_SHINY:
  8925. if (remain < 1)
  8926. return null;
  8927. face = (int)rules.GetLSLIntegerItem(idx++);
  8928. if (face > 21)
  8929. break;
  8930. res.Add(ScriptBaseClass.PRIM_SHINY_NONE);
  8931. res.Add(ScriptBaseClass.PRIM_BUMP_NONE);
  8932. break;
  8933. case (int)ScriptBaseClass.PRIM_FULLBRIGHT:
  8934. if (remain < 1)
  8935. return null;
  8936. face = (int)rules.GetLSLIntegerItem(idx++);
  8937. if (face > 21)
  8938. break;
  8939. res.Add(ScriptBaseClass.FALSE);
  8940. break;
  8941. case (int)ScriptBaseClass.PRIM_FLEXIBLE:
  8942. res.Add(ScriptBaseClass.FALSE);
  8943. res.Add(new LSL_Integer(0));
  8944. res.Add(new LSL_Float(0));
  8945. res.Add(new LSL_Float(0));
  8946. res.Add(new LSL_Float(0));
  8947. res.Add(new LSL_Float(0));
  8948. res.Add(ScriptBaseClass.ZERO_VECTOR);
  8949. break;
  8950. case (int)ScriptBaseClass.PRIM_TEXGEN:
  8951. if (remain < 1)
  8952. return null;
  8953. face = (int)rules.GetLSLIntegerItem(idx++);
  8954. if (face > 21)
  8955. break;
  8956. res.Add(ScriptBaseClass.PRIM_TEXGEN_DEFAULT);
  8957. break;
  8958. case (int)ScriptBaseClass.PRIM_POINT_LIGHT:
  8959. res.Add(ScriptBaseClass.FALSE);
  8960. res.Add(ScriptBaseClass.ZERO_VECTOR);
  8961. res.Add(ScriptBaseClass.ZERO_VECTOR);
  8962. break;
  8963. case (int)ScriptBaseClass.PRIM_GLOW:
  8964. if (remain < 1)
  8965. return null;
  8966. face = (int)rules.GetLSLIntegerItem(idx++);
  8967. if (face > 21)
  8968. break;
  8969. res.Add(new LSL_Float(0));
  8970. break;
  8971. case (int)ScriptBaseClass.PRIM_TEXT:
  8972. res.Add(new LSL_String(""));
  8973. res.Add(ScriptBaseClass.ZERO_VECTOR);
  8974. res.Add(new LSL_Float(1));
  8975. break;
  8976. case (int)ScriptBaseClass.PRIM_ROT_LOCAL:
  8977. res.Add(new LSL_Rotation(sp.Rotation));
  8978. break;
  8979. case (int)ScriptBaseClass.PRIM_POS_LOCAL:
  8980. res.Add(new LSL_Vector(sp.OffsetPosition));
  8981. break;
  8982. case (int)ScriptBaseClass.PRIM_SLICE:
  8983. res.Add(new LSL_Vector(0, 1, 0));
  8984. break;
  8985. case (int)ScriptBaseClass.PRIM_LINK_TARGET:
  8986. if(remain < 3)
  8987. return null;
  8988. return rules.GetSublist(idx, -1);
  8989. }
  8990. }
  8991. return null;
  8992. }
  8993. public LSL_List GetPrimParams(SceneObjectPart part, LSL_List rules, ref LSL_List res)
  8994. {
  8995. int idx = 0;
  8996. while (idx < rules.Length)
  8997. {
  8998. int code = (int)rules.GetLSLIntegerItem(idx++);
  8999. int remain = rules.Length - idx;
  9000. switch (code)
  9001. {
  9002. case (int)ScriptBaseClass.PRIM_MATERIAL:
  9003. res.Add(new LSL_Integer(part.Material));
  9004. break;
  9005. case (int)ScriptBaseClass.PRIM_PHYSICS:
  9006. if ((part.GetEffectiveObjectFlags() & (uint)PrimFlags.Physics) != 0)
  9007. res.Add(new LSL_Integer(1));
  9008. else
  9009. res.Add(new LSL_Integer(0));
  9010. break;
  9011. case (int)ScriptBaseClass.PRIM_TEMP_ON_REZ:
  9012. if ((part.GetEffectiveObjectFlags() & (uint)PrimFlags.TemporaryOnRez) != 0)
  9013. res.Add(new LSL_Integer(1));
  9014. else
  9015. res.Add(new LSL_Integer(0));
  9016. break;
  9017. case (int)ScriptBaseClass.PRIM_PHANTOM:
  9018. if ((part.GetEffectiveObjectFlags() & (uint)PrimFlags.Phantom) != 0)
  9019. res.Add(new LSL_Integer(1));
  9020. else
  9021. res.Add(new LSL_Integer(0));
  9022. break;
  9023. case (int)ScriptBaseClass.PRIM_POSITION:
  9024. LSL_Vector v = new LSL_Vector(part.AbsolutePosition);
  9025. // For some reason, the part.AbsolutePosition.* values do not change if the
  9026. // linkset is rotated; they always reflect the child prim's world position
  9027. // as though the linkset is unrotated. This is incompatible behavior with SL's
  9028. // implementation, so will break scripts imported from there (not to mention it
  9029. // makes it more difficult to determine a child prim's actual inworld position).
  9030. if (!part.IsRoot)
  9031. {
  9032. LSL_Vector rootPos = new LSL_Vector(m_host.ParentGroup.AbsolutePosition);
  9033. v = ((v - rootPos) * llGetRootRotation()) + rootPos;
  9034. }
  9035. res.Add(v);
  9036. break;
  9037. case (int)ScriptBaseClass.PRIM_SIZE:
  9038. res.Add(new LSL_Vector(part.Scale));
  9039. break;
  9040. case (int)ScriptBaseClass.PRIM_ROTATION:
  9041. res.Add(GetPartRot(part));
  9042. break;
  9043. case (int)ScriptBaseClass.PRIM_PHYSICS_SHAPE_TYPE:
  9044. res.Add(new LSL_Integer((int)part.PhysicsShapeType));
  9045. break;
  9046. case (int)ScriptBaseClass.PRIM_TYPE:
  9047. // implementing box
  9048. PrimitiveBaseShape Shape = part.Shape;
  9049. int primType = (int)part.GetPrimType();
  9050. res.Add(new LSL_Integer(primType));
  9051. double topshearx = (double)(sbyte)Shape.PathShearX / 100.0; // Fix negative values for PathShearX
  9052. double topsheary = (double)(sbyte)Shape.PathShearY / 100.0; // and PathShearY.
  9053. switch (primType)
  9054. {
  9055. case ScriptBaseClass.PRIM_TYPE_BOX:
  9056. case ScriptBaseClass.PRIM_TYPE_CYLINDER:
  9057. case ScriptBaseClass.PRIM_TYPE_PRISM:
  9058. res.Add(new LSL_Integer(Shape.ProfileCurve) & 0xf0); // Isolate hole shape nibble.
  9059. res.Add(new LSL_Vector(Shape.ProfileBegin / 50000.0, 1 - Shape.ProfileEnd / 50000.0, 0));
  9060. res.Add(new LSL_Float(Shape.ProfileHollow / 50000.0));
  9061. res.Add(new LSL_Vector(Shape.PathTwistBegin / 100.0, Shape.PathTwist / 100.0, 0));
  9062. res.Add(new LSL_Vector(1 - (Shape.PathScaleX / 100.0 - 1), 1 - (Shape.PathScaleY / 100.0 - 1), 0));
  9063. res.Add(new LSL_Vector(topshearx, topsheary, 0));
  9064. break;
  9065. case ScriptBaseClass.PRIM_TYPE_SPHERE:
  9066. res.Add(new LSL_Integer(Shape.ProfileCurve) & 0xf0); // Isolate hole shape nibble.
  9067. res.Add(new LSL_Vector(Shape.PathBegin / 50000.0, 1 - Shape.PathEnd / 50000.0, 0));
  9068. res.Add(new LSL_Float(Shape.ProfileHollow / 50000.0));
  9069. res.Add(new LSL_Vector(Shape.PathTwistBegin / 100.0, Shape.PathTwist / 100.0, 0));
  9070. res.Add(new LSL_Vector(Shape.ProfileBegin / 50000.0, 1 - Shape.ProfileEnd / 50000.0, 0));
  9071. break;
  9072. case ScriptBaseClass.PRIM_TYPE_SCULPT:
  9073. res.Add(new LSL_String(Shape.SculptTexture.ToString()));
  9074. res.Add(new LSL_Integer(Shape.SculptType));
  9075. break;
  9076. case ScriptBaseClass.PRIM_TYPE_RING:
  9077. case ScriptBaseClass.PRIM_TYPE_TUBE:
  9078. case ScriptBaseClass.PRIM_TYPE_TORUS:
  9079. // holeshape
  9080. res.Add(new LSL_Integer(Shape.ProfileCurve) & 0xf0); // Isolate hole shape nibble.
  9081. // cut
  9082. res.Add(new LSL_Vector(Shape.PathBegin / 50000.0, 1 - Shape.PathEnd / 50000.0, 0));
  9083. // hollow
  9084. res.Add(new LSL_Float(Shape.ProfileHollow / 50000.0));
  9085. // twist
  9086. res.Add(new LSL_Vector(Shape.PathTwistBegin / 100.0, Shape.PathTwist / 100.0, 0));
  9087. // vector holesize
  9088. res.Add(new LSL_Vector(1 - (Shape.PathScaleX / 100.0 - 1), 1 - (Shape.PathScaleY / 100.0 - 1), 0));
  9089. // vector topshear
  9090. res.Add(new LSL_Vector(topshearx, topsheary, 0));
  9091. // vector profilecut
  9092. res.Add(new LSL_Vector(Shape.ProfileBegin / 50000.0, 1 - Shape.ProfileEnd / 50000.0, 0));
  9093. // vector tapera
  9094. res.Add(new LSL_Vector(Shape.PathTaperX / 100.0, Shape.PathTaperY / 100.0, 0));
  9095. // float revolutions
  9096. res.Add(new LSL_Float(Math.Round(Shape.PathRevolutions * 0.015d, 2, MidpointRounding.AwayFromZero)) + 1.0d);
  9097. // Slightly inaccurate, because an unsigned byte is being used to represent
  9098. // the entire range of floating-point values from 1.0 through 4.0 (which is how
  9099. // SL does it).
  9100. //
  9101. // Using these formulas to store and retrieve PathRevolutions, it is not
  9102. // possible to use all values between 1.00 and 4.00. For instance, you can't
  9103. // represent 1.10. You can represent 1.09 and 1.11, but not 1.10. So, if you
  9104. // use llSetPrimitiveParams to set revolutions to 1.10 and then retreive them
  9105. // with llGetPrimitiveParams, you'll retrieve 1.09. You can also see a similar
  9106. // behavior in the viewer as you cannot set 1.10. The viewer jumps to 1.11.
  9107. // In SL, llSetPrimitveParams and llGetPrimitiveParams can set and get a value
  9108. // such as 1.10. So, SL must store and retreive the actual user input rather
  9109. // than only storing the encoded value.
  9110. // float radiusoffset
  9111. res.Add(new LSL_Float(Shape.PathRadiusOffset / 100.0));
  9112. // float skew
  9113. res.Add(new LSL_Float(Shape.PathSkew / 100.0));
  9114. break;
  9115. }
  9116. break;
  9117. case (int)ScriptBaseClass.PRIM_TEXTURE:
  9118. if (remain < 1)
  9119. return null;
  9120. int face = (int)rules.GetLSLIntegerItem(idx++);
  9121. Primitive.TextureEntry tex = part.Shape.Textures;
  9122. if (face == ScriptBaseClass.ALL_SIDES)
  9123. {
  9124. for (face = 0 ; face < GetNumberOfSides(part); face++)
  9125. {
  9126. Primitive.TextureEntryFace texface = tex.GetFace((uint)face);
  9127. res.Add(new LSL_String(texface.TextureID.ToString()));
  9128. res.Add(new LSL_Vector(texface.RepeatU,
  9129. texface.RepeatV,
  9130. 0));
  9131. res.Add(new LSL_Vector(texface.OffsetU,
  9132. texface.OffsetV,
  9133. 0));
  9134. res.Add(new LSL_Float(texface.Rotation));
  9135. }
  9136. }
  9137. else
  9138. {
  9139. if (face >= 0 && face < GetNumberOfSides(part))
  9140. {
  9141. Primitive.TextureEntryFace texface = tex.GetFace((uint)face);
  9142. res.Add(new LSL_String(texface.TextureID.ToString()));
  9143. res.Add(new LSL_Vector(texface.RepeatU,
  9144. texface.RepeatV,
  9145. 0));
  9146. res.Add(new LSL_Vector(texface.OffsetU,
  9147. texface.OffsetV,
  9148. 0));
  9149. res.Add(new LSL_Float(texface.Rotation));
  9150. }
  9151. }
  9152. break;
  9153. case (int)ScriptBaseClass.PRIM_COLOR:
  9154. if (remain < 1)
  9155. return null;
  9156. face=(int)rules.GetLSLIntegerItem(idx++);
  9157. tex = part.Shape.Textures;
  9158. Color4 texcolor;
  9159. if (face == ScriptBaseClass.ALL_SIDES)
  9160. {
  9161. for (face = 0 ; face < GetNumberOfSides(part); face++)
  9162. {
  9163. texcolor = tex.GetFace((uint)face).RGBA;
  9164. res.Add(new LSL_Vector(texcolor.R,
  9165. texcolor.G,
  9166. texcolor.B));
  9167. res.Add(new LSL_Float(texcolor.A));
  9168. }
  9169. }
  9170. else
  9171. {
  9172. texcolor = tex.GetFace((uint)face).RGBA;
  9173. res.Add(new LSL_Vector(texcolor.R,
  9174. texcolor.G,
  9175. texcolor.B));
  9176. res.Add(new LSL_Float(texcolor.A));
  9177. }
  9178. break;
  9179. case (int)ScriptBaseClass.PRIM_BUMP_SHINY:
  9180. if (remain < 1)
  9181. return null;
  9182. face=(int)rules.GetLSLIntegerItem(idx++);
  9183. tex = part.Shape.Textures;
  9184. if (face == ScriptBaseClass.ALL_SIDES)
  9185. {
  9186. for (face = 0; face < GetNumberOfSides(part); face++)
  9187. {
  9188. Primitive.TextureEntryFace texface = tex.GetFace((uint)face);
  9189. // Convert Shininess to PRIM_SHINY_*
  9190. res.Add(new LSL_Integer((uint)texface.Shiny >> 6));
  9191. // PRIM_BUMP_*
  9192. res.Add(new LSL_Integer((int)texface.Bump));
  9193. }
  9194. }
  9195. else
  9196. {
  9197. if (face >= 0 && face < GetNumberOfSides(part))
  9198. {
  9199. Primitive.TextureEntryFace texface = tex.GetFace((uint)face);
  9200. // Convert Shininess to PRIM_SHINY_*
  9201. res.Add(new LSL_Integer((uint)texface.Shiny >> 6));
  9202. // PRIM_BUMP_*
  9203. res.Add(new LSL_Integer((int)texface.Bump));
  9204. }
  9205. }
  9206. break;
  9207. case (int)ScriptBaseClass.PRIM_FULLBRIGHT:
  9208. if (remain < 1)
  9209. return null;
  9210. face = (int)rules.GetLSLIntegerItem(idx++);
  9211. tex = part.Shape.Textures;
  9212. if (face == ScriptBaseClass.ALL_SIDES)
  9213. {
  9214. for (face = 0; face < GetNumberOfSides(part); face++)
  9215. {
  9216. Primitive.TextureEntryFace texface = tex.GetFace((uint)face);
  9217. res.Add(new LSL_Integer(texface.Fullbright ? 1 : 0));
  9218. }
  9219. }
  9220. else
  9221. {
  9222. if (face >= 0 && face < GetNumberOfSides(part))
  9223. {
  9224. Primitive.TextureEntryFace texface = tex.GetFace((uint)face);
  9225. res.Add(new LSL_Integer(texface.Fullbright ? 1 : 0));
  9226. }
  9227. }
  9228. break;
  9229. case (int)ScriptBaseClass.PRIM_FLEXIBLE:
  9230. PrimitiveBaseShape shape = part.Shape;
  9231. if (shape.FlexiEntry)
  9232. res.Add(new LSL_Integer(1)); // active
  9233. else
  9234. res.Add(new LSL_Integer(0));
  9235. res.Add(new LSL_Integer(shape.FlexiSoftness));// softness
  9236. res.Add(new LSL_Float(shape.FlexiGravity)); // gravity
  9237. res.Add(new LSL_Float(shape.FlexiDrag)); // friction
  9238. res.Add(new LSL_Float(shape.FlexiWind)); // wind
  9239. res.Add(new LSL_Float(shape.FlexiTension)); // tension
  9240. res.Add(new LSL_Vector(shape.FlexiForceX, // force
  9241. shape.FlexiForceY,
  9242. shape.FlexiForceZ));
  9243. break;
  9244. case (int)ScriptBaseClass.PRIM_TEXGEN:
  9245. if (remain < 1)
  9246. return null;
  9247. face=(int)rules.GetLSLIntegerItem(idx++);
  9248. tex = part.Shape.Textures;
  9249. if (face == ScriptBaseClass.ALL_SIDES)
  9250. {
  9251. for (face = 0; face < GetNumberOfSides(part); face++)
  9252. {
  9253. MappingType texgen = tex.GetFace((uint)face).TexMapType;
  9254. // Convert MappingType to PRIM_TEXGEN_DEFAULT, PRIM_TEXGEN_PLANAR etc.
  9255. res.Add(new LSL_Integer((uint)texgen >> 1));
  9256. }
  9257. }
  9258. else
  9259. {
  9260. if (face >= 0 && face < GetNumberOfSides(part))
  9261. {
  9262. MappingType texgen = tex.GetFace((uint)face).TexMapType;
  9263. res.Add(new LSL_Integer((uint)texgen >> 1));
  9264. }
  9265. }
  9266. break;
  9267. case (int)ScriptBaseClass.PRIM_POINT_LIGHT:
  9268. shape = part.Shape;
  9269. if (shape.LightEntry)
  9270. res.Add(new LSL_Integer(1)); // active
  9271. else
  9272. res.Add(new LSL_Integer(0));
  9273. res.Add(new LSL_Vector(shape.LightColorR, // color
  9274. shape.LightColorG,
  9275. shape.LightColorB));
  9276. res.Add(new LSL_Float(shape.LightIntensity)); // intensity
  9277. res.Add(new LSL_Float(shape.LightRadius)); // radius
  9278. res.Add(new LSL_Float(shape.LightFalloff)); // falloff
  9279. break;
  9280. case (int)ScriptBaseClass.PRIM_GLOW:
  9281. if (remain < 1)
  9282. return null;
  9283. face=(int)rules.GetLSLIntegerItem(idx++);
  9284. tex = part.Shape.Textures;
  9285. if (face == ScriptBaseClass.ALL_SIDES)
  9286. {
  9287. for (face = 0; face < GetNumberOfSides(part); face++)
  9288. {
  9289. Primitive.TextureEntryFace texface = tex.GetFace((uint)face);
  9290. res.Add(new LSL_Float(texface.Glow));
  9291. }
  9292. }
  9293. else
  9294. {
  9295. if (face >= 0 && face < GetNumberOfSides(part))
  9296. {
  9297. Primitive.TextureEntryFace texface = tex.GetFace((uint)face);
  9298. res.Add(new LSL_Float(texface.Glow));
  9299. }
  9300. }
  9301. break;
  9302. case (int)ScriptBaseClass.PRIM_TEXT:
  9303. Color4 textColor = part.GetTextColor();
  9304. res.Add(new LSL_String(part.Text));
  9305. res.Add(new LSL_Vector(textColor.R,
  9306. textColor.G,
  9307. textColor.B));
  9308. res.Add(new LSL_Float(1.0 - textColor.A));
  9309. break;
  9310. case (int)ScriptBaseClass.PRIM_NAME:
  9311. res.Add(new LSL_String(part.Name));
  9312. break;
  9313. case (int)ScriptBaseClass.PRIM_DESC:
  9314. res.Add(new LSL_String(part.Description));
  9315. break;
  9316. case (int)ScriptBaseClass.PRIM_ROT_LOCAL:
  9317. res.Add(new LSL_Rotation(part.RotationOffset));
  9318. break;
  9319. case (int)ScriptBaseClass.PRIM_POS_LOCAL:
  9320. res.Add(new LSL_Vector(GetPartLocalPos(part)));
  9321. break;
  9322. case (int)ScriptBaseClass.PRIM_SLICE:
  9323. PrimType prim_type = part.GetPrimType();
  9324. bool useProfileBeginEnd = (prim_type == PrimType.SPHERE || prim_type == PrimType.TORUS || prim_type == PrimType.TUBE || prim_type == PrimType.RING);
  9325. res.Add(new LSL_Vector(
  9326. (useProfileBeginEnd ? part.Shape.ProfileBegin : part.Shape.PathBegin) / 50000.0,
  9327. 1 - (useProfileBeginEnd ? part.Shape.ProfileEnd : part.Shape.PathEnd) / 50000.0,
  9328. 0
  9329. ));
  9330. break;
  9331. case (int)ScriptBaseClass.PRIM_LINK_TARGET:
  9332. // TODO: Should be issuing a runtime script warning in this case.
  9333. if (remain < 2)
  9334. return null;
  9335. return rules.GetSublist(idx, -1);
  9336. }
  9337. }
  9338. return null;
  9339. }
  9340. public LSL_List llGetPrimMediaParams(int face, LSL_List rules)
  9341. {
  9342. m_host.AddScriptLPS(1);
  9343. ScriptSleep(m_sleepMsOnGetPrimMediaParams);
  9344. return GetPrimMediaParams(m_host, face, rules);
  9345. }
  9346. public LSL_List llGetLinkMedia(LSL_Integer link, LSL_Integer face, LSL_List rules)
  9347. {
  9348. m_host.AddScriptLPS(1);
  9349. ScriptSleep(m_sleepMsOnGetLinkMedia);
  9350. if (link == ScriptBaseClass.LINK_ROOT)
  9351. return GetPrimMediaParams(m_host.ParentGroup.RootPart, face, rules);
  9352. else if (link == ScriptBaseClass.LINK_THIS)
  9353. return GetPrimMediaParams(m_host, face, rules);
  9354. else
  9355. {
  9356. SceneObjectPart part = m_host.ParentGroup.GetLinkNumPart(link);
  9357. if (null != part)
  9358. return GetPrimMediaParams(part, face, rules);
  9359. }
  9360. return new LSL_List();
  9361. }
  9362. private LSL_List GetPrimMediaParams(SceneObjectPart part, int face, LSL_List rules)
  9363. {
  9364. // LSL Spec http://wiki.secondlife.com/wiki/LlGetPrimMediaParams says to fail silently if face is invalid
  9365. // TODO: Need to correctly handle case where a face has no media (which gives back an empty list).
  9366. // Assuming silently fail means give back an empty list. Ideally, need to check this.
  9367. if (face < 0 || face > part.GetNumberOfSides() - 1)
  9368. return new LSL_List();
  9369. IMoapModule module = m_ScriptEngine.World.RequestModuleInterface<IMoapModule>();
  9370. if (null == module)
  9371. return new LSL_List();
  9372. MediaEntry me = module.GetMediaEntry(part, face);
  9373. // As per http://wiki.secondlife.com/wiki/LlGetPrimMediaParams
  9374. if (null == me)
  9375. return new LSL_List();
  9376. LSL_List res = new LSL_List();
  9377. for (int i = 0; i < rules.Length; i++)
  9378. {
  9379. int code = (int)rules.GetLSLIntegerItem(i);
  9380. switch (code)
  9381. {
  9382. case ScriptBaseClass.PRIM_MEDIA_ALT_IMAGE_ENABLE:
  9383. // Not implemented
  9384. res.Add(new LSL_Integer(0));
  9385. break;
  9386. case ScriptBaseClass.PRIM_MEDIA_CONTROLS:
  9387. if (me.Controls == MediaControls.Standard)
  9388. res.Add(new LSL_Integer(ScriptBaseClass.PRIM_MEDIA_CONTROLS_STANDARD));
  9389. else
  9390. res.Add(new LSL_Integer(ScriptBaseClass.PRIM_MEDIA_CONTROLS_MINI));
  9391. break;
  9392. case ScriptBaseClass.PRIM_MEDIA_CURRENT_URL:
  9393. res.Add(new LSL_String(me.CurrentURL));
  9394. break;
  9395. case ScriptBaseClass.PRIM_MEDIA_HOME_URL:
  9396. res.Add(new LSL_String(me.HomeURL));
  9397. break;
  9398. case ScriptBaseClass.PRIM_MEDIA_AUTO_LOOP:
  9399. res.Add(me.AutoLoop ? ScriptBaseClass.TRUE : ScriptBaseClass.FALSE);
  9400. break;
  9401. case ScriptBaseClass.PRIM_MEDIA_AUTO_PLAY:
  9402. res.Add(me.AutoPlay ? ScriptBaseClass.TRUE : ScriptBaseClass.FALSE);
  9403. break;
  9404. case ScriptBaseClass.PRIM_MEDIA_AUTO_SCALE:
  9405. res.Add(me.AutoScale ? ScriptBaseClass.TRUE : ScriptBaseClass.FALSE);
  9406. break;
  9407. case ScriptBaseClass.PRIM_MEDIA_AUTO_ZOOM:
  9408. res.Add(me.AutoZoom ? ScriptBaseClass.TRUE : ScriptBaseClass.FALSE);
  9409. break;
  9410. case ScriptBaseClass.PRIM_MEDIA_FIRST_CLICK_INTERACT:
  9411. res.Add(me.InteractOnFirstClick ? ScriptBaseClass.TRUE : ScriptBaseClass.FALSE);
  9412. break;
  9413. case ScriptBaseClass.PRIM_MEDIA_WIDTH_PIXELS:
  9414. res.Add(new LSL_Integer(me.Width));
  9415. break;
  9416. case ScriptBaseClass.PRIM_MEDIA_HEIGHT_PIXELS:
  9417. res.Add(new LSL_Integer(me.Height));
  9418. break;
  9419. case ScriptBaseClass.PRIM_MEDIA_WHITELIST_ENABLE:
  9420. res.Add(me.EnableWhiteList ? ScriptBaseClass.TRUE : ScriptBaseClass.FALSE);
  9421. break;
  9422. case ScriptBaseClass.PRIM_MEDIA_WHITELIST:
  9423. string[] urls = (string[])me.WhiteList.Clone();
  9424. for (int j = 0; j < urls.Length; j++)
  9425. urls[j] = Uri.EscapeDataString(urls[j]);
  9426. res.Add(new LSL_String(string.Join(", ", urls)));
  9427. break;
  9428. case ScriptBaseClass.PRIM_MEDIA_PERMS_INTERACT:
  9429. res.Add(new LSL_Integer((int)me.InteractPermissions));
  9430. break;
  9431. case ScriptBaseClass.PRIM_MEDIA_PERMS_CONTROL:
  9432. res.Add(new LSL_Integer((int)me.ControlPermissions));
  9433. break;
  9434. default: return ScriptBaseClass.LSL_STATUS_MALFORMED_PARAMS;
  9435. }
  9436. }
  9437. return res;
  9438. }
  9439. public LSL_Integer llSetPrimMediaParams(LSL_Integer face, LSL_List rules)
  9440. {
  9441. m_host.AddScriptLPS(1);
  9442. ScriptSleep(m_sleepMsOnSetPrimMediaParams);
  9443. return SetPrimMediaParams(m_host, face, rules);
  9444. }
  9445. public LSL_Integer llSetLinkMedia(LSL_Integer link, LSL_Integer face, LSL_List rules)
  9446. {
  9447. m_host.AddScriptLPS(1);
  9448. ScriptSleep(m_sleepMsOnSetLinkMedia);
  9449. if (link == ScriptBaseClass.LINK_ROOT)
  9450. return SetPrimMediaParams(m_host.ParentGroup.RootPart, face, rules);
  9451. else if (link == ScriptBaseClass.LINK_THIS)
  9452. return SetPrimMediaParams(m_host, face, rules);
  9453. else
  9454. {
  9455. SceneObjectPart part = m_host.ParentGroup.GetLinkNumPart(link);
  9456. if (null != part)
  9457. return SetPrimMediaParams(part, face, rules);
  9458. }
  9459. return ScriptBaseClass.LSL_STATUS_NOT_FOUND;
  9460. }
  9461. private LSL_Integer SetPrimMediaParams(SceneObjectPart part, LSL_Integer face, LSL_List rules)
  9462. {
  9463. // LSL Spec http://wiki.secondlife.com/wiki/LlSetPrimMediaParams says to fail silently if face is invalid
  9464. // Assuming silently fail means sending back LSL_STATUS_OK. Ideally, need to check this.
  9465. // Don't perform the media check directly
  9466. if (face < 0 || face > part.GetNumberOfSides() - 1)
  9467. return ScriptBaseClass.LSL_STATUS_NOT_FOUND;
  9468. IMoapModule module = m_ScriptEngine.World.RequestModuleInterface<IMoapModule>();
  9469. if (null == module)
  9470. return ScriptBaseClass.LSL_STATUS_NOT_SUPPORTED;
  9471. MediaEntry me = module.GetMediaEntry(part, face);
  9472. if (null == me)
  9473. me = new MediaEntry();
  9474. int i = 0;
  9475. while (i < rules.Length - 1)
  9476. {
  9477. int code = rules.GetLSLIntegerItem(i++);
  9478. switch (code)
  9479. {
  9480. case ScriptBaseClass.PRIM_MEDIA_ALT_IMAGE_ENABLE:
  9481. me.EnableAlterntiveImage = (rules.GetLSLIntegerItem(i++) != 0 ? true : false);
  9482. break;
  9483. case ScriptBaseClass.PRIM_MEDIA_CONTROLS:
  9484. int v = rules.GetLSLIntegerItem(i++);
  9485. if (ScriptBaseClass.PRIM_MEDIA_CONTROLS_STANDARD == v)
  9486. me.Controls = MediaControls.Standard;
  9487. else
  9488. me.Controls = MediaControls.Mini;
  9489. break;
  9490. case ScriptBaseClass.PRIM_MEDIA_CURRENT_URL:
  9491. me.CurrentURL = rules.GetLSLStringItem(i++);
  9492. break;
  9493. case ScriptBaseClass.PRIM_MEDIA_HOME_URL:
  9494. me.HomeURL = rules.GetLSLStringItem(i++);
  9495. break;
  9496. case ScriptBaseClass.PRIM_MEDIA_AUTO_LOOP:
  9497. me.AutoLoop = (ScriptBaseClass.TRUE == rules.GetLSLIntegerItem(i++) ? true : false);
  9498. break;
  9499. case ScriptBaseClass.PRIM_MEDIA_AUTO_PLAY:
  9500. me.AutoPlay = (ScriptBaseClass.TRUE == rules.GetLSLIntegerItem(i++) ? true : false);
  9501. break;
  9502. case ScriptBaseClass.PRIM_MEDIA_AUTO_SCALE:
  9503. me.AutoScale = (ScriptBaseClass.TRUE == rules.GetLSLIntegerItem(i++) ? true : false);
  9504. break;
  9505. case ScriptBaseClass.PRIM_MEDIA_AUTO_ZOOM:
  9506. me.AutoZoom = (ScriptBaseClass.TRUE == rules.GetLSLIntegerItem(i++) ? true : false);
  9507. break;
  9508. case ScriptBaseClass.PRIM_MEDIA_FIRST_CLICK_INTERACT:
  9509. me.InteractOnFirstClick = (ScriptBaseClass.TRUE == rules.GetLSLIntegerItem(i++) ? true : false);
  9510. break;
  9511. case ScriptBaseClass.PRIM_MEDIA_WIDTH_PIXELS:
  9512. me.Width = (int)rules.GetLSLIntegerItem(i++);
  9513. break;
  9514. case ScriptBaseClass.PRIM_MEDIA_HEIGHT_PIXELS:
  9515. me.Height = (int)rules.GetLSLIntegerItem(i++);
  9516. break;
  9517. case ScriptBaseClass.PRIM_MEDIA_WHITELIST_ENABLE:
  9518. me.EnableWhiteList = (ScriptBaseClass.TRUE == rules.GetLSLIntegerItem(i++) ? true : false);
  9519. break;
  9520. case ScriptBaseClass.PRIM_MEDIA_WHITELIST:
  9521. string[] rawWhiteListUrls = rules.GetLSLStringItem(i++).ToString().Split(new char[] { ',' });
  9522. List<string> whiteListUrls = new List<string>();
  9523. Array.ForEach(
  9524. rawWhiteListUrls, delegate(string rawUrl) { whiteListUrls.Add(rawUrl.Trim()); });
  9525. me.WhiteList = whiteListUrls.ToArray();
  9526. break;
  9527. case ScriptBaseClass.PRIM_MEDIA_PERMS_INTERACT:
  9528. me.InteractPermissions = (MediaPermission)(byte)(int)rules.GetLSLIntegerItem(i++);
  9529. break;
  9530. case ScriptBaseClass.PRIM_MEDIA_PERMS_CONTROL:
  9531. me.ControlPermissions = (MediaPermission)(byte)(int)rules.GetLSLIntegerItem(i++);
  9532. break;
  9533. default: return ScriptBaseClass.LSL_STATUS_MALFORMED_PARAMS;
  9534. }
  9535. }
  9536. module.SetMediaEntry(part, face, me);
  9537. return ScriptBaseClass.LSL_STATUS_OK;
  9538. }
  9539. public LSL_Integer llClearPrimMedia(LSL_Integer face)
  9540. {
  9541. m_host.AddScriptLPS(1);
  9542. ScriptSleep(m_sleepMsOnClearPrimMedia);
  9543. return ClearPrimMedia(m_host, face);
  9544. }
  9545. public LSL_Integer llClearLinkMedia(LSL_Integer link, LSL_Integer face)
  9546. {
  9547. m_host.AddScriptLPS(1);
  9548. ScriptSleep(m_sleepMsOnClearLinkMedia);
  9549. if (link == ScriptBaseClass.LINK_ROOT)
  9550. return ClearPrimMedia(m_host.ParentGroup.RootPart, face);
  9551. else if (link == ScriptBaseClass.LINK_THIS)
  9552. return ClearPrimMedia(m_host, face);
  9553. else
  9554. {
  9555. SceneObjectPart part = m_host.ParentGroup.GetLinkNumPart(link);
  9556. if (null != part)
  9557. return ClearPrimMedia(part, face);
  9558. }
  9559. return ScriptBaseClass.LSL_STATUS_NOT_FOUND;
  9560. }
  9561. private LSL_Integer ClearPrimMedia(SceneObjectPart part, LSL_Integer face)
  9562. {
  9563. // LSL Spec http://wiki.secondlife.com/wiki/LlClearPrimMedia says to fail silently if face is invalid
  9564. // Assuming silently fail means sending back LSL_STATUS_OK. Ideally, need to check this.
  9565. // FIXME: Don't perform the media check directly
  9566. if (face < 0 || face > part.GetNumberOfSides() - 1)
  9567. return ScriptBaseClass.LSL_STATUS_NOT_FOUND;
  9568. IMoapModule module = m_ScriptEngine.World.RequestModuleInterface<IMoapModule>();
  9569. if (null == module)
  9570. return ScriptBaseClass.LSL_STATUS_NOT_SUPPORTED;
  9571. module.ClearMediaEntry(part, face);
  9572. return ScriptBaseClass.LSL_STATUS_OK;
  9573. }
  9574. // <remarks>
  9575. // <para>
  9576. // The .NET definition of base 64 is:
  9577. // <list>
  9578. // <item>
  9579. // Significant: A-Z a-z 0-9 + -
  9580. // </item>
  9581. // <item>
  9582. // Whitespace: \t \n \r ' '
  9583. // </item>
  9584. // <item>
  9585. // Valueless: =
  9586. // </item>
  9587. // <item>
  9588. // End-of-string: \0 or '=='
  9589. // </item>
  9590. // </list>
  9591. // </para>
  9592. // <para>
  9593. // Each point in a base-64 string represents
  9594. // a 6 bit value. A 32-bit integer can be
  9595. // represented using 6 characters (with some
  9596. // redundancy).
  9597. // </para>
  9598. // <para>
  9599. // LSL requires a base64 string to be 8
  9600. // characters in length. LSL also uses '/'
  9601. // rather than '-' (MIME compliant).
  9602. // </para>
  9603. // <para>
  9604. // RFC 1341 used as a reference (as specified
  9605. // by the SecondLife Wiki).
  9606. // </para>
  9607. // <para>
  9608. // SL do not record any kind of exception for
  9609. // these functions, so the string to integer
  9610. // conversion returns '0' if an invalid
  9611. // character is encountered during conversion.
  9612. // </para>
  9613. // <para>
  9614. // References
  9615. // <list>
  9616. // <item>
  9617. // http://lslwiki.net/lslwiki/wakka.php?wakka=Base64
  9618. // </item>
  9619. // <item>
  9620. // </item>
  9621. // </list>
  9622. // </para>
  9623. // </remarks>
  9624. // <summary>
  9625. // Table for converting 6-bit integers into
  9626. // base-64 characters
  9627. // </summary>
  9628. protected static readonly char[] i2ctable =
  9629. {
  9630. 'A','B','C','D','E','F','G','H',
  9631. 'I','J','K','L','M','N','O','P',
  9632. 'Q','R','S','T','U','V','W','X',
  9633. 'Y','Z',
  9634. 'a','b','c','d','e','f','g','h',
  9635. 'i','j','k','l','m','n','o','p',
  9636. 'q','r','s','t','u','v','w','x',
  9637. 'y','z',
  9638. '0','1','2','3','4','5','6','7',
  9639. '8','9',
  9640. '+','/'
  9641. };
  9642. // <summary>
  9643. // Table for converting base-64 characters
  9644. // into 6-bit integers.
  9645. // </summary>
  9646. protected static readonly int[] c2itable =
  9647. {
  9648. -1,-1,-1,-1,-1,-1,-1,-1, // 0x
  9649. -1,-1,-1,-1,-1,-1,-1,-1,
  9650. -1,-1,-1,-1,-1,-1,-1,-1, // 1x
  9651. -1,-1,-1,-1,-1,-1,-1,-1,
  9652. -1,-1,-1,-1,-1,-1,-1,-1, // 2x
  9653. -1,-1,-1,63,-1,-1,-1,64,
  9654. 53,54,55,56,57,58,59,60, // 3x
  9655. 61,62,-1,-1,-1,0,-1,-1,
  9656. -1,1,2,3,4,5,6,7, // 4x
  9657. 8,9,10,11,12,13,14,15,
  9658. 16,17,18,19,20,21,22,23, // 5x
  9659. 24,25,26,-1,-1,-1,-1,-1,
  9660. -1,27,28,29,30,31,32,33, // 6x
  9661. 34,35,36,37,38,39,40,41,
  9662. 42,43,44,45,46,47,48,49, // 7x
  9663. 50,51,52,-1,-1,-1,-1,-1,
  9664. -1,-1,-1,-1,-1,-1,-1,-1, // 8x
  9665. -1,-1,-1,-1,-1,-1,-1,-1,
  9666. -1,-1,-1,-1,-1,-1,-1,-1, // 9x
  9667. -1,-1,-1,-1,-1,-1,-1,-1,
  9668. -1,-1,-1,-1,-1,-1,-1,-1, // Ax
  9669. -1,-1,-1,-1,-1,-1,-1,-1,
  9670. -1,-1,-1,-1,-1,-1,-1,-1, // Bx
  9671. -1,-1,-1,-1,-1,-1,-1,-1,
  9672. -1,-1,-1,-1,-1,-1,-1,-1, // Cx
  9673. -1,-1,-1,-1,-1,-1,-1,-1,
  9674. -1,-1,-1,-1,-1,-1,-1,-1, // Dx
  9675. -1,-1,-1,-1,-1,-1,-1,-1,
  9676. -1,-1,-1,-1,-1,-1,-1,-1, // Ex
  9677. -1,-1,-1,-1,-1,-1,-1,-1,
  9678. -1,-1,-1,-1,-1,-1,-1,-1, // Fx
  9679. -1,-1,-1,-1,-1,-1,-1,-1
  9680. };
  9681. // <summary>
  9682. // Converts a 32-bit integer into a Base64
  9683. // character string. Base64 character strings
  9684. // are always 8 characters long. All iinteger
  9685. // values are acceptable.
  9686. // </summary>
  9687. // <param name="number">
  9688. // 32-bit integer to be converted.
  9689. // </param>
  9690. // <returns>
  9691. // 8 character string. The 1st six characters
  9692. // contain the encoded number, the last two
  9693. // characters are padded with "=".
  9694. // </returns>
  9695. public LSL_String llIntegerToBase64(int number)
  9696. {
  9697. // uninitialized string
  9698. char[] imdt = new char[8];
  9699. m_host.AddScriptLPS(1);
  9700. // Manually unroll the loop
  9701. imdt[7] = '=';
  9702. imdt[6] = '=';
  9703. imdt[5] = i2ctable[number<<4 & 0x3F];
  9704. imdt[4] = i2ctable[number>>2 & 0x3F];
  9705. imdt[3] = i2ctable[number>>8 & 0x3F];
  9706. imdt[2] = i2ctable[number>>14 & 0x3F];
  9707. imdt[1] = i2ctable[number>>20 & 0x3F];
  9708. imdt[0] = i2ctable[number>>26 & 0x3F];
  9709. return new string(imdt);
  9710. }
  9711. // <summary>
  9712. // Converts an eight character base-64 string
  9713. // into a 32-bit integer.
  9714. // </summary>
  9715. // <param name="str">
  9716. // 8 characters string to be converted. Other
  9717. // length strings return zero.
  9718. // </param>
  9719. // <returns>
  9720. // Returns an integer representing the
  9721. // encoded value providedint he 1st 6
  9722. // characters of the string.
  9723. // </returns>
  9724. // <remarks>
  9725. // This is coded to behave like LSL's
  9726. // implementation (I think), based upon the
  9727. // information available at the Wiki.
  9728. // If more than 8 characters are supplied,
  9729. // zero is returned.
  9730. // If a NULL string is supplied, zero will
  9731. // be returned.
  9732. // If fewer than 6 characters are supplied, then
  9733. // the answer will reflect a partial
  9734. // accumulation.
  9735. // <para>
  9736. // The 6-bit segments are
  9737. // extracted left-to-right in big-endian mode,
  9738. // which means that segment 6 only contains the
  9739. // two low-order bits of the 32 bit integer as
  9740. // its high order 2 bits. A short string therefore
  9741. // means loss of low-order information. E.g.
  9742. //
  9743. // |<---------------------- 32-bit integer ----------------------->|<-Pad->|
  9744. // |<--Byte 0----->|<--Byte 1----->|<--Byte 2----->|<--Byte 3----->|<-Pad->|
  9745. // |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|
  9746. // |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|
  9747. // | str[0] | str[1] | str[2] | str[3] | str[4] | str[6] |
  9748. //
  9749. // </para>
  9750. // </remarks>
  9751. public LSL_Integer llBase64ToInteger(string str)
  9752. {
  9753. int number = 0;
  9754. int digit;
  9755. m_host.AddScriptLPS(1);
  9756. // Require a well-fromed base64 string
  9757. if (str.Length > 8)
  9758. return 0;
  9759. // The loop is unrolled in the interests
  9760. // of performance and simple necessity.
  9761. //
  9762. // MUST find 6 digits to be well formed
  9763. // -1 == invalid
  9764. // 0 == padding
  9765. if ((digit = c2itable[str[0]]) <= 0)
  9766. {
  9767. return digit < 0 ? (int)0 : number;
  9768. }
  9769. number += --digit<<26;
  9770. if ((digit = c2itable[str[1]]) <= 0)
  9771. {
  9772. return digit < 0 ? (int)0 : number;
  9773. }
  9774. number += --digit<<20;
  9775. if ((digit = c2itable[str[2]]) <= 0)
  9776. {
  9777. return digit < 0 ? (int)0 : number;
  9778. }
  9779. number += --digit<<14;
  9780. if ((digit = c2itable[str[3]]) <= 0)
  9781. {
  9782. return digit < 0 ? (int)0 : number;
  9783. }
  9784. number += --digit<<8;
  9785. if ((digit = c2itable[str[4]]) <= 0)
  9786. {
  9787. return digit < 0 ? (int)0 : number;
  9788. }
  9789. number += --digit<<2;
  9790. if ((digit = c2itable[str[5]]) <= 0)
  9791. {
  9792. return digit < 0 ? (int)0 : number;
  9793. }
  9794. number += --digit>>4;
  9795. // ignore trailing padding
  9796. return number;
  9797. }
  9798. public LSL_Float llGetGMTclock()
  9799. {
  9800. m_host.AddScriptLPS(1);
  9801. return DateTime.UtcNow.TimeOfDay.TotalSeconds;
  9802. }
  9803. public LSL_String llGetHTTPHeader(LSL_Key request_id, string header)
  9804. {
  9805. m_host.AddScriptLPS(1);
  9806. if (m_UrlModule != null)
  9807. return m_UrlModule.GetHttpHeader(new UUID(request_id), header);
  9808. return String.Empty;
  9809. }
  9810. public LSL_String llGetSimulatorHostname()
  9811. {
  9812. m_host.AddScriptLPS(1);
  9813. IUrlModule UrlModule = World.RequestModuleInterface<IUrlModule>();
  9814. return UrlModule.ExternalHostNameForLSL;
  9815. }
  9816. // <summary>
  9817. // Scan the string supplied in 'src' and
  9818. // tokenize it based upon two sets of
  9819. // tokenizers provided in two lists,
  9820. // separators and spacers.
  9821. // </summary>
  9822. //
  9823. // <remarks>
  9824. // Separators demarcate tokens and are
  9825. // elided as they are encountered. Spacers
  9826. // also demarcate tokens, but are themselves
  9827. // retained as tokens.
  9828. //
  9829. // Both separators and spacers may be arbitrarily
  9830. // long strings. i.e. ":::".
  9831. //
  9832. // The function returns an ordered list
  9833. // representing the tokens found in the supplied
  9834. // sources string. If two successive tokenizers
  9835. // are encountered, then a NULL entry is added
  9836. // to the list.
  9837. //
  9838. // It is a precondition that the source and
  9839. // toekizer lisst are non-null. If they are null,
  9840. // then a null pointer exception will be thrown
  9841. // while their lengths are being determined.
  9842. //
  9843. // A small amount of working memoryis required
  9844. // of approximately 8*#tokenizers.
  9845. //
  9846. // There are many ways in which this function
  9847. // can be implemented, this implementation is
  9848. // fairly naive and assumes that when the
  9849. // function is invooked with a short source
  9850. // string and/or short lists of tokenizers, then
  9851. // performance will not be an issue.
  9852. //
  9853. // In order to minimize the perofrmance
  9854. // effects of long strings, or large numbers
  9855. // of tokeizers, the function skips as far as
  9856. // possible whenever a toekenizer is found,
  9857. // and eliminates redundant tokenizers as soon
  9858. // as is possible.
  9859. //
  9860. // The implementation tries to avoid any copying
  9861. // of arrays or other objects.
  9862. // </remarks>
  9863. private LSL_List ParseString(string src, LSL_List separators, LSL_List spacers, bool keepNulls)
  9864. {
  9865. int beginning = 0;
  9866. int srclen = src.Length;
  9867. int seplen = separators.Length;
  9868. object[] separray = separators.Data;
  9869. int spclen = spacers.Length;
  9870. object[] spcarray = spacers.Data;
  9871. int mlen = seplen+spclen;
  9872. int[] offset = new int[mlen+1];
  9873. bool[] active = new bool[mlen];
  9874. int best;
  9875. int j;
  9876. // Initial capacity reduces resize cost
  9877. LSL_List tokens = new LSL_List();
  9878. // All entries are initially valid
  9879. for (int i = 0; i < mlen; i++)
  9880. active[i] = true;
  9881. offset[mlen] = srclen;
  9882. while (beginning < srclen)
  9883. {
  9884. best = mlen; // as bad as it gets
  9885. // Scan for separators
  9886. for (j = 0; j < seplen; j++)
  9887. {
  9888. if (separray[j].ToString() == String.Empty)
  9889. active[j] = false;
  9890. if (active[j])
  9891. {
  9892. // scan all of the markers
  9893. if ((offset[j] = src.IndexOf(separray[j].ToString(), beginning)) == -1)
  9894. {
  9895. // not present at all
  9896. active[j] = false;
  9897. }
  9898. else
  9899. {
  9900. // present and correct
  9901. if (offset[j] < offset[best])
  9902. {
  9903. // closest so far
  9904. best = j;
  9905. if (offset[best] == beginning)
  9906. break;
  9907. }
  9908. }
  9909. }
  9910. }
  9911. // Scan for spacers
  9912. if (offset[best] != beginning)
  9913. {
  9914. for (j = seplen; (j < mlen) && (offset[best] > beginning); j++)
  9915. {
  9916. if (spcarray[j-seplen].ToString() == String.Empty)
  9917. active[j] = false;
  9918. if (active[j])
  9919. {
  9920. // scan all of the markers
  9921. if ((offset[j] = src.IndexOf(spcarray[j-seplen].ToString(), beginning)) == -1)
  9922. {
  9923. // not present at all
  9924. active[j] = false;
  9925. }
  9926. else
  9927. {
  9928. // present and correct
  9929. if (offset[j] < offset[best])
  9930. {
  9931. // closest so far
  9932. best = j;
  9933. }
  9934. }
  9935. }
  9936. }
  9937. }
  9938. // This is the normal exit from the scanning loop
  9939. if (best == mlen)
  9940. {
  9941. // no markers were found on this pass
  9942. // so we're pretty much done
  9943. if ((keepNulls) || ((!keepNulls) && (srclen - beginning) > 0))
  9944. tokens.Add(new LSL_String(src.Substring(beginning, srclen - beginning)));
  9945. break;
  9946. }
  9947. // Otherwise we just add the newly delimited token
  9948. // and recalculate where the search should continue.
  9949. if ((keepNulls) || ((!keepNulls) && (offset[best] - beginning) > 0))
  9950. tokens.Add(new LSL_String(src.Substring(beginning,offset[best]-beginning)));
  9951. if (best < seplen)
  9952. {
  9953. beginning = offset[best] + (separray[best].ToString()).Length;
  9954. }
  9955. else
  9956. {
  9957. beginning = offset[best] + (spcarray[best - seplen].ToString()).Length;
  9958. string str = spcarray[best - seplen].ToString();
  9959. if ((keepNulls) || ((!keepNulls) && (str.Length > 0)))
  9960. tokens.Add(new LSL_String(str));
  9961. }
  9962. }
  9963. // This an awkward an not very intuitive boundary case. If the
  9964. // last substring is a tokenizer, then there is an implied trailing
  9965. // null list entry. Hopefully the single comparison will not be too
  9966. // arduous. Alternatively the 'break' could be replced with a return
  9967. // but that's shabby programming.
  9968. if ((beginning == srclen) && (keepNulls))
  9969. {
  9970. if (srclen != 0)
  9971. tokens.Add(new LSL_String(""));
  9972. }
  9973. return tokens;
  9974. }
  9975. public LSL_List llParseString2List(string src, LSL_List separators, LSL_List spacers)
  9976. {
  9977. m_host.AddScriptLPS(1);
  9978. return this.ParseString(src, separators, spacers, false);
  9979. }
  9980. public LSL_List llParseStringKeepNulls(string src, LSL_List separators, LSL_List spacers)
  9981. {
  9982. m_host.AddScriptLPS(1);
  9983. return this.ParseString(src, separators, spacers, true);
  9984. }
  9985. public LSL_Integer llGetObjectPermMask(int mask)
  9986. {
  9987. m_host.AddScriptLPS(1);
  9988. int permmask = 0;
  9989. if (mask == ScriptBaseClass.MASK_BASE)//0
  9990. {
  9991. permmask = (int)m_host.BaseMask;
  9992. }
  9993. else if (mask == ScriptBaseClass.MASK_OWNER)//1
  9994. {
  9995. permmask = (int)m_host.OwnerMask;
  9996. }
  9997. else if (mask == ScriptBaseClass.MASK_GROUP)//2
  9998. {
  9999. permmask = (int)m_host.GroupMask;
  10000. }
  10001. else if (mask == ScriptBaseClass.MASK_EVERYONE)//3
  10002. {
  10003. permmask = (int)m_host.EveryoneMask;
  10004. }
  10005. else if (mask == ScriptBaseClass.MASK_NEXT)//4
  10006. {
  10007. permmask = (int)m_host.NextOwnerMask;
  10008. }
  10009. return permmask;
  10010. }
  10011. public void llSetObjectPermMask(int mask, int value)
  10012. {
  10013. m_host.AddScriptLPS(1);
  10014. if (m_ScriptEngine.Config.GetBoolean("AllowGodFunctions", false))
  10015. {
  10016. if (World.Permissions.CanRunConsoleCommand(m_host.OwnerID))
  10017. {
  10018. if (mask == ScriptBaseClass.MASK_BASE)//0
  10019. {
  10020. m_host.BaseMask = (uint)value;
  10021. }
  10022. else if (mask == ScriptBaseClass.MASK_OWNER)//1
  10023. {
  10024. m_host.OwnerMask = (uint)value;
  10025. }
  10026. else if (mask == ScriptBaseClass.MASK_GROUP)//2
  10027. {
  10028. m_host.GroupMask = (uint)value;
  10029. }
  10030. else if (mask == ScriptBaseClass.MASK_EVERYONE)//3
  10031. {
  10032. m_host.EveryoneMask = (uint)value;
  10033. }
  10034. else if (mask == ScriptBaseClass.MASK_NEXT)//4
  10035. {
  10036. m_host.NextOwnerMask = (uint)value;
  10037. }
  10038. }
  10039. }
  10040. }
  10041. public LSL_Integer llGetInventoryPermMask(string itemName, int mask)
  10042. {
  10043. m_host.AddScriptLPS(1);
  10044. TaskInventoryItem item = m_host.Inventory.GetInventoryItem(itemName);
  10045. if (item == null)
  10046. return -1;
  10047. switch (mask)
  10048. {
  10049. case 0:
  10050. return (int)item.BasePermissions;
  10051. case 1:
  10052. return (int)item.CurrentPermissions;
  10053. case 2:
  10054. return (int)item.GroupPermissions;
  10055. case 3:
  10056. return (int)item.EveryonePermissions;
  10057. case 4:
  10058. return (int)item.NextPermissions;
  10059. }
  10060. return -1;
  10061. }
  10062. public void llSetInventoryPermMask(string itemName, int mask, int value)
  10063. {
  10064. m_host.AddScriptLPS(1);
  10065. if (m_ScriptEngine.Config.GetBoolean("AllowGodFunctions", false))
  10066. {
  10067. if (World.Permissions.CanRunConsoleCommand(m_host.OwnerID))
  10068. {
  10069. TaskInventoryItem item = m_host.Inventory.GetInventoryItem(itemName);
  10070. if (item != null)
  10071. {
  10072. switch (mask)
  10073. {
  10074. case 0:
  10075. item.BasePermissions = (uint)value;
  10076. break;
  10077. case 1:
  10078. item.CurrentPermissions = (uint)value;
  10079. break;
  10080. case 2:
  10081. item.GroupPermissions = (uint)value;
  10082. break;
  10083. case 3:
  10084. item.EveryonePermissions = (uint)value;
  10085. break;
  10086. case 4:
  10087. item.NextPermissions = (uint)value;
  10088. break;
  10089. }
  10090. }
  10091. }
  10092. }
  10093. }
  10094. public LSL_String llGetInventoryCreator(string itemName)
  10095. {
  10096. m_host.AddScriptLPS(1);
  10097. TaskInventoryItem item = m_host.Inventory.GetInventoryItem(itemName);
  10098. if (item == null)
  10099. {
  10100. Error("llGetInventoryCreator", "Can't find item '" + item + "'");
  10101. return String.Empty;
  10102. }
  10103. return item.CreatorID.ToString();
  10104. }
  10105. public void llOwnerSay(string msg)
  10106. {
  10107. m_host.AddScriptLPS(1);
  10108. World.SimChatBroadcast(Utils.StringToBytes(msg), ChatTypeEnum.Owner, 0,
  10109. m_host.AbsolutePosition, m_host.Name, m_host.UUID, false);
  10110. // IWorldComm wComm = m_ScriptEngine.World.RequestModuleInterface<IWorldComm>();
  10111. // wComm.DeliverMessage(ChatTypeEnum.Owner, 0, m_host.Name, m_host.UUID, msg);
  10112. }
  10113. public LSL_String llRequestSecureURL()
  10114. {
  10115. m_host.AddScriptLPS(1);
  10116. if (m_UrlModule != null)
  10117. return m_UrlModule.RequestSecureURL(m_ScriptEngine.ScriptModule, m_host, m_item.ItemID).ToString();
  10118. return UUID.Zero.ToString();
  10119. }
  10120. public LSL_String llRequestSimulatorData(string simulator, int data)
  10121. {
  10122. IOSSL_Api ossl = (IOSSL_Api)m_ScriptEngine.GetApi(m_item.ItemID, "OSSL");
  10123. try
  10124. {
  10125. m_host.AddScriptLPS(1);
  10126. string reply = String.Empty;
  10127. GridRegion info;
  10128. if (World.RegionInfo.RegionName == simulator)
  10129. info = new GridRegion(World.RegionInfo);
  10130. else
  10131. info = World.GridService.GetRegionByName(m_ScriptEngine.World.RegionInfo.ScopeID, simulator);
  10132. switch (data)
  10133. {
  10134. case ScriptBaseClass.DATA_SIM_POS:
  10135. if (info == null)
  10136. {
  10137. ScriptSleep(m_sleepMsOnRequestSimulatorData);
  10138. return UUID.Zero.ToString();
  10139. }
  10140. bool isHypergridRegion = false;
  10141. if (World.RegionInfo.RegionName != simulator && info.RegionSecret != "")
  10142. {
  10143. // Hypergrid is currently placing real destination region co-ords into RegionSecret.
  10144. // But other code can also use this field for a genuine RegionSecret! Therefore, if
  10145. // anything is present we need to disambiguate.
  10146. //
  10147. // FIXME: Hypergrid should be storing this data in a different field.
  10148. RegionFlags regionFlags
  10149. = (RegionFlags)m_ScriptEngine.World.GridService.GetRegionFlags(
  10150. info.ScopeID, info.RegionID);
  10151. isHypergridRegion = (regionFlags & RegionFlags.Hyperlink) != 0;
  10152. }
  10153. if (isHypergridRegion)
  10154. {
  10155. uint rx = 0, ry = 0;
  10156. Utils.LongToUInts(Convert.ToUInt64(info.RegionSecret), out rx, out ry);
  10157. reply = new LSL_Vector(
  10158. rx,
  10159. ry,
  10160. 0).ToString();
  10161. }
  10162. else
  10163. {
  10164. // Local grid co-oridnates
  10165. reply = new LSL_Vector(
  10166. info.RegionLocX,
  10167. info.RegionLocY,
  10168. 0).ToString();
  10169. }
  10170. break;
  10171. case ScriptBaseClass.DATA_SIM_STATUS:
  10172. if (info != null)
  10173. reply = "up"; // Duh!
  10174. else
  10175. reply = "unknown";
  10176. break;
  10177. case ScriptBaseClass.DATA_SIM_RATING:
  10178. if (info == null)
  10179. {
  10180. ScriptSleep(m_sleepMsOnRequestSimulatorData);
  10181. return UUID.Zero.ToString();
  10182. }
  10183. int access = info.Maturity;
  10184. if (access == 0)
  10185. reply = "PG";
  10186. else if (access == 1)
  10187. reply = "MATURE";
  10188. else if (access == 2)
  10189. reply = "ADULT";
  10190. else
  10191. reply = "UNKNOWN";
  10192. break;
  10193. case ScriptBaseClass.DATA_SIM_RELEASE:
  10194. if (ossl != null)
  10195. ossl.CheckThreatLevel(ThreatLevel.High, "llRequestSimulatorData");
  10196. reply = "OpenSim";
  10197. break;
  10198. default:
  10199. ScriptSleep(m_sleepMsOnRequestSimulatorData);
  10200. return UUID.Zero.ToString(); // Raise no event
  10201. }
  10202. UUID rq = UUID.Random();
  10203. UUID tid = AsyncCommands.
  10204. DataserverPlugin.RegisterRequest(m_host.LocalId, m_item.ItemID, rq.ToString());
  10205. AsyncCommands.
  10206. DataserverPlugin.DataserverReply(rq.ToString(), reply);
  10207. ScriptSleep(m_sleepMsOnRequestSimulatorData);
  10208. return tid.ToString();
  10209. }
  10210. catch(Exception)
  10211. {
  10212. //m_log.Error("[LSL_API]: llRequestSimulatorData" + e.ToString());
  10213. return UUID.Zero.ToString();
  10214. }
  10215. }
  10216. public LSL_String llRequestURL()
  10217. {
  10218. m_host.AddScriptLPS(1);
  10219. if (m_UrlModule != null)
  10220. return m_UrlModule.RequestURL(m_ScriptEngine.ScriptModule, m_host, m_item.ItemID).ToString();
  10221. return UUID.Zero.ToString();
  10222. }
  10223. public void llForceMouselook(int mouselook)
  10224. {
  10225. m_host.AddScriptLPS(1);
  10226. m_host.SetForceMouselook(mouselook != 0);
  10227. }
  10228. public LSL_Float llGetObjectMass(string id)
  10229. {
  10230. m_host.AddScriptLPS(1);
  10231. UUID key = new UUID();
  10232. if (UUID.TryParse(id, out key))
  10233. {
  10234. try
  10235. {
  10236. SceneObjectPart obj = World.GetSceneObjectPart(World.Entities[key].LocalId);
  10237. if (obj != null)
  10238. return (double)obj.GetMass();
  10239. // the object is null so the key is for an avatar
  10240. ScenePresence avatar = World.GetScenePresence(key);
  10241. if (avatar != null)
  10242. if (avatar.IsChildAgent)
  10243. // reference http://www.lslwiki.net/lslwiki/wakka.php?wakka=llGetObjectMass
  10244. // child agents have a mass of 1.0
  10245. return 1;
  10246. else
  10247. return (double)avatar.GetMass();
  10248. }
  10249. catch (KeyNotFoundException)
  10250. {
  10251. return 0; // The Object/Agent not in the region so just return zero
  10252. }
  10253. }
  10254. return 0;
  10255. }
  10256. /// <summary>
  10257. /// illListReplaceList removes the sub-list defined by the inclusive indices
  10258. /// start and end and inserts the src list in its place. The inclusive
  10259. /// nature of the indices means that at least one element must be deleted
  10260. /// if the indices are within the bounds of the existing list. I.e. 2,2
  10261. /// will remove the element at index 2 and replace it with the source
  10262. /// list. Both indices may be negative, with the usual interpretation. An
  10263. /// interesting case is where end is lower than start. As these indices
  10264. /// bound the list to be removed, then 0->end, and start->lim are removed
  10265. /// and the source list is added as a suffix.
  10266. /// </summary>
  10267. public LSL_List llListReplaceList(LSL_List dest, LSL_List src, int start, int end)
  10268. {
  10269. LSL_List pref = null;
  10270. m_host.AddScriptLPS(1);
  10271. // Note that although we have normalized, both
  10272. // indices could still be negative.
  10273. if (start < 0)
  10274. {
  10275. start = start+dest.Length;
  10276. }
  10277. if (end < 0)
  10278. {
  10279. end = end+dest.Length;
  10280. }
  10281. // The comventional case, remove a sequence starting with
  10282. // start and ending with end. And then insert the source
  10283. // list.
  10284. if (start <= end)
  10285. {
  10286. // If greater than zero, then there is going to be a
  10287. // surviving prefix. Otherwise the inclusive nature
  10288. // of the indices mean that we're going to add the
  10289. // source list as a prefix.
  10290. if (start > 0)
  10291. {
  10292. pref = dest.GetSublist(0,start-1);
  10293. // Only add a suffix if there is something
  10294. // beyond the end index (it's inclusive too).
  10295. if (end + 1 < dest.Length)
  10296. {
  10297. return pref + src + dest.GetSublist(end + 1, -1);
  10298. }
  10299. else
  10300. {
  10301. return pref + src;
  10302. }
  10303. }
  10304. // If start is less than or equal to zero, then
  10305. // the new list is simply a prefix. We still need to
  10306. // figure out any necessary surgery to the destination
  10307. // based upon end. Note that if end exceeds the upper
  10308. // bound in this case, the entire destination list
  10309. // is removed.
  10310. else
  10311. {
  10312. if (end + 1 < dest.Length)
  10313. {
  10314. return src + dest.GetSublist(end + 1, -1);
  10315. }
  10316. else
  10317. {
  10318. return src;
  10319. }
  10320. }
  10321. }
  10322. // Finally, if start > end, we strip away a prefix and
  10323. // a suffix, to leave the list that sits <between> ens
  10324. // and start, and then tag on the src list. AT least
  10325. // that's my interpretation. We can get sublist to do
  10326. // this for us. Note that one, or both of the indices
  10327. // might have been negative.
  10328. else
  10329. {
  10330. return dest.GetSublist(end + 1, start - 1) + src;
  10331. }
  10332. }
  10333. public void llLoadURL(string avatar_id, string message, string url)
  10334. {
  10335. m_host.AddScriptLPS(1);
  10336. IDialogModule dm = World.RequestModuleInterface<IDialogModule>();
  10337. if (null != dm)
  10338. dm.SendUrlToUser(
  10339. new UUID(avatar_id), m_host.Name, m_host.UUID, m_host.OwnerID, false, message, url);
  10340. ScriptSleep(m_sleepMsOnLoadURL);
  10341. }
  10342. public void llParcelMediaCommandList(LSL_List commandList)
  10343. {
  10344. // TODO: Not implemented yet (missing in libomv?):
  10345. // 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)
  10346. m_host.AddScriptLPS(1);
  10347. // according to the docs, this command only works if script owner and land owner are the same
  10348. // lets add estate owners and gods, too, and use the generic permission check.
  10349. ILandObject landObject = World.LandChannel.GetLandObject(m_host.AbsolutePosition);
  10350. if (!World.Permissions.CanEditParcelProperties(m_host.OwnerID, landObject, GroupPowers.ChangeMedia)) return;
  10351. bool update = false; // send a ParcelMediaUpdate (and possibly change the land's media URL)?
  10352. byte loop = 0;
  10353. LandData landData = landObject.LandData;
  10354. string url = landData.MediaURL;
  10355. string texture = landData.MediaID.ToString();
  10356. bool autoAlign = landData.MediaAutoScale != 0;
  10357. string mediaType = ""; // TODO these have to be added as soon as LandData supports it
  10358. string description = "";
  10359. int width = 0;
  10360. int height = 0;
  10361. ParcelMediaCommandEnum? commandToSend = null;
  10362. float time = 0.0f; // default is from start
  10363. ScenePresence presence = null;
  10364. for (int i = 0; i < commandList.Data.Length; i++)
  10365. {
  10366. ParcelMediaCommandEnum command = (ParcelMediaCommandEnum)commandList.Data[i];
  10367. switch (command)
  10368. {
  10369. case ParcelMediaCommandEnum.Agent:
  10370. // we send only to one agent
  10371. if ((i + 1) < commandList.Length)
  10372. {
  10373. if (commandList.Data[i + 1] is LSL_String)
  10374. {
  10375. UUID agentID;
  10376. if (UUID.TryParse((LSL_String)commandList.Data[i + 1], out agentID))
  10377. {
  10378. presence = World.GetScenePresence(agentID);
  10379. }
  10380. }
  10381. else Error("llParcelMediaCommandList", "The argument of PARCEL_MEDIA_COMMAND_AGENT must be a key");
  10382. ++i;
  10383. }
  10384. break;
  10385. case ParcelMediaCommandEnum.Loop:
  10386. loop = 1;
  10387. commandToSend = command;
  10388. update = true; //need to send the media update packet to set looping
  10389. break;
  10390. case ParcelMediaCommandEnum.Play:
  10391. loop = 0;
  10392. commandToSend = command;
  10393. update = true; //need to send the media update packet to make sure it doesn't loop
  10394. break;
  10395. case ParcelMediaCommandEnum.Pause:
  10396. case ParcelMediaCommandEnum.Stop:
  10397. case ParcelMediaCommandEnum.Unload:
  10398. commandToSend = command;
  10399. break;
  10400. case ParcelMediaCommandEnum.Url:
  10401. if ((i + 1) < commandList.Length)
  10402. {
  10403. if (commandList.Data[i + 1] is LSL_String)
  10404. {
  10405. url = (LSL_String)commandList.Data[i + 1];
  10406. update = true;
  10407. }
  10408. else Error("llParcelMediaCommandList", "The argument of PARCEL_MEDIA_COMMAND_URL must be a string");
  10409. ++i;
  10410. }
  10411. break;
  10412. case ParcelMediaCommandEnum.Texture:
  10413. if ((i + 1) < commandList.Length)
  10414. {
  10415. if (commandList.Data[i + 1] is LSL_String)
  10416. {
  10417. texture = (LSL_String)commandList.Data[i + 1];
  10418. update = true;
  10419. }
  10420. else Error("llParcelMediaCommandList", "The argument of PARCEL_MEDIA_COMMAND_TEXTURE must be a string or a key");
  10421. ++i;
  10422. }
  10423. break;
  10424. case ParcelMediaCommandEnum.Time:
  10425. if ((i + 1) < commandList.Length)
  10426. {
  10427. if (commandList.Data[i + 1] is LSL_Float)
  10428. {
  10429. time = (float)(LSL_Float)commandList.Data[i + 1];
  10430. }
  10431. else Error("llParcelMediaCommandList", "The argument of PARCEL_MEDIA_COMMAND_TIME must be a float");
  10432. ++i;
  10433. }
  10434. break;
  10435. case ParcelMediaCommandEnum.AutoAlign:
  10436. if ((i + 1) < commandList.Length)
  10437. {
  10438. if (commandList.Data[i + 1] is LSL_Integer)
  10439. {
  10440. autoAlign = (LSL_Integer)commandList.Data[i + 1];
  10441. update = true;
  10442. }
  10443. else Error("llParcelMediaCommandList", "The argument of PARCEL_MEDIA_COMMAND_AUTO_ALIGN must be an integer");
  10444. ++i;
  10445. }
  10446. break;
  10447. case ParcelMediaCommandEnum.Type:
  10448. if ((i + 1) < commandList.Length)
  10449. {
  10450. if (commandList.Data[i + 1] is LSL_String)
  10451. {
  10452. mediaType = (LSL_String)commandList.Data[i + 1];
  10453. update = true;
  10454. }
  10455. else Error("llParcelMediaCommandList", "The argument of PARCEL_MEDIA_COMMAND_TYPE must be a string");
  10456. ++i;
  10457. }
  10458. break;
  10459. case ParcelMediaCommandEnum.Desc:
  10460. if ((i + 1) < commandList.Length)
  10461. {
  10462. if (commandList.Data[i + 1] is LSL_String)
  10463. {
  10464. description = (LSL_String)commandList.Data[i + 1];
  10465. update = true;
  10466. }
  10467. else Error("llParcelMediaCommandList", "The argument of PARCEL_MEDIA_COMMAND_DESC must be a string");
  10468. ++i;
  10469. }
  10470. break;
  10471. case ParcelMediaCommandEnum.Size:
  10472. if ((i + 2) < commandList.Length)
  10473. {
  10474. if (commandList.Data[i + 1] is LSL_Integer)
  10475. {
  10476. if (commandList.Data[i + 2] is LSL_Integer)
  10477. {
  10478. width = (LSL_Integer)commandList.Data[i + 1];
  10479. height = (LSL_Integer)commandList.Data[i + 2];
  10480. update = true;
  10481. }
  10482. else Error("llParcelMediaCommandList", "The second argument of PARCEL_MEDIA_COMMAND_SIZE must be an integer");
  10483. }
  10484. else Error("llParcelMediaCommandList", "The first argument of PARCEL_MEDIA_COMMAND_SIZE must be an integer");
  10485. i += 2;
  10486. }
  10487. break;
  10488. default:
  10489. NotImplemented("llParcelMediaCommandList", "Parameter not supported yet: " + Enum.Parse(typeof(ParcelMediaCommandEnum), commandList.Data[i].ToString()).ToString());
  10490. break;
  10491. }//end switch
  10492. }//end for
  10493. // if we didn't get a presence, we send to all and change the url
  10494. // if we did get a presence, we only send to the agent specified, and *don't change the land settings*!
  10495. // did something important change or do we only start/stop/pause?
  10496. if (update)
  10497. {
  10498. if (presence == null)
  10499. {
  10500. // we send to all
  10501. landData.MediaID = new UUID(texture);
  10502. landData.MediaAutoScale = autoAlign ? (byte)1 : (byte)0;
  10503. landData.MediaWidth = width;
  10504. landData.MediaHeight = height;
  10505. landData.MediaType = mediaType;
  10506. // do that one last, it will cause a ParcelPropertiesUpdate
  10507. landObject.SetMediaUrl(url);
  10508. // now send to all (non-child) agents in the parcel
  10509. World.ForEachRootScenePresence(delegate(ScenePresence sp)
  10510. {
  10511. if (sp.currentParcelUUID == landData.GlobalID)
  10512. {
  10513. sp.ControllingClient.SendParcelMediaUpdate(landData.MediaURL,
  10514. landData.MediaID,
  10515. landData.MediaAutoScale,
  10516. mediaType,
  10517. description,
  10518. width, height,
  10519. loop);
  10520. }
  10521. });
  10522. }
  10523. else if (!presence.IsChildAgent)
  10524. {
  10525. // we only send to one (root) agent
  10526. presence.ControllingClient.SendParcelMediaUpdate(url,
  10527. new UUID(texture),
  10528. autoAlign ? (byte)1 : (byte)0,
  10529. mediaType,
  10530. description,
  10531. width, height,
  10532. loop);
  10533. }
  10534. }
  10535. if (commandToSend != null)
  10536. {
  10537. // the commandList contained a start/stop/... command, too
  10538. if (presence == null)
  10539. {
  10540. // send to all (non-child) agents in the parcel
  10541. World.ForEachRootScenePresence(delegate(ScenePresence sp)
  10542. {
  10543. if (sp.currentParcelUUID == landData.GlobalID)
  10544. {
  10545. sp.ControllingClient.SendParcelMediaCommand(0x4, // TODO what is this?
  10546. (ParcelMediaCommandEnum)commandToSend,
  10547. time);
  10548. }
  10549. });
  10550. }
  10551. else if (!presence.IsChildAgent)
  10552. {
  10553. presence.ControllingClient.SendParcelMediaCommand(0x4, // TODO what is this?
  10554. (ParcelMediaCommandEnum)commandToSend,
  10555. time);
  10556. }
  10557. }
  10558. ScriptSleep(m_sleepMsOnParcelMediaCommandList);
  10559. }
  10560. public LSL_List llParcelMediaQuery(LSL_List aList)
  10561. {
  10562. m_host.AddScriptLPS(1);
  10563. LSL_List list = new LSL_List();
  10564. //TO DO: make the implementation for the missing commands
  10565. //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)
  10566. for (int i = 0; i < aList.Data.Length; i++)
  10567. {
  10568. if (aList.Data[i] != null)
  10569. {
  10570. switch ((ParcelMediaCommandEnum) aList.Data[i])
  10571. {
  10572. case ParcelMediaCommandEnum.Url:
  10573. list.Add(new LSL_String(World.GetLandData(m_host.AbsolutePosition).MediaURL));
  10574. break;
  10575. case ParcelMediaCommandEnum.Desc:
  10576. list.Add(new LSL_String(World.GetLandData(m_host.AbsolutePosition).Description));
  10577. break;
  10578. case ParcelMediaCommandEnum.Texture:
  10579. list.Add(new LSL_String(World.GetLandData(m_host.AbsolutePosition).MediaID.ToString()));
  10580. break;
  10581. case ParcelMediaCommandEnum.Type:
  10582. list.Add(new LSL_String(World.GetLandData(m_host.AbsolutePosition).MediaType));
  10583. break;
  10584. case ParcelMediaCommandEnum.Size:
  10585. list.Add(new LSL_String(World.GetLandData(m_host.AbsolutePosition).MediaWidth));
  10586. list.Add(new LSL_String(World.GetLandData(m_host.AbsolutePosition).MediaHeight));
  10587. break;
  10588. default:
  10589. ParcelMediaCommandEnum mediaCommandEnum = ParcelMediaCommandEnum.Url;
  10590. NotImplemented("llParcelMediaQuery", "Parameter not supported yet: " + Enum.Parse(mediaCommandEnum.GetType() , aList.Data[i].ToString()).ToString());
  10591. break;
  10592. }
  10593. }
  10594. }
  10595. ScriptSleep(m_sleepMsOnParcelMediaQuery);
  10596. return list;
  10597. }
  10598. public LSL_Integer llModPow(int a, int b, int c)
  10599. {
  10600. m_host.AddScriptLPS(1);
  10601. Int64 tmp = 0;
  10602. Math.DivRem(Convert.ToInt64(Math.Pow(a, b)), c, out tmp);
  10603. ScriptSleep(m_sleepMsOnModPow);
  10604. return Convert.ToInt32(tmp);
  10605. }
  10606. public LSL_Integer llGetInventoryType(string name)
  10607. {
  10608. m_host.AddScriptLPS(1);
  10609. TaskInventoryItem item = m_host.Inventory.GetInventoryItem(name);
  10610. if (item == null)
  10611. return -1;
  10612. return item.Type;
  10613. }
  10614. public void llSetPayPrice(int price, LSL_List quick_pay_buttons)
  10615. {
  10616. m_host.AddScriptLPS(1);
  10617. if (quick_pay_buttons.Data.Length < 4)
  10618. {
  10619. Error("llSetPayPrice", "List must have at least 4 elements");
  10620. return;
  10621. }
  10622. m_host.ParentGroup.RootPart.PayPrice[0]=price;
  10623. m_host.ParentGroup.RootPart.PayPrice[1]=(LSL_Integer)quick_pay_buttons.Data[0];
  10624. m_host.ParentGroup.RootPart.PayPrice[2]=(LSL_Integer)quick_pay_buttons.Data[1];
  10625. m_host.ParentGroup.RootPart.PayPrice[3]=(LSL_Integer)quick_pay_buttons.Data[2];
  10626. m_host.ParentGroup.RootPart.PayPrice[4]=(LSL_Integer)quick_pay_buttons.Data[3];
  10627. m_host.ParentGroup.HasGroupChanged = true;
  10628. }
  10629. public LSL_Vector llGetCameraPos()
  10630. {
  10631. m_host.AddScriptLPS(1);
  10632. if (m_item.PermsGranter == UUID.Zero)
  10633. return Vector3.Zero;
  10634. if ((m_item.PermsMask & ScriptBaseClass.PERMISSION_TRACK_CAMERA) == 0)
  10635. {
  10636. Error("llGetCameraPos", "No permissions to track the camera");
  10637. return Vector3.Zero;
  10638. }
  10639. ScenePresence presence = World.GetScenePresence(m_host.OwnerID);
  10640. if (presence != null)
  10641. {
  10642. LSL_Vector pos = new LSL_Vector(presence.CameraPosition);
  10643. return pos;
  10644. }
  10645. return Vector3.Zero;
  10646. }
  10647. public LSL_Rotation llGetCameraRot()
  10648. {
  10649. m_host.AddScriptLPS(1);
  10650. if (m_item.PermsGranter == UUID.Zero)
  10651. return Quaternion.Identity;
  10652. if ((m_item.PermsMask & ScriptBaseClass.PERMISSION_TRACK_CAMERA) == 0)
  10653. {
  10654. Error("llGetCameraRot", "No permissions to track the camera");
  10655. return Quaternion.Identity;
  10656. }
  10657. ScenePresence presence = World.GetScenePresence(m_host.OwnerID);
  10658. if (presence != null)
  10659. {
  10660. return new LSL_Rotation(presence.CameraRotation);
  10661. }
  10662. return Quaternion.Identity;
  10663. }
  10664. public void llSetPrimURL(string url)
  10665. {
  10666. m_host.AddScriptLPS(1);
  10667. Deprecated("llSetPrimURL", "Use llSetPrimMediaParams instead");
  10668. ScriptSleep(m_sleepMsOnSetPrimURL);
  10669. }
  10670. public void llRefreshPrimURL()
  10671. {
  10672. m_host.AddScriptLPS(1);
  10673. Deprecated("llRefreshPrimURL");
  10674. ScriptSleep(m_sleepMsOnRefreshPrimURL);
  10675. }
  10676. public LSL_String llEscapeURL(string url)
  10677. {
  10678. m_host.AddScriptLPS(1);
  10679. try
  10680. {
  10681. return Uri.EscapeDataString(url);
  10682. }
  10683. catch (Exception ex)
  10684. {
  10685. return "llEscapeURL: " + ex.ToString();
  10686. }
  10687. }
  10688. public LSL_String llUnescapeURL(string url)
  10689. {
  10690. m_host.AddScriptLPS(1);
  10691. try
  10692. {
  10693. return Uri.UnescapeDataString(url);
  10694. }
  10695. catch (Exception ex)
  10696. {
  10697. return "llUnescapeURL: " + ex.ToString();
  10698. }
  10699. }
  10700. public void llMapDestination(string simname, LSL_Vector pos, LSL_Vector lookAt)
  10701. {
  10702. m_host.AddScriptLPS(1);
  10703. DetectParams detectedParams = m_ScriptEngine.GetDetectParams(m_item.ItemID, 0);
  10704. if (detectedParams == null) return; // only works on the first detected avatar
  10705. ScenePresence avatar = World.GetScenePresence(detectedParams.Key);
  10706. if (avatar != null)
  10707. {
  10708. avatar.ControllingClient.SendScriptTeleportRequest(m_host.Name,
  10709. simname, pos, lookAt);
  10710. }
  10711. ScriptSleep(m_sleepMsOnMapDestination);
  10712. }
  10713. public void llAddToLandBanList(string avatar, double hours)
  10714. {
  10715. m_host.AddScriptLPS(1);
  10716. UUID key;
  10717. ILandObject land = World.LandChannel.GetLandObject(m_host.AbsolutePosition);
  10718. if (World.Permissions.CanEditParcelProperties(m_host.OwnerID, land, GroupPowers.LandManageBanned))
  10719. {
  10720. int expires = 0;
  10721. if (hours != 0)
  10722. expires = Util.UnixTimeSinceEpoch() + (int)(3600.0 * hours);
  10723. if (UUID.TryParse(avatar, out key))
  10724. {
  10725. int idx = land.LandData.ParcelAccessList.FindIndex(
  10726. delegate(LandAccessEntry e)
  10727. {
  10728. if (e.AgentID == key && e.Flags == AccessList.Ban)
  10729. return true;
  10730. return false;
  10731. });
  10732. if (idx != -1 && (land.LandData.ParcelAccessList[idx].Expires == 0 || (expires != 0 && expires < land.LandData.ParcelAccessList[idx].Expires)))
  10733. return;
  10734. if (idx != -1)
  10735. land.LandData.ParcelAccessList.RemoveAt(idx);
  10736. LandAccessEntry entry = new LandAccessEntry();
  10737. entry.AgentID = key;
  10738. entry.Flags = AccessList.Ban;
  10739. entry.Expires = expires;
  10740. land.LandData.ParcelAccessList.Add(entry);
  10741. World.EventManager.TriggerLandObjectUpdated((uint)land.LandData.LocalID, land);
  10742. }
  10743. }
  10744. ScriptSleep(m_sleepMsOnAddToLandBanList);
  10745. }
  10746. public void llRemoveFromLandPassList(string avatar)
  10747. {
  10748. m_host.AddScriptLPS(1);
  10749. UUID key;
  10750. ILandObject land = World.LandChannel.GetLandObject(m_host.AbsolutePosition);
  10751. if (World.Permissions.CanEditParcelProperties(m_host.OwnerID, land, GroupPowers.LandManageAllowed))
  10752. {
  10753. if (UUID.TryParse(avatar, out key))
  10754. {
  10755. int idx = land.LandData.ParcelAccessList.FindIndex(
  10756. delegate(LandAccessEntry e)
  10757. {
  10758. if (e.AgentID == key && e.Flags == AccessList.Access)
  10759. return true;
  10760. return false;
  10761. });
  10762. if (idx != -1)
  10763. {
  10764. land.LandData.ParcelAccessList.RemoveAt(idx);
  10765. World.EventManager.TriggerLandObjectUpdated((uint)land.LandData.LocalID, land);
  10766. }
  10767. }
  10768. }
  10769. ScriptSleep(m_sleepMsOnRemoveFromLandPassList);
  10770. }
  10771. public void llRemoveFromLandBanList(string avatar)
  10772. {
  10773. m_host.AddScriptLPS(1);
  10774. UUID key;
  10775. ILandObject land = World.LandChannel.GetLandObject(m_host.AbsolutePosition);
  10776. if (World.Permissions.CanEditParcelProperties(m_host.OwnerID, land, GroupPowers.LandManageBanned))
  10777. {
  10778. if (UUID.TryParse(avatar, out key))
  10779. {
  10780. int idx = land.LandData.ParcelAccessList.FindIndex(
  10781. delegate(LandAccessEntry e)
  10782. {
  10783. if (e.AgentID == key && e.Flags == AccessList.Ban)
  10784. return true;
  10785. return false;
  10786. });
  10787. if (idx != -1)
  10788. {
  10789. land.LandData.ParcelAccessList.RemoveAt(idx);
  10790. World.EventManager.TriggerLandObjectUpdated((uint)land.LandData.LocalID, land);
  10791. }
  10792. }
  10793. }
  10794. ScriptSleep(m_sleepMsOnRemoveFromLandBanList);
  10795. }
  10796. public void llSetCameraParams(LSL_List rules)
  10797. {
  10798. m_host.AddScriptLPS(1);
  10799. // the object we are in
  10800. UUID objectID = m_host.ParentUUID;
  10801. if (objectID == UUID.Zero)
  10802. return;
  10803. // we need the permission first, to know which avatar we want to set the camera for
  10804. UUID agentID = m_item.PermsGranter;
  10805. if (agentID == UUID.Zero)
  10806. return;
  10807. if ((m_item.PermsMask & ScriptBaseClass.PERMISSION_CONTROL_CAMERA) == 0)
  10808. return;
  10809. ScenePresence presence = World.GetScenePresence(agentID);
  10810. // we are not interested in child-agents
  10811. if (presence.IsChildAgent) return;
  10812. SortedDictionary<int, float> parameters = new SortedDictionary<int, float>();
  10813. object[] data = rules.Data;
  10814. for (int i = 0; i < data.Length; ++i)
  10815. {
  10816. int type;
  10817. try
  10818. {
  10819. type = Convert.ToInt32(data[i++].ToString());
  10820. }
  10821. catch
  10822. {
  10823. Error("llSetCameraParams", string.Format("Invalid camera param type {0}", data[i - 1]));
  10824. return;
  10825. }
  10826. if (i >= data.Length) break; // odd number of entries => ignore the last
  10827. // some special cases: Vector parameters are split into 3 float parameters (with type+1, type+2, type+3)
  10828. switch (type)
  10829. {
  10830. case ScriptBaseClass.CAMERA_FOCUS:
  10831. case ScriptBaseClass.CAMERA_FOCUS_OFFSET:
  10832. case ScriptBaseClass.CAMERA_POSITION:
  10833. LSL_Vector v = (LSL_Vector)data[i];
  10834. try
  10835. {
  10836. parameters.Add(type + 1, (float)v.x);
  10837. }
  10838. catch
  10839. {
  10840. switch(type)
  10841. {
  10842. case ScriptBaseClass.CAMERA_FOCUS:
  10843. Error("llSetCameraParams", "CAMERA_FOCUS: Parameter x is invalid");
  10844. return;
  10845. case ScriptBaseClass.CAMERA_FOCUS_OFFSET:
  10846. Error("llSetCameraParams", "CAMERA_FOCUS_OFFSET: Parameter x is invalid");
  10847. return;
  10848. case ScriptBaseClass.CAMERA_POSITION:
  10849. Error("llSetCameraParams", "CAMERA_POSITION: Parameter x is invalid");
  10850. return;
  10851. }
  10852. }
  10853. try
  10854. {
  10855. parameters.Add(type + 2, (float)v.y);
  10856. }
  10857. catch
  10858. {
  10859. switch(type)
  10860. {
  10861. case ScriptBaseClass.CAMERA_FOCUS:
  10862. Error("llSetCameraParams", "CAMERA_FOCUS: Parameter y is invalid");
  10863. return;
  10864. case ScriptBaseClass.CAMERA_FOCUS_OFFSET:
  10865. Error("llSetCameraParams", "CAMERA_FOCUS_OFFSET: Parameter y is invalid");
  10866. return;
  10867. case ScriptBaseClass.CAMERA_POSITION:
  10868. Error("llSetCameraParams", "CAMERA_POSITION: Parameter y is invalid");
  10869. return;
  10870. }
  10871. }
  10872. try
  10873. {
  10874. parameters.Add(type + 3, (float)v.z);
  10875. }
  10876. catch
  10877. {
  10878. switch(type)
  10879. {
  10880. case ScriptBaseClass.CAMERA_FOCUS:
  10881. Error("llSetCameraParams", "CAMERA_FOCUS: Parameter z is invalid");
  10882. return;
  10883. case ScriptBaseClass.CAMERA_FOCUS_OFFSET:
  10884. Error("llSetCameraParams", "CAMERA_FOCUS_OFFSET: Parameter z is invalid");
  10885. return;
  10886. case ScriptBaseClass.CAMERA_POSITION:
  10887. Error("llSetCameraParams", "CAMERA_POSITION: Parameter z is invalid");
  10888. return;
  10889. }
  10890. }
  10891. break;
  10892. default:
  10893. // TODO: clean that up as soon as the implicit casts are in
  10894. if (data[i] is LSL_Float)
  10895. parameters.Add(type, (float)((LSL_Float)data[i]).value);
  10896. else if (data[i] is LSL_Integer)
  10897. parameters.Add(type, (float)((LSL_Integer)data[i]).value);
  10898. else
  10899. {
  10900. try
  10901. {
  10902. parameters.Add(type, Convert.ToSingle(data[i]));
  10903. }
  10904. catch
  10905. {
  10906. Error("llSetCameraParams", string.Format("{0}: Parameter is invalid", type));
  10907. }
  10908. }
  10909. break;
  10910. }
  10911. }
  10912. if (parameters.Count > 0) presence.ControllingClient.SendSetFollowCamProperties(objectID, parameters);
  10913. }
  10914. public void llClearCameraParams()
  10915. {
  10916. m_host.AddScriptLPS(1);
  10917. // the object we are in
  10918. UUID objectID = m_host.ParentUUID;
  10919. if (objectID == UUID.Zero)
  10920. return;
  10921. // we need the permission first, to know which avatar we want to clear the camera for
  10922. UUID agentID = m_item.PermsGranter;
  10923. if (agentID == UUID.Zero)
  10924. return;
  10925. if ((m_item.PermsMask & ScriptBaseClass.PERMISSION_CONTROL_CAMERA) == 0)
  10926. return;
  10927. ScenePresence presence = World.GetScenePresence(agentID);
  10928. // we are not interested in child-agents
  10929. if (presence.IsChildAgent)
  10930. return;
  10931. presence.ControllingClient.SendClearFollowCamProperties(objectID);
  10932. }
  10933. public LSL_Float llListStatistics(int operation, LSL_List src)
  10934. {
  10935. m_host.AddScriptLPS(1);
  10936. switch (operation)
  10937. {
  10938. case ScriptBaseClass.LIST_STAT_RANGE:
  10939. return src.Range();
  10940. case ScriptBaseClass.LIST_STAT_MIN:
  10941. return src.Min();
  10942. case ScriptBaseClass.LIST_STAT_MAX:
  10943. return src.Max();
  10944. case ScriptBaseClass.LIST_STAT_MEAN:
  10945. return src.Mean();
  10946. case ScriptBaseClass.LIST_STAT_MEDIAN:
  10947. return LSL_List.ToDoubleList(src).Median();
  10948. case ScriptBaseClass.LIST_STAT_NUM_COUNT:
  10949. return src.NumericLength();
  10950. case ScriptBaseClass.LIST_STAT_STD_DEV:
  10951. return src.StdDev();
  10952. case ScriptBaseClass.LIST_STAT_SUM:
  10953. return src.Sum();
  10954. case ScriptBaseClass.LIST_STAT_SUM_SQUARES:
  10955. return src.SumSqrs();
  10956. case ScriptBaseClass.LIST_STAT_GEOMETRIC_MEAN:
  10957. return src.GeometricMean();
  10958. case ScriptBaseClass.LIST_STAT_HARMONIC_MEAN:
  10959. return src.HarmonicMean();
  10960. default:
  10961. return 0.0;
  10962. }
  10963. }
  10964. public LSL_Integer llGetUnixTime()
  10965. {
  10966. m_host.AddScriptLPS(1);
  10967. return Util.UnixTimeSinceEpoch();
  10968. }
  10969. public LSL_Integer llGetParcelFlags(LSL_Vector pos)
  10970. {
  10971. m_host.AddScriptLPS(1);
  10972. return (int)World.LandChannel.GetLandObject((float)pos.x, (float)pos.y).LandData.Flags;
  10973. }
  10974. public LSL_Integer llGetRegionFlags()
  10975. {
  10976. m_host.AddScriptLPS(1);
  10977. IEstateModule estate = World.RequestModuleInterface<IEstateModule>();
  10978. if (estate == null)
  10979. return 67108864;
  10980. return (int)estate.GetRegionFlags();
  10981. }
  10982. public LSL_String llXorBase64StringsCorrect(string str1, string str2)
  10983. {
  10984. m_host.AddScriptLPS(1);
  10985. string ret = String.Empty;
  10986. string src1 = llBase64ToString(str1);
  10987. string src2 = llBase64ToString(str2);
  10988. int c = 0;
  10989. for (int i = 0; i < src1.Length; i++)
  10990. {
  10991. ret += (char) (src1[i] ^ src2[c]);
  10992. c++;
  10993. if (c >= src2.Length)
  10994. c = 0;
  10995. }
  10996. return llStringToBase64(ret);
  10997. }
  10998. public LSL_String llHTTPRequest(string url, LSL_List parameters, string body)
  10999. {
  11000. // Partial implementation: support for parameter flags needed
  11001. // see http://wiki.secondlife.com/wiki/LlHTTPRequest
  11002. // parameter flags support are implemented in ScriptsHttpRequests.cs
  11003. // in StartHttpRequest
  11004. m_host.AddScriptLPS(1);
  11005. IHttpRequestModule httpScriptMod =
  11006. m_ScriptEngine.World.RequestModuleInterface<IHttpRequestModule>();
  11007. List<string> param = new List<string>();
  11008. bool ok;
  11009. Int32 flag;
  11010. for (int i = 0; i < parameters.Data.Length; i += 2)
  11011. {
  11012. ok = Int32.TryParse(parameters.Data[i].ToString(), out flag);
  11013. if (!ok || flag < 0 ||
  11014. flag > (int)HttpRequestConstants.HTTP_PRAGMA_NO_CACHE)
  11015. {
  11016. Error("llHTTPRequest", "Parameter " + i.ToString() + " is an invalid flag");
  11017. }
  11018. param.Add(parameters.Data[i].ToString()); //Add parameter flag
  11019. if (flag != (int)HttpRequestConstants.HTTP_CUSTOM_HEADER)
  11020. {
  11021. param.Add(parameters.Data[i+1].ToString()); //Add parameter value
  11022. }
  11023. else
  11024. {
  11025. //Parameters are in pairs and custom header takes
  11026. //arguments in pairs so adjust for header marker.
  11027. ++i;
  11028. //Maximum of 8 headers are allowed based on the
  11029. //Second Life documentation for llHTTPRequest.
  11030. for (int count = 1; count <= 8; ++count)
  11031. {
  11032. //Enough parameters remaining for (another) header?
  11033. if (parameters.Data.Length - i < 2)
  11034. {
  11035. //There must be at least one name/value pair for custom header
  11036. if (count == 1)
  11037. Error("llHTTPRequest", "Missing name/value for custom header at parameter " + i.ToString());
  11038. break;
  11039. }
  11040. if (HttpStandardHeaders.Contains(parameters.Data[i].ToString(), StringComparer.OrdinalIgnoreCase))
  11041. Error("llHTTPRequest", "Name is invalid as a custom header at parameter " + i.ToString());
  11042. param.Add(parameters.Data[i].ToString());
  11043. param.Add(parameters.Data[i+1].ToString());
  11044. //Have we reached the end of the list of headers?
  11045. //End is marked by a string with a single digit.
  11046. if (i+2 >= parameters.Data.Length ||
  11047. Char.IsDigit(parameters.Data[i].ToString()[0]))
  11048. {
  11049. break;
  11050. }
  11051. i += 2;
  11052. }
  11053. }
  11054. }
  11055. Vector3 position = m_host.AbsolutePosition;
  11056. Vector3 velocity = m_host.Velocity;
  11057. Quaternion rotation = m_host.RotationOffset;
  11058. string ownerName = String.Empty;
  11059. ScenePresence scenePresence = World.GetScenePresence(m_host.OwnerID);
  11060. if (scenePresence == null)
  11061. ownerName = resolveName(m_host.OwnerID);
  11062. else
  11063. ownerName = scenePresence.Name;
  11064. RegionInfo regionInfo = World.RegionInfo;
  11065. Dictionary<string, string> httpHeaders = new Dictionary<string, string>();
  11066. string shard = "OpenSim";
  11067. IConfigSource config = m_ScriptEngine.ConfigSource;
  11068. if (config.Configs["Network"] != null)
  11069. {
  11070. shard = config.Configs["Network"].GetString("shard", shard);
  11071. }
  11072. httpHeaders["X-SecondLife-Shard"] = shard;
  11073. httpHeaders["X-SecondLife-Object-Name"] = m_host.Name;
  11074. httpHeaders["X-SecondLife-Object-Key"] = m_host.UUID.ToString();
  11075. httpHeaders["X-SecondLife-Region"] = string.Format("{0} ({1}, {2})", regionInfo.RegionName, regionInfo.RegionLocX, regionInfo.RegionLocY);
  11076. httpHeaders["X-SecondLife-Local-Position"] = string.Format("({0:0.000000}, {1:0.000000}, {2:0.000000})", position.X, position.Y, position.Z);
  11077. httpHeaders["X-SecondLife-Local-Velocity"] = string.Format("({0:0.000000}, {1:0.000000}, {2:0.000000})", velocity.X, velocity.Y, velocity.Z);
  11078. 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);
  11079. httpHeaders["X-SecondLife-Owner-Name"] = ownerName;
  11080. httpHeaders["X-SecondLife-Owner-Key"] = m_host.OwnerID.ToString();
  11081. string userAgent = config.Configs["Network"].GetString("user_agent", null);
  11082. if (userAgent != null)
  11083. httpHeaders["User-Agent"] = userAgent;
  11084. string authregex = @"^(https?:\/\/)(\w+):(\w+)@(.*)$";
  11085. Regex r = new Regex(authregex);
  11086. int[] gnums = r.GetGroupNumbers();
  11087. Match m = r.Match(url);
  11088. if (m.Success) {
  11089. for (int i = 1; i < gnums.Length; i++) {
  11090. //System.Text.RegularExpressions.Group g = m.Groups[gnums[i]];
  11091. //CaptureCollection cc = g.Captures;
  11092. }
  11093. if (m.Groups.Count == 5) {
  11094. httpHeaders["Authorization"] = String.Format("Basic {0}", Convert.ToBase64String(System.Text.ASCIIEncoding.ASCII.GetBytes(m.Groups[2].ToString() + ":" + m.Groups[3].ToString())));
  11095. url = m.Groups[1].ToString() + m.Groups[4].ToString();
  11096. }
  11097. }
  11098. HttpInitialRequestStatus status;
  11099. UUID reqID
  11100. = httpScriptMod.StartHttpRequest(m_host.LocalId, m_item.ItemID, url, param, httpHeaders, body, out status);
  11101. if (status == HttpInitialRequestStatus.DISALLOWED_BY_FILTER)
  11102. Error("llHttpRequest", string.Format("Request to {0} disallowed by filter", url));
  11103. if (reqID != UUID.Zero)
  11104. return reqID.ToString();
  11105. else
  11106. return null;
  11107. }
  11108. public void llHTTPResponse(LSL_Key id, int status, string body)
  11109. {
  11110. // Partial implementation: support for parameter flags needed
  11111. // see http://wiki.secondlife.com/wiki/llHTTPResponse
  11112. m_host.AddScriptLPS(1);
  11113. if (m_UrlModule != null)
  11114. m_UrlModule.HttpResponse(new UUID(id), status,body);
  11115. }
  11116. public void llResetLandBanList()
  11117. {
  11118. m_host.AddScriptLPS(1);
  11119. LandData land = World.LandChannel.GetLandObject(m_host.AbsolutePosition).LandData;
  11120. if (land.OwnerID == m_host.OwnerID)
  11121. {
  11122. foreach (LandAccessEntry entry in land.ParcelAccessList)
  11123. {
  11124. if (entry.Flags == AccessList.Ban)
  11125. {
  11126. land.ParcelAccessList.Remove(entry);
  11127. }
  11128. }
  11129. }
  11130. ScriptSleep(m_sleepMsOnResetLandBanList);
  11131. }
  11132. public void llResetLandPassList()
  11133. {
  11134. m_host.AddScriptLPS(1);
  11135. LandData land = World.LandChannel.GetLandObject(m_host.AbsolutePosition).LandData;
  11136. if (land.OwnerID == m_host.OwnerID)
  11137. {
  11138. foreach (LandAccessEntry entry in land.ParcelAccessList)
  11139. {
  11140. if (entry.Flags == AccessList.Access)
  11141. {
  11142. land.ParcelAccessList.Remove(entry);
  11143. }
  11144. }
  11145. }
  11146. ScriptSleep(m_sleepMsOnResetLandPassList);
  11147. }
  11148. public LSL_Integer llGetParcelPrimCount(LSL_Vector pos, int category, int sim_wide)
  11149. {
  11150. m_host.AddScriptLPS(1);
  11151. ILandObject lo = World.LandChannel.GetLandObject((float)pos.x, (float)pos.y);
  11152. if (lo == null)
  11153. return 0;
  11154. IPrimCounts pc = lo.PrimCounts;
  11155. if (sim_wide != ScriptBaseClass.FALSE)
  11156. {
  11157. if (category == ScriptBaseClass.PARCEL_COUNT_TOTAL)
  11158. {
  11159. return pc.Simulator;
  11160. }
  11161. else
  11162. {
  11163. // counts not implemented yet
  11164. return 0;
  11165. }
  11166. }
  11167. else
  11168. {
  11169. if (category == ScriptBaseClass.PARCEL_COUNT_TOTAL)
  11170. return pc.Total;
  11171. else if (category == ScriptBaseClass.PARCEL_COUNT_OWNER)
  11172. return pc.Owner;
  11173. else if (category == ScriptBaseClass.PARCEL_COUNT_GROUP)
  11174. return pc.Group;
  11175. else if (category == ScriptBaseClass.PARCEL_COUNT_OTHER)
  11176. return pc.Others;
  11177. else if (category == ScriptBaseClass.PARCEL_COUNT_SELECTED)
  11178. return pc.Selected;
  11179. else if (category == ScriptBaseClass.PARCEL_COUNT_TEMP)
  11180. return 0; // counts not implemented yet
  11181. }
  11182. return 0;
  11183. }
  11184. public LSL_List llGetParcelPrimOwners(LSL_Vector pos)
  11185. {
  11186. m_host.AddScriptLPS(1);
  11187. LandObject land = (LandObject)World.LandChannel.GetLandObject((float)pos.x, (float)pos.y);
  11188. LSL_List ret = new LSL_List();
  11189. if (land != null)
  11190. {
  11191. foreach (KeyValuePair<UUID, int> detectedParams in land.GetLandObjectOwners())
  11192. {
  11193. ret.Add(new LSL_String(detectedParams.Key.ToString()));
  11194. ret.Add(new LSL_Integer(detectedParams.Value));
  11195. }
  11196. }
  11197. ScriptSleep(m_sleepMsOnGetParcelPrimOwners);
  11198. return ret;
  11199. }
  11200. public LSL_Integer llGetObjectPrimCount(string object_id)
  11201. {
  11202. m_host.AddScriptLPS(1);
  11203. SceneObjectPart part = World.GetSceneObjectPart(new UUID(object_id));
  11204. if (part == null)
  11205. {
  11206. return 0;
  11207. }
  11208. else
  11209. {
  11210. return part.ParentGroup.PrimCount;
  11211. }
  11212. }
  11213. public LSL_Integer llGetParcelMaxPrims(LSL_Vector pos, int sim_wide)
  11214. {
  11215. m_host.AddScriptLPS(1);
  11216. ILandObject lo = World.LandChannel.GetLandObject((float)pos.x, (float)pos.y);
  11217. if (lo == null)
  11218. return 0;
  11219. if (sim_wide != 0)
  11220. return lo.GetSimulatorMaxPrimCount();
  11221. else
  11222. return lo.GetParcelMaxPrimCount();
  11223. }
  11224. public LSL_List llGetParcelDetails(LSL_Vector pos, LSL_List param)
  11225. {
  11226. m_host.AddScriptLPS(1);
  11227. LandData land = World.GetLandData(pos);
  11228. if (land == null)
  11229. {
  11230. return new LSL_List(0);
  11231. }
  11232. LSL_List ret = new LSL_List();
  11233. foreach (object o in param.Data)
  11234. {
  11235. switch (o.ToString())
  11236. {
  11237. case "0":
  11238. ret.Add(new LSL_String(land.Name));
  11239. break;
  11240. case "1":
  11241. ret.Add(new LSL_String(land.Description));
  11242. break;
  11243. case "2":
  11244. ret.Add(new LSL_Key(land.OwnerID.ToString()));
  11245. break;
  11246. case "3":
  11247. ret.Add(new LSL_Key(land.GroupID.ToString()));
  11248. break;
  11249. case "4":
  11250. ret.Add(new LSL_Integer(land.Area));
  11251. break;
  11252. case "5":
  11253. ret.Add(new LSL_Key(land.GlobalID.ToString()));
  11254. break;
  11255. default:
  11256. ret.Add(new LSL_Integer(0));
  11257. break;
  11258. }
  11259. }
  11260. return ret;
  11261. }
  11262. public LSL_String llStringTrim(string src, int type)
  11263. {
  11264. m_host.AddScriptLPS(1);
  11265. if (type == (int)ScriptBaseClass.STRING_TRIM_HEAD) { return src.TrimStart(); }
  11266. if (type == (int)ScriptBaseClass.STRING_TRIM_TAIL) { return src.TrimEnd(); }
  11267. if (type == (int)ScriptBaseClass.STRING_TRIM) { return src.Trim(); }
  11268. return src;
  11269. }
  11270. public LSL_List llGetObjectDetails(string id, LSL_List args)
  11271. {
  11272. m_host.AddScriptLPS(1);
  11273. LSL_List ret = new LSL_List();
  11274. UUID key = new UUID();
  11275. if (UUID.TryParse(id, out key))
  11276. {
  11277. ScenePresence av = World.GetScenePresence(key);
  11278. if (av != null)
  11279. {
  11280. foreach (object o in args.Data)
  11281. {
  11282. switch (int.Parse(o.ToString()))
  11283. {
  11284. case ScriptBaseClass.OBJECT_NAME:
  11285. ret.Add(new LSL_String(av.Firstname + " " + av.Lastname));
  11286. break;
  11287. case ScriptBaseClass.OBJECT_DESC:
  11288. ret.Add(new LSL_String(""));
  11289. break;
  11290. case ScriptBaseClass.OBJECT_POS:
  11291. ret.Add(new LSL_Vector((double)av.AbsolutePosition.X, (double)av.AbsolutePosition.Y, (double)av.AbsolutePosition.Z));
  11292. break;
  11293. case ScriptBaseClass.OBJECT_ROT:
  11294. ret.Add(new LSL_Rotation(av.GetWorldRotation()));
  11295. break;
  11296. case ScriptBaseClass.OBJECT_VELOCITY:
  11297. ret.Add(new LSL_Vector(av.GetWorldVelocity()));
  11298. break;
  11299. case ScriptBaseClass.OBJECT_OWNER:
  11300. ret.Add(new LSL_String(id));
  11301. break;
  11302. case ScriptBaseClass.OBJECT_GROUP:
  11303. ret.Add(new LSL_String(UUID.Zero.ToString()));
  11304. break;
  11305. case ScriptBaseClass.OBJECT_CREATOR:
  11306. ret.Add(new LSL_String(UUID.Zero.ToString()));
  11307. break;
  11308. // For the following 8 see the Object version below
  11309. case ScriptBaseClass.OBJECT_RUNNING_SCRIPT_COUNT:
  11310. ret.Add(new LSL_Integer(av.RunningScriptCount()));
  11311. break;
  11312. case ScriptBaseClass.OBJECT_TOTAL_SCRIPT_COUNT:
  11313. ret.Add(new LSL_Integer(av.ScriptCount()));
  11314. break;
  11315. case ScriptBaseClass.OBJECT_SCRIPT_MEMORY:
  11316. ret.Add(new LSL_Integer(av.RunningScriptCount() * 16384));
  11317. break;
  11318. case ScriptBaseClass.OBJECT_SCRIPT_TIME:
  11319. ret.Add(new LSL_Float(av.ScriptExecutionTime() / 1000.0f));
  11320. break;
  11321. case ScriptBaseClass.OBJECT_PRIM_EQUIVALENCE:
  11322. ret.Add(new LSL_Integer(1));
  11323. break;
  11324. case ScriptBaseClass.OBJECT_SERVER_COST:
  11325. ret.Add(new LSL_Float(0));
  11326. break;
  11327. case ScriptBaseClass.OBJECT_STREAMING_COST:
  11328. ret.Add(new LSL_Float(0));
  11329. break;
  11330. case ScriptBaseClass.OBJECT_PHYSICS_COST:
  11331. ret.Add(new LSL_Float(0));
  11332. break;
  11333. case ScriptBaseClass.OBJECT_CHARACTER_TIME: // Pathfinding
  11334. ret.Add(new LSL_Float(0));
  11335. break;
  11336. case ScriptBaseClass.OBJECT_ROOT:
  11337. SceneObjectPart p = av.ParentPart;
  11338. if (p != null)
  11339. {
  11340. ret.Add(new LSL_String(p.ParentGroup.RootPart.UUID.ToString()));
  11341. }
  11342. else
  11343. {
  11344. ret.Add(new LSL_String(id));
  11345. }
  11346. break;
  11347. case ScriptBaseClass.OBJECT_ATTACHED_POINT:
  11348. ret.Add(new LSL_Integer(0));
  11349. break;
  11350. case ScriptBaseClass.OBJECT_PATHFINDING_TYPE: // Pathfinding
  11351. ret.Add(new LSL_Integer(ScriptBaseClass.OPT_AVATAR));
  11352. break;
  11353. case ScriptBaseClass.OBJECT_PHYSICS:
  11354. ret.Add(new LSL_Integer(0));
  11355. break;
  11356. case ScriptBaseClass.OBJECT_PHANTOM:
  11357. ret.Add(new LSL_Integer(0));
  11358. break;
  11359. case ScriptBaseClass.OBJECT_TEMP_ON_REZ:
  11360. ret.Add(new LSL_Integer(0));
  11361. break;
  11362. case ScriptBaseClass.OBJECT_RENDER_WEIGHT:
  11363. ret.Add(new LSL_Integer(-1));
  11364. break;
  11365. case ScriptBaseClass.OBJECT_HOVER_HEIGHT:
  11366. ret.Add(new LSL_Float(0));
  11367. break;
  11368. case ScriptBaseClass.OBJECT_BODY_SHAPE_TYPE:
  11369. LSL_Float shapeType;
  11370. if (av.Appearance.VisualParams[(int)AvatarAppearance.VPElement.SHAPE_MALE] != 0)
  11371. shapeType = new LSL_Float(1);
  11372. else
  11373. shapeType = new LSL_Float(0);
  11374. ret.Add(shapeType);
  11375. break;
  11376. case ScriptBaseClass.OBJECT_LAST_OWNER_ID:
  11377. ret.Add(new LSL_Key(ScriptBaseClass.NULL_KEY));
  11378. break;
  11379. default:
  11380. // Invalid or unhandled constant.
  11381. ret.Add(new LSL_Integer(ScriptBaseClass.OBJECT_UNKNOWN_DETAIL));
  11382. break;
  11383. }
  11384. }
  11385. return ret;
  11386. }
  11387. SceneObjectPart obj = World.GetSceneObjectPart(key);
  11388. if (obj != null)
  11389. {
  11390. foreach (object o in args.Data)
  11391. {
  11392. switch (int.Parse(o.ToString()))
  11393. {
  11394. case ScriptBaseClass.OBJECT_NAME:
  11395. ret.Add(new LSL_String(obj.Name));
  11396. break;
  11397. case ScriptBaseClass.OBJECT_DESC:
  11398. ret.Add(new LSL_String(obj.Description));
  11399. break;
  11400. case ScriptBaseClass.OBJECT_POS:
  11401. ret.Add(new LSL_Vector(obj.AbsolutePosition.X, obj.AbsolutePosition.Y, obj.AbsolutePosition.Z));
  11402. break;
  11403. case ScriptBaseClass.OBJECT_ROT:
  11404. Quaternion rot = Quaternion.Identity;
  11405. if (obj.ParentGroup.IsAttachment)
  11406. {
  11407. ScenePresence sp = World.GetScenePresence(obj.ParentGroup.AttachedAvatar);
  11408. if (sp != null)
  11409. rot = sp.GetWorldRotation();
  11410. }
  11411. else
  11412. {
  11413. if (obj.ParentGroup.RootPart == obj)
  11414. rot = obj.ParentGroup.GroupRotation;
  11415. else
  11416. rot = obj.GetWorldRotation();
  11417. }
  11418. LSL_Rotation objrot = new LSL_Rotation(rot);
  11419. ret.Add(objrot);
  11420. break;
  11421. case ScriptBaseClass.OBJECT_VELOCITY:
  11422. Vector3 vel = Vector3.Zero;
  11423. if (obj.ParentGroup.IsAttachment)
  11424. {
  11425. ScenePresence sp = World.GetScenePresence(obj.ParentGroup.AttachedAvatar);
  11426. if (sp != null)
  11427. vel = sp.GetWorldVelocity();
  11428. }
  11429. else
  11430. {
  11431. vel = obj.Velocity;
  11432. }
  11433. ret.Add(vel);
  11434. break;
  11435. case ScriptBaseClass.OBJECT_OWNER:
  11436. ret.Add(new LSL_String(obj.OwnerID.ToString()));
  11437. break;
  11438. case ScriptBaseClass.OBJECT_GROUP:
  11439. ret.Add(new LSL_String(obj.GroupID.ToString()));
  11440. break;
  11441. case ScriptBaseClass.OBJECT_CREATOR:
  11442. ret.Add(new LSL_String(obj.CreatorID.ToString()));
  11443. break;
  11444. case ScriptBaseClass.OBJECT_RUNNING_SCRIPT_COUNT:
  11445. ret.Add(new LSL_Integer(obj.ParentGroup.RunningScriptCount()));
  11446. break;
  11447. case ScriptBaseClass.OBJECT_TOTAL_SCRIPT_COUNT:
  11448. ret.Add(new LSL_Integer(obj.ParentGroup.ScriptCount()));
  11449. break;
  11450. case ScriptBaseClass.OBJECT_SCRIPT_MEMORY:
  11451. // The value returned in SL for mono scripts is 65536 * number of active scripts
  11452. // and 16384 * number of active scripts for LSO. since llGetFreememory
  11453. // is coded to give the LSO value use it here
  11454. ret.Add(new LSL_Integer(obj.ParentGroup.RunningScriptCount() * 16384));
  11455. break;
  11456. case ScriptBaseClass.OBJECT_SCRIPT_TIME:
  11457. // Average cpu time in seconds per simulator frame expended on all scripts in the object
  11458. ret.Add(new LSL_Float(obj.ParentGroup.ScriptExecutionTime() / 1000.0f));
  11459. break;
  11460. case ScriptBaseClass.OBJECT_PRIM_EQUIVALENCE:
  11461. // according to the SL wiki A prim or linkset will have prim
  11462. // equivalent of the number of prims in a linkset if it does not
  11463. // contain a mesh anywhere in the link set or is not a normal prim
  11464. // The value returned in SL for normal prims is prim count
  11465. ret.Add(new LSL_Integer(obj.ParentGroup.PrimCount));
  11466. break;
  11467. // The following 3 costs I have intentionaly coded to return zero. They are part of
  11468. // "Land Impact" calculations. These calculations are probably not applicable
  11469. // to OpenSim and are not yet complete in SL
  11470. case ScriptBaseClass.OBJECT_SERVER_COST:
  11471. // The linden calculation is here
  11472. // http://wiki.secondlife.com/wiki/Mesh/Mesh_Server_Weight
  11473. // The value returned in SL for normal prims looks like the prim count
  11474. ret.Add(new LSL_Float(0));
  11475. break;
  11476. case ScriptBaseClass.OBJECT_STREAMING_COST:
  11477. // The linden calculation is here
  11478. // http://wiki.secondlife.com/wiki/Mesh/Mesh_Streaming_Cost
  11479. // The value returned in SL for normal prims looks like the prim count * 0.06
  11480. ret.Add(new LSL_Float(0));
  11481. break;
  11482. case ScriptBaseClass.OBJECT_PHYSICS_COST:
  11483. // The linden calculation is here
  11484. // http://wiki.secondlife.com/wiki/Mesh/Mesh_physics
  11485. // The value returned in SL for normal prims looks like the prim count
  11486. ret.Add(new LSL_Float(0));
  11487. break;
  11488. case ScriptBaseClass.OBJECT_CHARACTER_TIME: // Pathfinding
  11489. ret.Add(new LSL_Float(0));
  11490. break;
  11491. case ScriptBaseClass.OBJECT_ROOT:
  11492. ret.Add(new LSL_String(obj.ParentGroup.RootPart.UUID.ToString()));
  11493. break;
  11494. case ScriptBaseClass.OBJECT_ATTACHED_POINT:
  11495. ret.Add(new LSL_Integer(obj.ParentGroup.AttachmentPoint));
  11496. break;
  11497. case ScriptBaseClass.OBJECT_PATHFINDING_TYPE:
  11498. byte pcode = obj.Shape.PCode;
  11499. if (obj.ParentGroup.AttachmentPoint != 0
  11500. || pcode == (byte)PCode.Grass
  11501. || pcode == (byte)PCode.Tree
  11502. || pcode == (byte)PCode.NewTree)
  11503. {
  11504. ret.Add(new LSL_Integer(ScriptBaseClass.OPT_OTHER));
  11505. }
  11506. else
  11507. {
  11508. ret.Add(new LSL_Integer(ScriptBaseClass.OPT_LEGACY_LINKSET));
  11509. }
  11510. break;
  11511. case ScriptBaseClass.OBJECT_PHYSICS:
  11512. if (obj.ParentGroup.AttachmentPoint != 0)
  11513. {
  11514. ret.Add(new LSL_Integer(0)); // Always false if attached
  11515. }
  11516. else
  11517. {
  11518. ret.Add(new LSL_Integer(obj.ParentGroup.UsesPhysics ? 1 : 0));
  11519. }
  11520. break;
  11521. case ScriptBaseClass.OBJECT_PHANTOM:
  11522. if (obj.ParentGroup.AttachmentPoint != 0)
  11523. {
  11524. ret.Add(new LSL_Integer(0)); // Always false if attached
  11525. }
  11526. else
  11527. {
  11528. ret.Add(new LSL_Integer(obj.ParentGroup.IsPhantom ? 1 : 0));
  11529. }
  11530. break;
  11531. case ScriptBaseClass.OBJECT_TEMP_ON_REZ:
  11532. ret.Add(new LSL_Integer(obj.ParentGroup.IsTemporary ? 1 : 0));
  11533. break;
  11534. case ScriptBaseClass.OBJECT_RENDER_WEIGHT:
  11535. ret.Add(new LSL_Integer(0));
  11536. break;
  11537. case ScriptBaseClass.OBJECT_HOVER_HEIGHT:
  11538. ret.Add(new LSL_Float(0));
  11539. break;
  11540. case ScriptBaseClass.OBJECT_BODY_SHAPE_TYPE:
  11541. ret.Add(new LSL_Float(-1));
  11542. break;
  11543. case ScriptBaseClass.OBJECT_LAST_OWNER_ID:
  11544. ret.Add(new LSL_Key(obj.ParentGroup.LastOwnerID.ToString()));
  11545. break;
  11546. default:
  11547. // Invalid or unhandled constant.
  11548. ret.Add(new LSL_Integer(ScriptBaseClass.OBJECT_UNKNOWN_DETAIL));
  11549. break;
  11550. }
  11551. }
  11552. return ret;
  11553. }
  11554. }
  11555. return new LSL_List();
  11556. }
  11557. internal UUID GetScriptByName(string name)
  11558. {
  11559. TaskInventoryItem item = m_host.Inventory.GetInventoryItem(name);
  11560. if (item == null || item.Type != 10)
  11561. return UUID.Zero;
  11562. return item.ItemID;
  11563. }
  11564. /// <summary>
  11565. /// Reports the script error in the viewer's Script Warning/Error dialog and shouts it on the debug channel.
  11566. /// </summary>
  11567. /// <param name="command">The name of the command that generated the error.</param>
  11568. /// <param name="message">The error message to report to the user.</param>
  11569. internal void Error(string command, string message)
  11570. {
  11571. string text = command + ": " + message;
  11572. if (text.Length > 1023)
  11573. {
  11574. text = text.Substring(0, 1023);
  11575. }
  11576. World.SimChat(Utils.StringToBytes(text), ChatTypeEnum.DebugChannel, ScriptBaseClass.DEBUG_CHANNEL,
  11577. m_host.ParentGroup.RootPart.AbsolutePosition, m_host.Name, m_host.UUID, false);
  11578. IWorldComm wComm = m_ScriptEngine.World.RequestModuleInterface<IWorldComm>();
  11579. if (wComm != null)
  11580. {
  11581. wComm.DeliverMessage(ChatTypeEnum.Shout, ScriptBaseClass.DEBUG_CHANNEL, m_host.Name, m_host.UUID, text);
  11582. }
  11583. }
  11584. /// <summary>
  11585. /// Reports that the command is not implemented as a script error.
  11586. /// </summary>
  11587. /// <param name="command">The name of the command that is not implemented.</param>
  11588. /// <param name="message">Additional information to report to the user. (Optional)</param>
  11589. internal void NotImplemented(string command, string message = "")
  11590. {
  11591. if (throwErrorOnNotImplemented)
  11592. {
  11593. if (message != "")
  11594. {
  11595. message = " - " + message;
  11596. }
  11597. throw new NotImplementedException("Command not implemented: " + command + message);
  11598. }
  11599. else
  11600. {
  11601. string text = "Command not implemented";
  11602. if (message != "")
  11603. {
  11604. text = text + " - " + message;
  11605. }
  11606. Error(command, text);
  11607. }
  11608. }
  11609. /// <summary>
  11610. /// Reports that the command is deprecated as a script error.
  11611. /// </summary>
  11612. /// <param name="command">The name of the command that is deprecated.</param>
  11613. /// <param name="message">Additional information to report to the user. (Optional)</param>
  11614. internal void Deprecated(string command, string message = "")
  11615. {
  11616. string text = "Command deprecated";
  11617. if (message != "")
  11618. {
  11619. text = text + " - " + message;
  11620. }
  11621. Error(command, text);
  11622. }
  11623. public delegate void AssetRequestCallback(UUID assetID, AssetBase asset);
  11624. protected void WithNotecard(UUID assetID, AssetRequestCallback cb)
  11625. {
  11626. World.AssetService.Get(assetID.ToString(), this,
  11627. delegate(string i, object sender, AssetBase a)
  11628. {
  11629. UUID uuid = UUID.Zero;
  11630. UUID.TryParse(i, out uuid);
  11631. cb(uuid, a);
  11632. });
  11633. }
  11634. public LSL_String llGetNumberOfNotecardLines(string name)
  11635. {
  11636. m_host.AddScriptLPS(1);
  11637. UUID assetID = UUID.Zero;
  11638. if (!UUID.TryParse(name, out assetID))
  11639. {
  11640. TaskInventoryItem item = m_host.Inventory.GetInventoryItem(name);
  11641. if (item != null && item.Type == 7)
  11642. assetID = item.AssetID;
  11643. }
  11644. if (assetID == UUID.Zero)
  11645. {
  11646. // => complain loudly, as specified by the LSL docs
  11647. Error("llGetNumberOfNotecardLines", "Can't find notecard '" + name + "'");
  11648. return UUID.Zero.ToString();
  11649. }
  11650. string reqIdentifier = UUID.Random().ToString();
  11651. // was: UUID tid = tid = AsyncCommands.
  11652. UUID tid = AsyncCommands.DataserverPlugin.RegisterRequest(m_host.LocalId, m_item.ItemID, reqIdentifier);
  11653. if (NotecardCache.IsCached(assetID))
  11654. {
  11655. AsyncCommands.DataserverPlugin.DataserverReply(reqIdentifier, NotecardCache.GetLines(assetID).ToString());
  11656. ScriptSleep(m_sleepMsOnGetNumberOfNotecardLines);
  11657. return tid.ToString();
  11658. }
  11659. WithNotecard(assetID, delegate (UUID id, AssetBase a)
  11660. {
  11661. if (a == null || a.Type != 7)
  11662. {
  11663. Error("llGetNumberOfNotecardLines", "Can't find notecard '" + name + "'");
  11664. return;
  11665. }
  11666. NotecardCache.Cache(id, a.Data);
  11667. AsyncCommands.DataserverPlugin.DataserverReply(reqIdentifier, NotecardCache.GetLines(id).ToString());
  11668. });
  11669. ScriptSleep(m_sleepMsOnGetNumberOfNotecardLines);
  11670. return tid.ToString();
  11671. }
  11672. public LSL_String llGetNotecardLine(string name, int line)
  11673. {
  11674. m_host.AddScriptLPS(1);
  11675. UUID assetID = UUID.Zero;
  11676. if (!UUID.TryParse(name, out assetID))
  11677. {
  11678. TaskInventoryItem item = m_host.Inventory.GetInventoryItem(name);
  11679. if (item != null && item.Type == 7)
  11680. assetID = item.AssetID;
  11681. }
  11682. if (assetID == UUID.Zero)
  11683. {
  11684. // => complain loudly, as specified by the LSL docs
  11685. Error("llGetNotecardLine", "Can't find notecard '" + name + "'");
  11686. return UUID.Zero.ToString();
  11687. }
  11688. string reqIdentifier = UUID.Random().ToString();
  11689. // was: UUID tid = tid = AsyncCommands.
  11690. UUID tid = AsyncCommands.DataserverPlugin.RegisterRequest(m_host.LocalId, m_item.ItemID, reqIdentifier);
  11691. if (NotecardCache.IsCached(assetID))
  11692. {
  11693. AsyncCommands.DataserverPlugin.DataserverReply(
  11694. reqIdentifier, NotecardCache.GetLine(assetID, line, m_notecardLineReadCharsMax));
  11695. ScriptSleep(m_sleepMsOnGetNotecardLine);
  11696. return tid.ToString();
  11697. }
  11698. WithNotecard(assetID, delegate (UUID id, AssetBase a)
  11699. {
  11700. if (a == null || a.Type != 7)
  11701. {
  11702. Error("llGetNotecardLine", "Can't find notecard '" + name + "'");
  11703. return;
  11704. }
  11705. string data = Encoding.UTF8.GetString(a.Data);
  11706. //m_log.Debug(data);
  11707. NotecardCache.Cache(id, a.Data);
  11708. AsyncCommands.DataserverPlugin.DataserverReply(
  11709. reqIdentifier, NotecardCache.GetLine(assetID, line, m_notecardLineReadCharsMax));
  11710. });
  11711. ScriptSleep(m_sleepMsOnGetNotecardLine);
  11712. return tid.ToString();
  11713. }
  11714. public void SetPrimitiveParamsEx(LSL_Key prim, LSL_List rules, string originFunc)
  11715. {
  11716. SceneObjectPart obj = World.GetSceneObjectPart(new UUID(prim));
  11717. if (obj == null)
  11718. return;
  11719. if (obj.OwnerID != m_host.OwnerID)
  11720. return;
  11721. SetEntityParams(new List<ISceneEntity>() { obj }, rules, originFunc);
  11722. }
  11723. public LSL_List GetPrimitiveParamsEx(LSL_Key prim, LSL_List rules)
  11724. {
  11725. SceneObjectPart obj = World.GetSceneObjectPart(new UUID(prim));
  11726. if (obj != null && obj.OwnerID == m_host.OwnerID)
  11727. return GetEntityParams(obj, rules);
  11728. return new LSL_List();
  11729. }
  11730. public void print(string str)
  11731. {
  11732. // yes, this is a real LSL function. See: http://wiki.secondlife.com/wiki/Print
  11733. IOSSL_Api ossl = (IOSSL_Api)m_ScriptEngine.GetApi(m_item.ItemID, "OSSL");
  11734. if (ossl != null)
  11735. {
  11736. ossl.CheckThreatLevel(ThreatLevel.High, "print");
  11737. m_log.Info("LSL print():" + str);
  11738. }
  11739. }
  11740. private string Name2Username(string name)
  11741. {
  11742. string[] parts = name.Split(new char[] {' '});
  11743. if (parts.Length < 2)
  11744. return name.ToLower();
  11745. if (parts[1] == "Resident")
  11746. return parts[0].ToLower();
  11747. return name.Replace(" ", ".").ToLower();
  11748. }
  11749. public LSL_String llGetUsername(string id)
  11750. {
  11751. return Name2Username(llKey2Name(id));
  11752. }
  11753. public LSL_String llRequestUsername(string id)
  11754. {
  11755. UUID rq = UUID.Random();
  11756. AsyncCommands.DataserverPlugin.RegisterRequest(m_host.LocalId, m_item.ItemID, rq.ToString());
  11757. AsyncCommands.DataserverPlugin.DataserverReply(rq.ToString(), Name2Username(llKey2Name(id)));
  11758. return rq.ToString();
  11759. }
  11760. public LSL_String llGetDisplayName(string id)
  11761. {
  11762. return llKey2Name(id);
  11763. }
  11764. public LSL_String llRequestDisplayName(string id)
  11765. {
  11766. UUID rq = UUID.Random();
  11767. AsyncCommands.DataserverPlugin.RegisterRequest(m_host.LocalId, m_item.ItemID, rq.ToString());
  11768. AsyncCommands.DataserverPlugin.DataserverReply(rq.ToString(), llKey2Name(id));
  11769. return rq.ToString();
  11770. }
  11771. private struct Tri
  11772. {
  11773. public Vector3 p1;
  11774. public Vector3 p2;
  11775. public Vector3 p3;
  11776. }
  11777. private bool InBoundingBox(ScenePresence avatar, Vector3 point)
  11778. {
  11779. float height = avatar.Appearance.AvatarHeight;
  11780. Vector3 b1 = avatar.AbsolutePosition + new Vector3(-0.22f, -0.22f, -height/2);
  11781. Vector3 b2 = avatar.AbsolutePosition + new Vector3(0.22f, 0.22f, height/2);
  11782. if (point.X > b1.X && point.X < b2.X &&
  11783. point.Y > b1.Y && point.Y < b2.Y &&
  11784. point.Z > b1.Z && point.Z < b2.Z)
  11785. return true;
  11786. return false;
  11787. }
  11788. private ContactResult[] AvatarIntersection(Vector3 rayStart, Vector3 rayEnd)
  11789. {
  11790. List<ContactResult> contacts = new List<ContactResult>();
  11791. Vector3 ab = rayEnd - rayStart;
  11792. World.ForEachScenePresence(delegate(ScenePresence sp)
  11793. {
  11794. Vector3 ac = sp.AbsolutePosition - rayStart;
  11795. // Vector3 bc = sp.AbsolutePosition - rayEnd;
  11796. double d = Math.Abs(Vector3.Mag(Vector3.Cross(ab, ac)) / Vector3.Distance(rayStart, rayEnd));
  11797. if (d > 1.5)
  11798. return;
  11799. double d2 = Vector3.Dot(Vector3.Negate(ab), ac);
  11800. if (d2 > 0)
  11801. return;
  11802. double dp = Math.Sqrt(Vector3.Mag(ac) * Vector3.Mag(ac) - d * d);
  11803. Vector3 p = rayStart + Vector3.Divide(Vector3.Multiply(ab, (float)dp), (float)Vector3.Mag(ab));
  11804. if (!InBoundingBox(sp, p))
  11805. return;
  11806. ContactResult result = new ContactResult ();
  11807. result.ConsumerID = sp.LocalId;
  11808. result.Depth = Vector3.Distance(rayStart, p);
  11809. result.Normal = Vector3.Zero;
  11810. result.Pos = p;
  11811. contacts.Add(result);
  11812. });
  11813. return contacts.ToArray();
  11814. }
  11815. private ContactResult[] ObjectIntersection(Vector3 rayStart, Vector3 rayEnd, bool includePhysical, bool includeNonPhysical, bool includePhantom)
  11816. {
  11817. Ray ray = new Ray(rayStart, Vector3.Normalize(rayEnd - rayStart));
  11818. List<ContactResult> contacts = new List<ContactResult>();
  11819. Vector3 ab = rayEnd - rayStart;
  11820. World.ForEachSOG(delegate(SceneObjectGroup group)
  11821. {
  11822. if (m_host.ParentGroup == group)
  11823. return;
  11824. if (group.IsAttachment)
  11825. return;
  11826. if (group.RootPart.PhysActor == null)
  11827. {
  11828. if (!includePhantom)
  11829. return;
  11830. }
  11831. else
  11832. {
  11833. if (group.RootPart.PhysActor.IsPhysical)
  11834. {
  11835. if (!includePhysical)
  11836. return;
  11837. }
  11838. else
  11839. {
  11840. if (!includeNonPhysical)
  11841. return;
  11842. }
  11843. }
  11844. // Find the radius ouside of which we don't even need to hit test
  11845. float minX;
  11846. float maxX;
  11847. float minY;
  11848. float maxY;
  11849. float minZ;
  11850. float maxZ;
  11851. float radius = 0.0f;
  11852. group.GetAxisAlignedBoundingBoxRaw(out minX, out maxX, out minY, out maxY, out minZ, out maxZ);
  11853. if (Math.Abs(minX) > radius)
  11854. radius = Math.Abs(minX);
  11855. if (Math.Abs(minY) > radius)
  11856. radius = Math.Abs(minY);
  11857. if (Math.Abs(minZ) > radius)
  11858. radius = Math.Abs(minZ);
  11859. if (Math.Abs(maxX) > radius)
  11860. radius = Math.Abs(maxX);
  11861. if (Math.Abs(maxY) > radius)
  11862. radius = Math.Abs(maxY);
  11863. if (Math.Abs(maxZ) > radius)
  11864. radius = Math.Abs(maxZ);
  11865. radius = radius*1.413f;
  11866. Vector3 ac = group.AbsolutePosition - rayStart;
  11867. // Vector3 bc = group.AbsolutePosition - rayEnd;
  11868. double d = Math.Abs(Vector3.Mag(Vector3.Cross(ab, ac)) / Vector3.Distance(rayStart, rayEnd));
  11869. // Too far off ray, don't bother
  11870. if (d > radius)
  11871. return;
  11872. // Behind ray, drop
  11873. double d2 = Vector3.Dot(Vector3.Negate(ab), ac);
  11874. if (d2 > 0)
  11875. return;
  11876. ray = new Ray(rayStart, Vector3.Normalize(rayEnd - rayStart));
  11877. EntityIntersection intersection = group.TestIntersection(ray, true, false);
  11878. // Miss.
  11879. if (!intersection.HitTF)
  11880. return;
  11881. Vector3 b1 = group.AbsolutePosition + new Vector3(minX, minY, minZ);
  11882. Vector3 b2 = group.AbsolutePosition + new Vector3(maxX, maxY, maxZ);
  11883. //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);
  11884. if (!(intersection.ipoint.X >= b1.X && intersection.ipoint.X <= b2.X &&
  11885. intersection.ipoint.Y >= b1.Y && intersection.ipoint.Y <= b2.Y &&
  11886. intersection.ipoint.Z >= b1.Z && intersection.ipoint.Z <= b2.Z))
  11887. return;
  11888. ContactResult result = new ContactResult ();
  11889. result.ConsumerID = group.LocalId;
  11890. result.Depth = intersection.distance;
  11891. result.Normal = intersection.normal;
  11892. result.Pos = intersection.ipoint;
  11893. contacts.Add(result);
  11894. });
  11895. return contacts.ToArray();
  11896. }
  11897. private ContactResult? GroundIntersection(Vector3 rayStart, Vector3 rayEnd)
  11898. {
  11899. double[,] heightfield = World.Heightmap.GetDoubles();
  11900. List<ContactResult> contacts = new List<ContactResult>();
  11901. double min = 2048.0;
  11902. double max = 0.0;
  11903. // Find the min and max of the heightfield
  11904. for (int x = 0 ; x < World.Heightmap.Width ; x++)
  11905. {
  11906. for (int y = 0 ; y < World.Heightmap.Height ; y++)
  11907. {
  11908. if (heightfield[x, y] > max)
  11909. max = heightfield[x, y];
  11910. if (heightfield[x, y] < min)
  11911. min = heightfield[x, y];
  11912. }
  11913. }
  11914. // A ray extends past rayEnd, but doesn't go back before
  11915. // rayStart. If the start is above the highest point of the ground
  11916. // and the ray goes up, we can't hit the ground. Ever.
  11917. if (rayStart.Z > max && rayEnd.Z >= rayStart.Z)
  11918. return null;
  11919. // Same for going down
  11920. if (rayStart.Z < min && rayEnd.Z <= rayStart.Z)
  11921. return null;
  11922. List<Tri> trilist = new List<Tri>();
  11923. // Create our triangle list
  11924. for (int x = 1 ; x < World.Heightmap.Width ; x++)
  11925. {
  11926. for (int y = 1 ; y < World.Heightmap.Height ; y++)
  11927. {
  11928. Tri t1 = new Tri();
  11929. Tri t2 = new Tri();
  11930. Vector3 p1 = new Vector3(x-1, y-1, (float)heightfield[x-1, y-1]);
  11931. Vector3 p2 = new Vector3(x, y-1, (float)heightfield[x, y-1]);
  11932. Vector3 p3 = new Vector3(x, y, (float)heightfield[x, y]);
  11933. Vector3 p4 = new Vector3(x-1, y, (float)heightfield[x-1, y]);
  11934. t1.p1 = p1;
  11935. t1.p2 = p2;
  11936. t1.p3 = p3;
  11937. t2.p1 = p3;
  11938. t2.p2 = p4;
  11939. t2.p3 = p1;
  11940. trilist.Add(t1);
  11941. trilist.Add(t2);
  11942. }
  11943. }
  11944. // Ray direction
  11945. Vector3 rayDirection = rayEnd - rayStart;
  11946. foreach (Tri t in trilist)
  11947. {
  11948. // Compute triangle plane normal and edges
  11949. Vector3 u = t.p2 - t.p1;
  11950. Vector3 v = t.p3 - t.p1;
  11951. Vector3 n = Vector3.Cross(u, v);
  11952. if (n == Vector3.Zero)
  11953. continue;
  11954. Vector3 w0 = rayStart - t.p1;
  11955. double a = -Vector3.Dot(n, w0);
  11956. double b = Vector3.Dot(n, rayDirection);
  11957. // Not intersecting the plane, or in plane (same thing)
  11958. // Ignoring this MAY cause the ground to not be detected
  11959. // sometimes
  11960. if (Math.Abs(b) < 0.000001)
  11961. continue;
  11962. double r = a / b;
  11963. // ray points away from plane
  11964. if (r < 0.0)
  11965. continue;
  11966. Vector3 ip = rayStart + Vector3.Multiply(rayDirection, (float)r);
  11967. float uu = Vector3.Dot(u, u);
  11968. float uv = Vector3.Dot(u, v);
  11969. float vv = Vector3.Dot(v, v);
  11970. Vector3 w = ip - t.p1;
  11971. float wu = Vector3.Dot(w, u);
  11972. float wv = Vector3.Dot(w, v);
  11973. float d = uv * uv - uu * vv;
  11974. float cs = (uv * wv - vv * wu) / d;
  11975. if (cs < 0 || cs > 1.0)
  11976. continue;
  11977. float ct = (uv * wu - uu * wv) / d;
  11978. if (ct < 0 || (cs + ct) > 1.0)
  11979. continue;
  11980. // Add contact point
  11981. ContactResult result = new ContactResult ();
  11982. result.ConsumerID = 0;
  11983. result.Depth = Vector3.Distance(rayStart, ip);
  11984. result.Normal = n;
  11985. result.Pos = ip;
  11986. contacts.Add(result);
  11987. }
  11988. if (contacts.Count == 0)
  11989. return null;
  11990. contacts.Sort(delegate(ContactResult a, ContactResult b)
  11991. {
  11992. return (int)(a.Depth - b.Depth);
  11993. });
  11994. return contacts[0];
  11995. }
  11996. public LSL_List llCastRayV1(LSL_Vector start, LSL_Vector end, LSL_List options)
  11997. {
  11998. LSL_List list = new LSL_List();
  11999. m_host.AddScriptLPS(1);
  12000. Vector3 rayStart = start;
  12001. Vector3 rayEnd = end;
  12002. Vector3 dir = rayEnd - rayStart;
  12003. float dist = Vector3.Mag(dir);
  12004. int count = 1;
  12005. bool detectPhantom = false;
  12006. int dataFlags = 0;
  12007. int rejectTypes = 0;
  12008. for (int i = 0; i < options.Length; i += 2)
  12009. {
  12010. if (options.GetLSLIntegerItem(i) == ScriptBaseClass.RC_MAX_HITS)
  12011. count = options.GetLSLIntegerItem(i + 1);
  12012. else if (options.GetLSLIntegerItem(i) == ScriptBaseClass.RC_DETECT_PHANTOM)
  12013. detectPhantom = (options.GetLSLIntegerItem(i + 1) > 0);
  12014. else if (options.GetLSLIntegerItem(i) == ScriptBaseClass.RC_DATA_FLAGS)
  12015. dataFlags = options.GetLSLIntegerItem(i + 1);
  12016. else if (options.GetLSLIntegerItem(i) == ScriptBaseClass.RC_REJECT_TYPES)
  12017. rejectTypes = options.GetLSLIntegerItem(i + 1);
  12018. }
  12019. if (count > 16)
  12020. count = 16;
  12021. List<ContactResult> results = new List<ContactResult>();
  12022. bool checkTerrain = !((rejectTypes & ScriptBaseClass.RC_REJECT_LAND) == ScriptBaseClass.RC_REJECT_LAND);
  12023. bool checkAgents = !((rejectTypes & ScriptBaseClass.RC_REJECT_AGENTS) == ScriptBaseClass.RC_REJECT_AGENTS);
  12024. bool checkNonPhysical = !((rejectTypes & ScriptBaseClass.RC_REJECT_NONPHYSICAL) == ScriptBaseClass.RC_REJECT_NONPHYSICAL);
  12025. bool checkPhysical = !((rejectTypes & ScriptBaseClass.RC_REJECT_PHYSICAL) == ScriptBaseClass.RC_REJECT_PHYSICAL);
  12026. if (World.SupportsRayCastFiltered())
  12027. {
  12028. if (dist == 0)
  12029. return list;
  12030. RayFilterFlags rayfilter = RayFilterFlags.ClosestAndBackCull;
  12031. if (checkTerrain)
  12032. rayfilter |= RayFilterFlags.land;
  12033. // if (checkAgents)
  12034. // rayfilter |= RayFilterFlags.agent;
  12035. if (checkPhysical)
  12036. rayfilter |= RayFilterFlags.physical;
  12037. if (checkNonPhysical)
  12038. rayfilter |= RayFilterFlags.nonphysical;
  12039. if (detectPhantom)
  12040. rayfilter |= RayFilterFlags.LSLPhantom;
  12041. Vector3 direction = dir * ( 1/dist);
  12042. if(rayfilter == 0)
  12043. {
  12044. list.Add(new LSL_Integer(0));
  12045. return list;
  12046. }
  12047. // get some more contacts to sort ???
  12048. int physcount = 4 * count;
  12049. if (physcount > 20)
  12050. physcount = 20;
  12051. object physresults;
  12052. physresults = World.RayCastFiltered(rayStart, direction, dist, physcount, rayfilter);
  12053. if (physresults == null)
  12054. {
  12055. list.Add(new LSL_Integer(-3)); // timeout error
  12056. return list;
  12057. }
  12058. results = (List<ContactResult>)physresults;
  12059. // for now physics doesn't detect sitted avatars so do it outside physics
  12060. if (checkAgents)
  12061. {
  12062. ContactResult[] agentHits = AvatarIntersection(rayStart, rayEnd);
  12063. foreach (ContactResult r in agentHits)
  12064. results.Add(r);
  12065. }
  12066. // TODO: Replace this with a better solution. ObjectIntersection can only
  12067. // detect nonphysical phantoms. They are detected by virtue of being
  12068. // nonphysical (e.g. no PhysActor) so will not conflict with detecting
  12069. // physicsl phantoms as done by the physics scene
  12070. // We don't want anything else but phantoms here.
  12071. if (detectPhantom)
  12072. {
  12073. ContactResult[] objectHits = ObjectIntersection(rayStart, rayEnd, false, false, true);
  12074. foreach (ContactResult r in objectHits)
  12075. results.Add(r);
  12076. }
  12077. }
  12078. else
  12079. {
  12080. if (checkAgents)
  12081. {
  12082. ContactResult[] agentHits = AvatarIntersection(rayStart, rayEnd);
  12083. foreach (ContactResult r in agentHits)
  12084. results.Add(r);
  12085. }
  12086. if (checkPhysical || checkNonPhysical || detectPhantom)
  12087. {
  12088. ContactResult[] objectHits = ObjectIntersection(rayStart, rayEnd, checkPhysical, checkNonPhysical, detectPhantom);
  12089. for (int iter = 0; iter < objectHits.Length; iter++)
  12090. {
  12091. // Redistance the Depth because the Scene RayCaster returns distance from center to make the rezzing code simpler.
  12092. objectHits[iter].Depth = Vector3.Distance(objectHits[iter].Pos, rayStart);
  12093. results.Add(objectHits[iter]);
  12094. }
  12095. }
  12096. }
  12097. if (checkTerrain)
  12098. {
  12099. ContactResult? groundContact = GroundIntersection(rayStart, rayEnd);
  12100. if (groundContact != null)
  12101. results.Add((ContactResult)groundContact);
  12102. }
  12103. results.Sort(delegate(ContactResult a, ContactResult b)
  12104. {
  12105. return a.Depth.CompareTo(b.Depth);
  12106. });
  12107. int values = 0;
  12108. SceneObjectGroup thisgrp = m_host.ParentGroup;
  12109. foreach (ContactResult result in results)
  12110. {
  12111. if (result.Depth > dist)
  12112. continue;
  12113. // physics ray can return colisions with host prim
  12114. if (m_host.LocalId == result.ConsumerID)
  12115. continue;
  12116. UUID itemID = UUID.Zero;
  12117. int linkNum = 0;
  12118. SceneObjectPart part = World.GetSceneObjectPart(result.ConsumerID);
  12119. // It's a prim!
  12120. if (part != null)
  12121. {
  12122. // dont detect members of same object ???
  12123. if (part.ParentGroup == thisgrp)
  12124. continue;
  12125. if ((dataFlags & ScriptBaseClass.RC_GET_ROOT_KEY) == ScriptBaseClass.RC_GET_ROOT_KEY)
  12126. itemID = part.ParentGroup.UUID;
  12127. else
  12128. itemID = part.UUID;
  12129. linkNum = part.LinkNum;
  12130. }
  12131. else
  12132. {
  12133. ScenePresence sp = World.GetScenePresence(result.ConsumerID);
  12134. /// It it a boy? a girl?
  12135. if (sp != null)
  12136. itemID = sp.UUID;
  12137. }
  12138. list.Add(new LSL_String(itemID.ToString()));
  12139. list.Add(new LSL_String(result.Pos.ToString()));
  12140. if ((dataFlags & ScriptBaseClass.RC_GET_LINK_NUM) == ScriptBaseClass.RC_GET_LINK_NUM)
  12141. list.Add(new LSL_Integer(linkNum));
  12142. if ((dataFlags & ScriptBaseClass.RC_GET_NORMAL) == ScriptBaseClass.RC_GET_NORMAL)
  12143. list.Add(new LSL_Vector(result.Normal));
  12144. values++;
  12145. if (values >= count)
  12146. break;
  12147. }
  12148. list.Add(new LSL_Integer(values));
  12149. return list;
  12150. }
  12151. /// <summary>
  12152. /// Full implementation of llCastRay similar to SL 2015-04-21.
  12153. /// http://wiki.secondlife.com/wiki/LlCastRay
  12154. /// Uses pure geometry, bounding shapes, meshing and no physics
  12155. /// for prims, sculpts, meshes, avatars and terrain.
  12156. /// Implements all flags, reject types and data flags.
  12157. /// Can handle both objects/groups and prims/parts, by config.
  12158. /// May give poor results with multi-part meshes where "root"
  12159. /// part doesn't dominate, owing to "guessed" bounding boxes.
  12160. /// May sometimes be inaccurate owing to calculation precision
  12161. /// and a bug in libopenmetaverse PrimMesher.
  12162. /// </summary>
  12163. public LSL_List llCastRay(LSL_Vector start, LSL_Vector end, LSL_List options)
  12164. {
  12165. // Use llCastRay v1 if configured
  12166. if (m_useCastRayV1)
  12167. return llCastRayV1(start, end, options);
  12168. // Initialize
  12169. m_host.AddScriptLPS(1);
  12170. List<RayHit> rayHits = new List<RayHit>();
  12171. LSL_List result = new LSL_List();
  12172. float tol = m_floatToleranceInCastRay;
  12173. float tol2 = m_floatTolerance2InCastRay;
  12174. // Get input options
  12175. int rejectTypes = 0;
  12176. int dataFlags = 0;
  12177. int maxHits = 1;
  12178. bool detectPhantom = false;
  12179. for (int i = 0; i < options.Length; i += 2)
  12180. {
  12181. if (options.GetLSLIntegerItem(i) == ScriptBaseClass.RC_REJECT_TYPES)
  12182. rejectTypes = options.GetLSLIntegerItem(i + 1);
  12183. else if (options.GetLSLIntegerItem(i) == ScriptBaseClass.RC_DATA_FLAGS)
  12184. dataFlags = options.GetLSLIntegerItem(i + 1);
  12185. else if (options.GetLSLIntegerItem(i) == ScriptBaseClass.RC_MAX_HITS)
  12186. maxHits = options.GetLSLIntegerItem(i + 1);
  12187. else if (options.GetLSLIntegerItem(i) == ScriptBaseClass.RC_DETECT_PHANTOM)
  12188. detectPhantom = (options.GetLSLIntegerItem(i + 1) != 0);
  12189. }
  12190. if (maxHits > m_maxHitsInCastRay)
  12191. maxHits = m_maxHitsInCastRay;
  12192. bool rejectAgents = ((rejectTypes & ScriptBaseClass.RC_REJECT_AGENTS) != 0);
  12193. bool rejectPhysical = ((rejectTypes & ScriptBaseClass.RC_REJECT_PHYSICAL) != 0);
  12194. bool rejectNonphysical = ((rejectTypes & ScriptBaseClass.RC_REJECT_NONPHYSICAL) != 0);
  12195. bool rejectLand = ((rejectTypes & ScriptBaseClass.RC_REJECT_LAND) != 0);
  12196. bool getNormal = ((dataFlags & ScriptBaseClass.RC_GET_NORMAL) != 0);
  12197. bool getRootKey = ((dataFlags & ScriptBaseClass.RC_GET_ROOT_KEY) != 0);
  12198. bool getLinkNum = ((dataFlags & ScriptBaseClass.RC_GET_LINK_NUM) != 0);
  12199. // Calculate some basic parameters
  12200. Vector3 ray = end - start;
  12201. float rayLength = ray.Length();
  12202. // Try to get a mesher and return failure if none or degenerate ray
  12203. IRendering primMesher = null;
  12204. List<string> renderers = RenderingLoader.ListRenderers(Util.ExecutingDirectory());
  12205. if (renderers.Count < 1 || rayLength < tol)
  12206. {
  12207. result.Add(new LSL_Integer(ScriptBaseClass.RCERR_UNKNOWN));
  12208. return result;
  12209. }
  12210. primMesher = RenderingLoader.LoadRenderer(renderers[0]);
  12211. // Used to translate and rotate world so ray is along negative Z axis from origo and
  12212. // calculations mostly simplified to a 2D projecttion on the X-Y plane
  12213. Vector3 posProj = new Vector3(-start);
  12214. Quaternion rotProj = Vector3.RotationBetween(ray, new Vector3(0.0f, 0.0f, -1.0f));
  12215. Quaternion rotBack = Quaternion.Inverse(rotProj);
  12216. // Iterate over all objects/groups and prims/parts in region
  12217. World.ForEachSOG(
  12218. delegate(SceneObjectGroup group)
  12219. {
  12220. // Check group filters unless part filters are configured
  12221. bool isPhysical = (group.RootPart != null && group.RootPart.PhysActor != null && group.RootPart.PhysActor.IsPhysical);
  12222. bool isNonphysical = !isPhysical;
  12223. bool isPhantom = group.IsPhantom || group.IsVolumeDetect;
  12224. bool isAttachment = group.IsAttachment;
  12225. bool doGroup = true;
  12226. if (isPhysical && rejectPhysical)
  12227. doGroup = false;
  12228. if (isNonphysical && rejectNonphysical)
  12229. doGroup = false;
  12230. if (isPhantom && detectPhantom)
  12231. doGroup = true;
  12232. if (m_filterPartsInCastRay)
  12233. doGroup = true;
  12234. if (isAttachment && !m_doAttachmentsInCastRay)
  12235. doGroup = false;
  12236. // Parse object/group if passed filters
  12237. if (doGroup)
  12238. {
  12239. // Iterate over all prims/parts in object/group
  12240. foreach(SceneObjectPart part in group.Parts)
  12241. {
  12242. // Check part filters if configured
  12243. if (m_filterPartsInCastRay)
  12244. {
  12245. isPhysical = (part.PhysActor != null && part.PhysActor.IsPhysical);
  12246. isNonphysical = !isPhysical;
  12247. isPhantom = ((part.Flags & PrimFlags.Phantom) != 0) || (part.VolumeDetectActive);
  12248. bool doPart = true;
  12249. if (isPhysical && rejectPhysical)
  12250. doPart = false;
  12251. if (isNonphysical && rejectNonphysical)
  12252. doPart = false;
  12253. if (isPhantom && detectPhantom)
  12254. doPart = true;
  12255. if (!doPart)
  12256. continue;
  12257. }
  12258. // Parse prim/part if passed filters
  12259. // Estimate bounding box from size box
  12260. Vector3 scaleSafe = part.Scale;
  12261. if (!part.Shape.SculptEntry)
  12262. scaleSafe = scaleSafe * (new Vector3(m_primSafetyCoeffX, m_primSafetyCoeffY, m_primSafetyCoeffZ));
  12263. // Filter parts by bounding shapes
  12264. Vector3 posPartRel = part.GetWorldPosition() + posProj;
  12265. Vector3 posPartProj = posPartRel * rotProj;
  12266. if (InBoundingShapes(ray, rayLength, scaleSafe, posPartRel, posPartProj, rotProj))
  12267. {
  12268. // Prepare data needed to check for ray hits
  12269. RayTrans rayTrans = new RayTrans();
  12270. rayTrans.PartId = part.UUID;
  12271. rayTrans.GroupId = part.ParentGroup.UUID;
  12272. rayTrans.Link = group.PrimCount > 1 ? part.LinkNum : 0;
  12273. rayTrans.Scale = part.Scale;
  12274. rayTrans.PositionPartProj = posPartProj;
  12275. rayTrans.PositionProj = posProj;
  12276. rayTrans.RotationPartProj = rotProj * part.GetWorldRotation();
  12277. rayTrans.RotationBack = rotBack;
  12278. rayTrans.NeedsEnds = true;
  12279. rayTrans.RayLength = rayLength;
  12280. rayTrans.Tolerance = tol;
  12281. rayTrans.Tolerance2 = tol2;
  12282. // Make an OMV prim to be able to mesh part
  12283. Primitive omvPrim = part.Shape.ToOmvPrimitive(posPartProj, rayTrans.RotationPartProj);
  12284. byte[] sculptAsset = null;
  12285. if (omvPrim.Sculpt != null)
  12286. sculptAsset = World.AssetService.GetData(omvPrim.Sculpt.SculptTexture.ToString());
  12287. // When part is mesh, get and check mesh
  12288. if (omvPrim.Sculpt != null && omvPrim.Sculpt.Type == SculptType.Mesh && sculptAsset != null)
  12289. {
  12290. AssetMesh meshAsset = new AssetMesh(omvPrim.Sculpt.SculptTexture, sculptAsset);
  12291. FacetedMesh mesh = null;
  12292. FacetedMesh.TryDecodeFromAsset(omvPrim, meshAsset, DetailLevel.Highest, out mesh);
  12293. meshAsset = null;
  12294. AddRayInFacetedMesh(mesh, rayTrans, ref rayHits);
  12295. mesh = null;
  12296. }
  12297. // When part is sculpt, create and check mesh
  12298. // Quirk: Generated sculpt mesh is about 2.8% smaller in X and Y than visual sculpt.
  12299. else if (omvPrim.Sculpt != null && omvPrim.Sculpt.Type != SculptType.Mesh && sculptAsset != null)
  12300. {
  12301. IJ2KDecoder imgDecoder = World.RequestModuleInterface<IJ2KDecoder>();
  12302. if (imgDecoder != null)
  12303. {
  12304. Image sculpt = imgDecoder.DecodeToImage(sculptAsset);
  12305. if (sculpt != null)
  12306. {
  12307. SimpleMesh mesh = primMesher.GenerateSimpleSculptMesh(omvPrim, (Bitmap)sculpt, DetailLevel.Medium);
  12308. sculpt.Dispose();
  12309. AddRayInSimpleMesh(mesh, rayTrans, ref rayHits);
  12310. mesh = null;
  12311. }
  12312. }
  12313. }
  12314. // When part is prim, create and check mesh
  12315. else if (omvPrim.Sculpt == null)
  12316. {
  12317. if (
  12318. omvPrim.PrimData.PathBegin == 0.0 && omvPrim.PrimData.PathEnd == 1.0 &&
  12319. omvPrim.PrimData.PathTaperX == 0.0 && omvPrim.PrimData.PathTaperY == 0.0 &&
  12320. omvPrim.PrimData.PathSkew == 0.0 &&
  12321. omvPrim.PrimData.PathTwist - omvPrim.PrimData.PathTwistBegin == 0.0
  12322. )
  12323. rayTrans.NeedsEnds = false;
  12324. SimpleMesh mesh = primMesher.GenerateSimpleMesh(omvPrim, DetailLevel.Medium);
  12325. AddRayInSimpleMesh(mesh, rayTrans, ref rayHits);
  12326. mesh = null;
  12327. }
  12328. }
  12329. }
  12330. }
  12331. }
  12332. );
  12333. // Check avatar filter
  12334. if (!rejectAgents)
  12335. {
  12336. // Iterate over all avatars in region
  12337. World.ForEachRootScenePresence(
  12338. delegate (ScenePresence sp)
  12339. {
  12340. // Parse avatar
  12341. // Get bounding box
  12342. Vector3 lower;
  12343. Vector3 upper;
  12344. BoundingBoxOfScenePresence(sp, out lower, out upper);
  12345. Vector3 scale = upper - lower;
  12346. // Filter avatars by bounding shapes
  12347. Vector3 posPartRel = sp.AbsolutePosition + posProj + (lower + upper) * 0.5f * sp.Rotation;
  12348. Vector3 posPartProj = posPartRel * rotProj;
  12349. if (InBoundingShapes(ray, rayLength, scale, posPartRel, posPartProj, rotProj))
  12350. {
  12351. // Prepare data needed to check for ray hits
  12352. RayTrans rayTrans = new RayTrans();
  12353. rayTrans.PartId = sp.UUID;
  12354. rayTrans.GroupId = sp.ParentPart != null ? sp.ParentPart.ParentGroup.UUID : sp.UUID;
  12355. rayTrans.Link = sp.ParentPart != null ? UUID2LinkNumber(sp.ParentPart, sp.UUID) : 0;
  12356. rayTrans.Scale = scale;
  12357. rayTrans.PositionPartProj = posPartProj;
  12358. rayTrans.PositionProj = posProj;
  12359. rayTrans.RotationPartProj = rotProj * sp.Rotation;
  12360. rayTrans.RotationBack = rotBack;
  12361. rayTrans.NeedsEnds = false;
  12362. rayTrans.RayLength = rayLength;
  12363. rayTrans.Tolerance = tol;
  12364. rayTrans.Tolerance2 = tol2;
  12365. // Make OMV prim, create and check mesh
  12366. Primitive omvPrim = MakeOpenMetaversePrim(scale, posPartProj, rayTrans.RotationPartProj, ScriptBaseClass.PRIM_TYPE_SPHERE);
  12367. SimpleMesh mesh = primMesher.GenerateSimpleMesh(omvPrim, DetailLevel.Medium);
  12368. AddRayInSimpleMesh(mesh, rayTrans, ref rayHits);
  12369. mesh = null;
  12370. }
  12371. }
  12372. );
  12373. }
  12374. // Check terrain filter
  12375. if (!rejectLand)
  12376. {
  12377. // Parse terrain
  12378. // Mesh terrain and check projected bounding box
  12379. Vector3 posPartProj = posProj * rotProj;
  12380. Quaternion rotPartProj = rotProj;
  12381. Vector3 lower;
  12382. Vector3 upper;
  12383. List<Tri> triangles = TrisFromHeightmapUnderRay(start, end, out lower, out upper);
  12384. Vector3 lowerBox = new Vector3(float.MaxValue, float.MaxValue, float.MaxValue);
  12385. Vector3 upperBox = new Vector3(float.MinValue, float.MinValue, float.MinValue);
  12386. int dummy = 0;
  12387. AddBoundingBoxOfSimpleBox(lower, upper, posPartProj, rotPartProj, true, ref lowerBox, ref upperBox, ref dummy);
  12388. if (lowerBox.X <= tol && lowerBox.Y <= tol && lowerBox.Z <= tol && upperBox.X >= -tol && upperBox.Y >= -tol && upperBox.Z >= -rayLength - tol)
  12389. {
  12390. // Prepare data needed to check for ray hits
  12391. RayTrans rayTrans = new RayTrans();
  12392. rayTrans.PartId = UUID.Zero;
  12393. rayTrans.GroupId = UUID.Zero;
  12394. rayTrans.Link = 0;
  12395. rayTrans.Scale = new Vector3 (1.0f, 1.0f, 1.0f);
  12396. rayTrans.PositionPartProj = posPartProj;
  12397. rayTrans.PositionProj = posProj;
  12398. rayTrans.RotationPartProj = rotPartProj;
  12399. rayTrans.RotationBack = rotBack;
  12400. rayTrans.NeedsEnds = true;
  12401. rayTrans.RayLength = rayLength;
  12402. rayTrans.Tolerance = tol;
  12403. rayTrans.Tolerance2 = tol2;
  12404. // Check mesh
  12405. AddRayInTris(triangles, rayTrans, ref rayHits);
  12406. triangles = null;
  12407. }
  12408. }
  12409. // Sort hits by ascending distance
  12410. rayHits.Sort((s1, s2) => s1.Distance.CompareTo(s2.Distance));
  12411. // Check excess hits per part and group
  12412. for (int t = 0; t < 2; t++)
  12413. {
  12414. int maxHitsPerType = 0;
  12415. UUID id = UUID.Zero;
  12416. if (t == 0)
  12417. maxHitsPerType = m_maxHitsPerPrimInCastRay;
  12418. else
  12419. maxHitsPerType = m_maxHitsPerObjectInCastRay;
  12420. // Handle excess hits only when needed
  12421. if (maxHitsPerType < m_maxHitsInCastRay)
  12422. {
  12423. // Find excess hits
  12424. Hashtable hits = new Hashtable();
  12425. for (int i = rayHits.Count - 1; i >= 0; i--)
  12426. {
  12427. if (t == 0)
  12428. id = rayHits[i].PartId;
  12429. else
  12430. id = rayHits[i].GroupId;
  12431. if (hits.ContainsKey(id))
  12432. hits[id] = (int)hits[id] + 1;
  12433. else
  12434. hits[id] = 1;
  12435. }
  12436. // Remove excess hits
  12437. for (int i = rayHits.Count - 1; i >= 0; i--)
  12438. {
  12439. if (t == 0)
  12440. id = rayHits[i].PartId;
  12441. else
  12442. id = rayHits[i].GroupId;
  12443. int hit = (int)hits[id];
  12444. if (hit > m_maxHitsPerPrimInCastRay)
  12445. {
  12446. rayHits.RemoveAt(i);
  12447. hit--;
  12448. hits[id] = hit;
  12449. }
  12450. }
  12451. }
  12452. }
  12453. // Parse hits into result list according to data flags
  12454. int hitCount = rayHits.Count;
  12455. if (hitCount > maxHits)
  12456. hitCount = maxHits;
  12457. for (int i = 0; i < hitCount; i++)
  12458. {
  12459. RayHit rayHit = rayHits[i];
  12460. if (getRootKey)
  12461. result.Add(new LSL_Key(rayHit.GroupId.ToString()));
  12462. else
  12463. result.Add(new LSL_Key(rayHit.PartId.ToString()));
  12464. result.Add(new LSL_Vector(rayHit.Position));
  12465. if (getLinkNum)
  12466. result.Add(new LSL_Integer(rayHit.Link));
  12467. if (getNormal)
  12468. result.Add(new LSL_Vector(rayHit.Normal));
  12469. }
  12470. result.Add(new LSL_Integer(hitCount));
  12471. return result;
  12472. }
  12473. /// <summary>
  12474. /// Struct for transmitting parameters required for finding llCastRay ray hits.
  12475. /// </summary>
  12476. public struct RayTrans
  12477. {
  12478. public UUID PartId;
  12479. public UUID GroupId;
  12480. public int Link;
  12481. public Vector3 Scale;
  12482. public Vector3 PositionPartProj;
  12483. public Vector3 PositionProj;
  12484. public Quaternion RotationPartProj;
  12485. public Quaternion RotationBack;
  12486. public bool NeedsEnds;
  12487. public float RayLength;
  12488. public float Tolerance;
  12489. public float Tolerance2;
  12490. }
  12491. /// <summary>
  12492. /// Struct for llCastRay ray hits.
  12493. /// </summary>
  12494. public struct RayHit
  12495. {
  12496. public UUID PartId;
  12497. public UUID GroupId;
  12498. public int Link;
  12499. public Vector3 Position;
  12500. public Vector3 Normal;
  12501. public float Distance;
  12502. }
  12503. /// <summary>
  12504. /// Helper to parse SimpleMesh for ray hits.
  12505. /// </summary>
  12506. private void AddRayInSimpleMesh(SimpleMesh mesh, RayTrans rayTrans, ref List<RayHit> rayHits)
  12507. {
  12508. if (mesh != null)
  12509. {
  12510. for (int i = 0; i < mesh.Indices.Count; i += 3)
  12511. {
  12512. Tri triangle = new Tri();
  12513. triangle.p1 = mesh.Vertices[mesh.Indices[i]].Position;
  12514. triangle.p2 = mesh.Vertices[mesh.Indices[i + 1]].Position;
  12515. triangle.p3 = mesh.Vertices[mesh.Indices[i + 2]].Position;
  12516. AddRayInTri(triangle, rayTrans, ref rayHits);
  12517. }
  12518. }
  12519. }
  12520. /// <summary>
  12521. /// Helper to parse FacetedMesh for ray hits.
  12522. /// </summary>
  12523. private void AddRayInFacetedMesh(FacetedMesh mesh, RayTrans rayTrans, ref List<RayHit> rayHits)
  12524. {
  12525. if (mesh != null)
  12526. {
  12527. foreach (Face face in mesh.Faces)
  12528. {
  12529. for (int i = 0; i <face.Indices.Count; i += 3)
  12530. {
  12531. Tri triangle = new Tri();
  12532. triangle.p1 = face.Vertices[face.Indices[i]].Position;
  12533. triangle.p2 = face.Vertices[face.Indices[i + 1]].Position;
  12534. triangle.p3 = face.Vertices[face.Indices[i + 2]].Position;
  12535. AddRayInTri(triangle, rayTrans, ref rayHits);
  12536. }
  12537. }
  12538. }
  12539. }
  12540. /// <summary>
  12541. /// Helper to parse Tri (triangle) List for ray hits.
  12542. /// </summary>
  12543. private void AddRayInTris(List<Tri> triangles, RayTrans rayTrans, ref List<RayHit> rayHits)
  12544. {
  12545. foreach (Tri triangle in triangles)
  12546. {
  12547. AddRayInTri(triangle, rayTrans, ref rayHits);
  12548. }
  12549. }
  12550. /// <summary>
  12551. /// Helper to add ray hit in a Tri (triangle).
  12552. /// </summary>
  12553. private void AddRayInTri(Tri triangle, RayTrans rayTrans, ref List<RayHit> rayHits)
  12554. {
  12555. // Check for hit in triangle
  12556. float distance;
  12557. Vector3 posHit;
  12558. Vector3 normal;
  12559. if (HitRayInTri(triangle, rayTrans, out distance, out posHit, out normal))
  12560. {
  12561. // Project hit part back to normal coordinate system
  12562. Vector3 posPart = rayTrans.PositionPartProj * rayTrans.RotationBack - rayTrans.PositionProj;
  12563. // Hack to circumvent ghost face bug in PrimMesher by removing hits in (ghost) faces plane through shape center
  12564. if (Math.Abs(Vector3.Dot(posPart, normal) - Vector3.Dot(posHit, normal)) < rayTrans.Tolerance && !rayTrans.NeedsEnds)
  12565. return;
  12566. // Remove duplicate hits at triangle edges and intersections
  12567. for (int i = rayHits.Count - 1; i >= 0; i--)
  12568. {
  12569. if (rayHits[i].PartId == rayTrans.PartId && Math.Abs(rayHits[i].Distance - distance) < rayTrans.Tolerance2)
  12570. return;
  12571. }
  12572. // Build result data set
  12573. RayHit rayHit = new RayHit();
  12574. rayHit.PartId = rayTrans.PartId;
  12575. rayHit.GroupId = rayTrans.GroupId;
  12576. rayHit.Link = rayTrans.Link;
  12577. rayHit.Position = posHit;
  12578. rayHit.Normal = normal;
  12579. rayHit.Distance = distance;
  12580. rayHits.Add(rayHit);
  12581. }
  12582. }
  12583. /// <summary>
  12584. /// Helper to find ray hit in a Tri (triangle).
  12585. /// </summary>
  12586. private bool HitRayInTri(Tri triangle, RayTrans rayTrans, out float distance, out Vector3 posHit, out Vector3 normal)
  12587. {
  12588. // Initialize
  12589. distance = 0.0f;
  12590. posHit = Vector3.Zero;
  12591. normal = Vector3.Zero;
  12592. float tol = rayTrans.Tolerance;
  12593. // Project triangle on X-Y plane
  12594. Vector3 pos1 = triangle.p1 * rayTrans.Scale * rayTrans.RotationPartProj + rayTrans.PositionPartProj;
  12595. Vector3 pos2 = triangle.p2 * rayTrans.Scale * rayTrans.RotationPartProj + rayTrans.PositionPartProj;
  12596. Vector3 pos3 = triangle.p3 * rayTrans.Scale * rayTrans.RotationPartProj + rayTrans.PositionPartProj;
  12597. // Check if ray/origo inside triangle bounding rectangle
  12598. Vector3 lower = Vector3.Min(pos1, Vector3.Min(pos2, pos3));
  12599. Vector3 upper = Vector3.Max(pos1, Vector3.Max(pos2, pos3));
  12600. if (lower.X > tol || lower.Y > tol || lower.Z > tol || upper.X < -tol || upper.Y < -tol || upper.Z < -rayTrans.RayLength - tol)
  12601. return false;
  12602. // Check if ray/origo inside every edge or reverse "outside" every edge on exit
  12603. float dist;
  12604. bool inside = true;
  12605. bool outside = true;
  12606. Vector3 vec1 = pos2 - pos1;
  12607. dist = pos1.X * vec1.Y - pos1.Y * vec1.X;
  12608. if (dist < -tol)
  12609. inside = false;
  12610. if (dist > tol)
  12611. outside = false;
  12612. Vector3 vec2 = pos3 - pos2;
  12613. dist = pos2.X * vec2.Y - pos2.Y * vec2.X;
  12614. if (dist < -tol)
  12615. inside = false;
  12616. if (dist > tol)
  12617. outside = false;
  12618. Vector3 vec3 = pos1 - pos3;
  12619. dist = pos3.X * vec3.Y - pos3.Y * vec3.X;
  12620. if (dist < -tol)
  12621. inside = false;
  12622. if (dist > tol)
  12623. outside = false;
  12624. // Skip if ray/origo outside
  12625. if (!inside && !(outside && m_detectExitsInCastRay))
  12626. return false;
  12627. // Calculate normal
  12628. Vector3 normalProj = Vector3.Cross(vec1, vec2);
  12629. float normalLength = normalProj.Length();
  12630. // Skip if degenerate triangle
  12631. if (normalLength < tol)
  12632. return false;
  12633. normalProj = normalProj / normalLength;
  12634. // Skip if ray parallell to triangle plane
  12635. if (Math.Abs(normalProj.Z) < tol)
  12636. return false;
  12637. // Calculate distance
  12638. distance = Vector3.Dot(normalProj, pos2) / normalProj.Z * -1.0f;
  12639. // Skip if outside ray
  12640. if (distance < -tol || distance > rayTrans.RayLength + tol)
  12641. return false;
  12642. // Calculate projected hit position
  12643. Vector3 posHitProj = new Vector3(0.0f, 0.0f, -distance);
  12644. // Project hit back to normal coordinate system
  12645. posHit = posHitProj * rayTrans.RotationBack - rayTrans.PositionProj;
  12646. normal = normalProj * rayTrans.RotationBack;
  12647. return true;
  12648. }
  12649. /// <summary>
  12650. /// Helper to parse selected parts of HeightMap into a Tri (triangle) List and calculate bounding box.
  12651. /// </summary>
  12652. private List<Tri> TrisFromHeightmapUnderRay(Vector3 posStart, Vector3 posEnd, out Vector3 lower, out Vector3 upper)
  12653. {
  12654. // Get bounding X-Y rectangle of terrain under ray
  12655. lower = Vector3.Min(posStart, posEnd);
  12656. upper = Vector3.Max(posStart, posEnd);
  12657. lower.X = (float)Math.Floor(lower.X);
  12658. lower.Y = (float)Math.Floor(lower.Y);
  12659. float zLower = float.MaxValue;
  12660. upper.X = (float)Math.Ceiling(upper.X);
  12661. upper.Y = (float)Math.Ceiling(upper.Y);
  12662. float zUpper = float.MinValue;
  12663. // Initialize Tri (triangle) List
  12664. List<Tri> triangles = new List<Tri>();
  12665. // Set parsing lane direction to major ray X-Y axis
  12666. Vector3 vec = posEnd - posStart;
  12667. float xAbs = Math.Abs(vec.X);
  12668. float yAbs = Math.Abs(vec.Y);
  12669. bool bigX = true;
  12670. if (yAbs > xAbs)
  12671. {
  12672. bigX = false;
  12673. vec = vec / yAbs;
  12674. }
  12675. else if (xAbs > yAbs || xAbs > 0.0f)
  12676. vec = vec / xAbs;
  12677. else
  12678. vec = new Vector3(1.0f, 1.0f, 0.0f);
  12679. // Simplify by start parsing in lower end of lane
  12680. if ((bigX && vec.X < 0.0f) || (!bigX && vec.Y < 0.0f))
  12681. {
  12682. Vector3 posTemp = posStart;
  12683. posStart = posEnd;
  12684. posEnd = posTemp;
  12685. vec = vec * -1.0f;
  12686. }
  12687. // First 1x1 rectangle under ray
  12688. float xFloorOld = 0.0f;
  12689. float yFloorOld = 0.0f;
  12690. Vector3 pos = posStart;
  12691. float xFloor = (float)Math.Floor(pos.X);
  12692. float yFloor = (float)Math.Floor(pos.Y);
  12693. AddTrisFromHeightmap(xFloor, yFloor, ref triangles, ref zLower, ref zUpper);
  12694. // Parse every remaining 1x1 rectangle under ray
  12695. while (pos != posEnd)
  12696. {
  12697. // Next 1x1 rectangle under ray
  12698. xFloorOld = xFloor;
  12699. yFloorOld = yFloor;
  12700. pos = pos + vec;
  12701. // Clip position to 1x1 rectangle border
  12702. xFloor = (float)Math.Floor(pos.X);
  12703. yFloor = (float)Math.Floor(pos.Y);
  12704. if (bigX && pos.X > xFloor)
  12705. {
  12706. pos.Y -= vec.Y * (pos.X - xFloor);
  12707. pos.X = xFloor;
  12708. }
  12709. else if (!bigX && pos.Y > yFloor)
  12710. {
  12711. pos.X -= vec.X * (pos.Y - yFloor);
  12712. pos.Y = yFloor;
  12713. }
  12714. // Last 1x1 rectangle under ray
  12715. if ((bigX && pos.X >= posEnd.X) || (!bigX && pos.Y >= posEnd.Y))
  12716. {
  12717. pos = posEnd;
  12718. xFloor = (float)Math.Floor(pos.X);
  12719. yFloor = (float)Math.Floor(pos.Y);
  12720. }
  12721. // Add new 1x1 rectangle in lane
  12722. if ((bigX && xFloor != xFloorOld) || (!bigX && yFloor != yFloorOld))
  12723. AddTrisFromHeightmap(xFloor, yFloor, ref triangles, ref zLower, ref zUpper);
  12724. // Add last 1x1 rectangle in old lane at lane shift
  12725. if (bigX && yFloor != yFloorOld)
  12726. AddTrisFromHeightmap(xFloor, yFloorOld, ref triangles, ref zLower, ref zUpper);
  12727. if (!bigX && xFloor != xFloorOld)
  12728. AddTrisFromHeightmap(xFloorOld, yFloor, ref triangles, ref zLower, ref zUpper);
  12729. }
  12730. // Finalize bounding box Z
  12731. lower.Z = zLower;
  12732. upper.Z = zUpper;
  12733. // Done and returning Tri (triangle)List
  12734. return triangles;
  12735. }
  12736. /// <summary>
  12737. /// Helper to add HeightMap squares into Tri (triangle) List and adjust bounding box.
  12738. /// </summary>
  12739. private void AddTrisFromHeightmap(float xPos, float yPos, ref List<Tri> triangles, ref float zLower, ref float zUpper)
  12740. {
  12741. int xInt = (int)xPos;
  12742. int yInt = (int)yPos;
  12743. // Corner 1 of 1x1 rectangle
  12744. int x = Util.Clamp<int>(xInt+1, 0, World.Heightmap.Width - 1);
  12745. int y = Util.Clamp<int>(yInt+1, 0, World.Heightmap.Height - 1);
  12746. Vector3 pos1 = new Vector3(x, y, (float)World.Heightmap[x, y]);
  12747. // Adjust bounding box
  12748. zLower = Math.Min(zLower, pos1.Z);
  12749. zUpper = Math.Max(zUpper, pos1.Z);
  12750. // Corner 2 of 1x1 rectangle
  12751. x = Util.Clamp<int>(xInt, 0, World.Heightmap.Width - 1);
  12752. y = Util.Clamp<int>(yInt+1, 0, World.Heightmap.Height - 1);
  12753. Vector3 pos2 = new Vector3(x, y, (float)World.Heightmap[x, y]);
  12754. // Adjust bounding box
  12755. zLower = Math.Min(zLower, pos1.Z);
  12756. zUpper = Math.Max(zUpper, pos1.Z);
  12757. // Corner 3 of 1x1 rectangle
  12758. x = Util.Clamp<int>(xInt, 0, World.Heightmap.Width - 1);
  12759. y = Util.Clamp<int>(yInt, 0, World.Heightmap.Height - 1);
  12760. Vector3 pos3 = new Vector3(x, y, (float)World.Heightmap[x, y]);
  12761. // Adjust bounding box
  12762. zLower = Math.Min(zLower, pos1.Z);
  12763. zUpper = Math.Max(zUpper, pos1.Z);
  12764. // Corner 4 of 1x1 rectangle
  12765. x = Util.Clamp<int>(xInt+1, 0, World.Heightmap.Width - 1);
  12766. y = Util.Clamp<int>(yInt, 0, World.Heightmap.Height - 1);
  12767. Vector3 pos4 = new Vector3(x, y, (float)World.Heightmap[x, y]);
  12768. // Adjust bounding box
  12769. zLower = Math.Min(zLower, pos1.Z);
  12770. zUpper = Math.Max(zUpper, pos1.Z);
  12771. // Add triangle 1
  12772. Tri triangle1 = new Tri();
  12773. triangle1.p1 = pos1;
  12774. triangle1.p2 = pos2;
  12775. triangle1.p3 = pos3;
  12776. triangles.Add(triangle1);
  12777. // Add triangle 2
  12778. Tri triangle2 = new Tri();
  12779. triangle2.p1 = pos3;
  12780. triangle2.p2 = pos4;
  12781. triangle2.p3 = pos1;
  12782. triangles.Add(triangle2);
  12783. }
  12784. /// <summary>
  12785. /// Helper to check if a ray intersects bounding shapes.
  12786. /// </summary>
  12787. private bool InBoundingShapes(Vector3 ray, float rayLength, Vector3 scale, Vector3 posPartRel, Vector3 posPartProj, Quaternion rotProj)
  12788. {
  12789. float tol = m_floatToleranceInCastRay;
  12790. // Check if ray intersects projected bounding box
  12791. Vector3 lowerBox = new Vector3(float.MaxValue, float.MaxValue, float.MaxValue);
  12792. Vector3 upperBox = new Vector3(float.MinValue, float.MinValue, float.MinValue);
  12793. int dummy = 0;
  12794. AddBoundingBoxOfSimpleBox(scale * -0.5f, scale * 0.5f, posPartProj, rotProj, true, ref lowerBox, ref upperBox, ref dummy);
  12795. if (lowerBox.X > tol || lowerBox.Y > tol || lowerBox.Z > tol || upperBox.X < -tol || upperBox.Y < -tol || upperBox.Z < -rayLength - tol)
  12796. return false;
  12797. // Passed bounding shape filters, so return true
  12798. return true;
  12799. }
  12800. /// <summary>
  12801. /// Helper to get link number for a UUID.
  12802. /// </summary>
  12803. private int UUID2LinkNumber(SceneObjectPart part, UUID id)
  12804. {
  12805. SceneObjectGroup group = part.ParentGroup;
  12806. if (group != null)
  12807. {
  12808. // Parse every link for UUID
  12809. int linkCount = group.PrimCount + group.GetSittingAvatarsCount();
  12810. for (int link = linkCount; link > 0; link--)
  12811. {
  12812. ISceneEntity entity = GetLinkEntity(part, link);
  12813. // Return link number if UUID match
  12814. if (entity != null && entity.UUID == id)
  12815. return link;
  12816. }
  12817. }
  12818. // Return link number 0 if no links or UUID matches
  12819. return 0;
  12820. }
  12821. public LSL_Integer llManageEstateAccess(int action, string avatar)
  12822. {
  12823. m_host.AddScriptLPS(1);
  12824. EstateSettings estate = World.RegionInfo.EstateSettings;
  12825. bool isAccount = false;
  12826. bool isGroup = false;
  12827. if (!estate.IsEstateOwner(m_host.OwnerID) || !estate.IsEstateManagerOrOwner(m_host.OwnerID))
  12828. return 0;
  12829. UUID id = new UUID();
  12830. if (!UUID.TryParse(avatar, out id))
  12831. return 0;
  12832. UserAccount account = World.UserAccountService.GetUserAccount(World.RegionInfo.ScopeID, id);
  12833. isAccount = account != null ? true : false;
  12834. if (!isAccount)
  12835. {
  12836. IGroupsModule groups = World.RequestModuleInterface<IGroupsModule>();
  12837. if (groups != null)
  12838. {
  12839. GroupRecord group = groups.GetGroupRecord(id);
  12840. isGroup = group != null ? true : false;
  12841. if (!isGroup)
  12842. return 0;
  12843. }
  12844. else
  12845. return 0;
  12846. }
  12847. switch (action)
  12848. {
  12849. case ScriptBaseClass.ESTATE_ACCESS_ALLOWED_AGENT_ADD:
  12850. if (!isAccount) return 0;
  12851. if (estate.HasAccess(id)) return 1;
  12852. if (estate.IsBanned(id))
  12853. estate.RemoveBan(id);
  12854. estate.AddEstateUser(id);
  12855. break;
  12856. case ScriptBaseClass.ESTATE_ACCESS_ALLOWED_AGENT_REMOVE:
  12857. if (!isAccount || !estate.HasAccess(id)) return 0;
  12858. estate.RemoveEstateUser(id);
  12859. break;
  12860. case ScriptBaseClass.ESTATE_ACCESS_ALLOWED_GROUP_ADD:
  12861. if (!isGroup) return 0;
  12862. if (estate.GroupAccess(id)) return 1;
  12863. estate.AddEstateGroup(id);
  12864. break;
  12865. case ScriptBaseClass.ESTATE_ACCESS_ALLOWED_GROUP_REMOVE:
  12866. if (!isGroup || !estate.GroupAccess(id)) return 0;
  12867. estate.RemoveEstateGroup(id);
  12868. break;
  12869. case ScriptBaseClass.ESTATE_ACCESS_BANNED_AGENT_ADD:
  12870. if (!isAccount) return 0;
  12871. if (estate.IsBanned(id)) return 1;
  12872. EstateBan ban = new EstateBan();
  12873. ban.EstateID = estate.EstateID;
  12874. ban.BannedUserID = id;
  12875. estate.AddBan(ban);
  12876. break;
  12877. case ScriptBaseClass.ESTATE_ACCESS_BANNED_AGENT_REMOVE:
  12878. if (!isAccount || !estate.IsBanned(id)) return 0;
  12879. estate.RemoveBan(id);
  12880. break;
  12881. default: return 0;
  12882. }
  12883. return 1;
  12884. }
  12885. public LSL_Integer llGetMemoryLimit()
  12886. {
  12887. m_host.AddScriptLPS(1);
  12888. // The value returned for Mono scripts in SL
  12889. return 65536;
  12890. }
  12891. public LSL_Integer llSetMemoryLimit(LSL_Integer limit)
  12892. {
  12893. m_host.AddScriptLPS(1);
  12894. // Treat as an LSO script
  12895. return ScriptBaseClass.FALSE;
  12896. }
  12897. public LSL_Integer llGetSPMaxMemory()
  12898. {
  12899. m_host.AddScriptLPS(1);
  12900. // The value returned for Mono scripts in SL
  12901. return 65536;
  12902. }
  12903. public virtual LSL_Integer llGetUsedMemory()
  12904. {
  12905. m_host.AddScriptLPS(1);
  12906. // The value returned for Mono scripts in SL
  12907. return 65536;
  12908. }
  12909. public void llScriptProfiler(LSL_Integer flags)
  12910. {
  12911. m_host.AddScriptLPS(1);
  12912. // This does nothing for LSO scripts in SL
  12913. }
  12914. #region Not Implemented
  12915. //
  12916. // Listing the unimplemented lsl functions here, please move
  12917. // them from this region as they are completed
  12918. //
  12919. public void llSetSoundQueueing(int queue)
  12920. {
  12921. m_host.AddScriptLPS(1);
  12922. if (m_SoundModule != null)
  12923. m_SoundModule.SetSoundQueueing(m_host.UUID, queue == ScriptBaseClass.TRUE.value);
  12924. }
  12925. public void llCollisionSprite(string impact_sprite)
  12926. {
  12927. m_host.AddScriptLPS(1);
  12928. NotImplemented("llCollisionSprite");
  12929. }
  12930. public void llGodLikeRezObject(string inventory, LSL_Vector pos)
  12931. {
  12932. m_host.AddScriptLPS(1);
  12933. NotImplemented("llGodLikeRezObject");
  12934. }
  12935. public LSL_String llTransferLindenDollars(string destination, int amount)
  12936. {
  12937. UUID txn = UUID.Random();
  12938. Util.FireAndForget(delegate(object x)
  12939. {
  12940. int replycode = 0;
  12941. string replydata = destination + "," + amount.ToString();
  12942. try
  12943. {
  12944. TaskInventoryItem item = m_item;
  12945. if (item == null)
  12946. {
  12947. replydata = "SERVICE_ERROR";
  12948. return;
  12949. }
  12950. m_host.AddScriptLPS(1);
  12951. if (item.PermsGranter == UUID.Zero)
  12952. {
  12953. replydata = "MISSING_PERMISSION_DEBIT";
  12954. return;
  12955. }
  12956. if ((item.PermsMask & ScriptBaseClass.PERMISSION_DEBIT) == 0)
  12957. {
  12958. replydata = "MISSING_PERMISSION_DEBIT";
  12959. return;
  12960. }
  12961. UUID toID = new UUID();
  12962. if (!UUID.TryParse(destination, out toID))
  12963. {
  12964. replydata = "INVALID_AGENT";
  12965. return;
  12966. }
  12967. IMoneyModule money = World.RequestModuleInterface<IMoneyModule>();
  12968. if (money == null)
  12969. {
  12970. replydata = "TRANSFERS_DISABLED";
  12971. return;
  12972. }
  12973. bool result = money.ObjectGiveMoney(
  12974. m_host.ParentGroup.RootPart.UUID, m_host.ParentGroup.RootPart.OwnerID, toID, amount);
  12975. if (result)
  12976. {
  12977. replycode = 1;
  12978. return;
  12979. }
  12980. replydata = "LINDENDOLLAR_INSUFFICIENTFUNDS";
  12981. }
  12982. finally
  12983. {
  12984. m_ScriptEngine.PostScriptEvent(m_item.ItemID, new EventParams(
  12985. "transaction_result", new Object[] {
  12986. new LSL_String(txn.ToString()),
  12987. new LSL_Integer(replycode),
  12988. new LSL_String(replydata) },
  12989. new DetectParams[0]));
  12990. }
  12991. }, null, "LSL_Api.llTransferLindenDollars");
  12992. return txn.ToString();
  12993. }
  12994. #endregion
  12995. }
  12996. public class NotecardCache
  12997. {
  12998. protected class Notecard
  12999. {
  13000. public string[] text;
  13001. public DateTime lastRef;
  13002. }
  13003. private static Dictionary<UUID, Notecard> m_Notecards =
  13004. new Dictionary<UUID, Notecard>();
  13005. public static void Cache(UUID assetID, byte[] text)
  13006. {
  13007. CheckCache();
  13008. lock (m_Notecards)
  13009. {
  13010. if (m_Notecards.ContainsKey(assetID))
  13011. return;
  13012. Notecard nc = new Notecard();
  13013. nc.lastRef = DateTime.Now;
  13014. try
  13015. {
  13016. nc.text = SLUtil.ParseNotecardToArray(text);
  13017. }
  13018. catch(SLUtil.NotANotecardFormatException)
  13019. {
  13020. nc.text = new string[0];
  13021. }
  13022. m_Notecards[assetID] = nc;
  13023. }
  13024. }
  13025. public static bool IsCached(UUID assetID)
  13026. {
  13027. lock (m_Notecards)
  13028. {
  13029. return m_Notecards.ContainsKey(assetID);
  13030. }
  13031. }
  13032. public static int GetLines(UUID assetID)
  13033. {
  13034. if (!IsCached(assetID))
  13035. return -1;
  13036. lock (m_Notecards)
  13037. {
  13038. m_Notecards[assetID].lastRef = DateTime.Now;
  13039. return m_Notecards[assetID].text.Length;
  13040. }
  13041. }
  13042. /// <summary>
  13043. /// Get a notecard line.
  13044. /// </summary>
  13045. /// <param name="assetID"></param>
  13046. /// <param name="lineNumber">Lines start at index 0</param>
  13047. /// <returns></returns>
  13048. public static string GetLine(UUID assetID, int lineNumber)
  13049. {
  13050. if (lineNumber < 0)
  13051. return "";
  13052. string data;
  13053. if (!IsCached(assetID))
  13054. return "";
  13055. lock (m_Notecards)
  13056. {
  13057. m_Notecards[assetID].lastRef = DateTime.Now;
  13058. if (lineNumber >= m_Notecards[assetID].text.Length)
  13059. return "\n\n\n";
  13060. data = m_Notecards[assetID].text[lineNumber];
  13061. return data;
  13062. }
  13063. }
  13064. /// <summary>
  13065. /// Get a notecard line.
  13066. /// </summary>
  13067. /// <param name="assetID"></param>
  13068. /// <param name="lineNumber">Lines start at index 0</param>
  13069. /// <param name="maxLength">
  13070. /// Maximum length of the returned line.
  13071. /// </param>
  13072. /// <returns>
  13073. /// If the line length is longer than <paramref name="maxLength"/>,
  13074. /// the return string will be truncated.
  13075. /// </returns>
  13076. public static string GetLine(UUID assetID, int lineNumber, int maxLength)
  13077. {
  13078. string line = GetLine(assetID, lineNumber);
  13079. if (line.Length > maxLength)
  13080. line = line.Substring(0, maxLength);
  13081. return line;
  13082. }
  13083. public static void CheckCache()
  13084. {
  13085. lock (m_Notecards)
  13086. {
  13087. foreach (UUID key in new List<UUID>(m_Notecards.Keys))
  13088. {
  13089. Notecard nc = m_Notecards[key];
  13090. if (nc.lastRef.AddSeconds(30) < DateTime.Now)
  13091. m_Notecards.Remove(key);
  13092. }
  13093. }
  13094. }
  13095. }
  13096. }