LSL_Api.cs 376 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359
  1. /*
  2. * Copyright (c) Contributors, http://opensimulator.org/
  3. * See CONTRIBUTORS.TXT for a full list of copyright holders.
  4. *
  5. * Redistribution and use in source and binary forms, with or without
  6. * modification, are permitted provided that the following conditions are met:
  7. * * Redistributions of source code must retain the above copyright
  8. * notice, this list of conditions and the following disclaimer.
  9. * * Redistributions in binary form must reproduce the above copyright
  10. * notice, this list of conditions and the following disclaimer in the
  11. * documentation and/or other materials provided with the distribution.
  12. * * Neither the name of the OpenSimulator Project nor the
  13. * names of its contributors may be used to endorse or promote products
  14. * derived from this software without specific prior written permission.
  15. *
  16. * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
  17. * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  18. * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  19. * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
  20. * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  21. * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  22. * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  23. * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  24. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  25. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  26. */
  27. using System;
  28. using System.Collections;
  29. using System.Collections.Generic;
  30. using System.Runtime.Remoting.Lifetime;
  31. using System.Text;
  32. using System.Threading;
  33. using System.Text.RegularExpressions;
  34. using Nini.Config;
  35. using log4net;
  36. using OpenMetaverse;
  37. using OpenMetaverse.Packets;
  38. using OpenSim;
  39. using OpenSim.Framework;
  40. using OpenSim.Region.CoreModules;
  41. using OpenSim.Region.CoreModules.World.Land;
  42. using OpenSim.Region.CoreModules.World.Terrain;
  43. using OpenSim.Region.Framework.Interfaces;
  44. using OpenSim.Region.Framework.Scenes;
  45. using OpenSim.Region.Framework.Scenes.Animation;
  46. using OpenSim.Region.Physics.Manager;
  47. using OpenSim.Region.ScriptEngine.Shared;
  48. using OpenSim.Region.ScriptEngine.Shared.Api.Plugins;
  49. using OpenSim.Region.ScriptEngine.Shared.ScriptBase;
  50. using OpenSim.Region.ScriptEngine.Interfaces;
  51. using OpenSim.Region.ScriptEngine.Shared.Api.Interfaces;
  52. using OpenSim.Services.Interfaces;
  53. using GridRegion = OpenSim.Services.Interfaces.GridRegion;
  54. using PresenceInfo = OpenSim.Services.Interfaces.PresenceInfo;
  55. using PrimType = OpenSim.Region.Framework.Scenes.PrimType;
  56. using AssetLandmark = OpenSim.Framework.AssetLandmark;
  57. using LSL_Float = OpenSim.Region.ScriptEngine.Shared.LSL_Types.LSLFloat;
  58. using LSL_Integer = OpenSim.Region.ScriptEngine.Shared.LSL_Types.LSLInteger;
  59. using LSL_Key = OpenSim.Region.ScriptEngine.Shared.LSL_Types.LSLString;
  60. using LSL_List = OpenSim.Region.ScriptEngine.Shared.LSL_Types.list;
  61. using LSL_Rotation = OpenSim.Region.ScriptEngine.Shared.LSL_Types.Quaternion;
  62. using LSL_String = OpenSim.Region.ScriptEngine.Shared.LSL_Types.LSLString;
  63. using LSL_Vector = OpenSim.Region.ScriptEngine.Shared.LSL_Types.Vector3;
  64. using System.Reflection;
  65. namespace OpenSim.Region.ScriptEngine.Shared.Api
  66. {
  67. // MUST be a ref type
  68. public class UserInfoCacheEntry
  69. {
  70. public int time;
  71. public UserAccount account;
  72. public PresenceInfo pinfo;
  73. }
  74. /// <summary>
  75. /// Contains all LSL ll-functions. This class will be in Default AppDomain.
  76. /// </summary>
  77. public class LSL_Api : MarshalByRefObject, ILSL_Api, IScriptApi
  78. {
  79. //private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
  80. protected IScriptEngine m_ScriptEngine;
  81. protected SceneObjectPart m_host;
  82. protected uint m_localID;
  83. protected UUID m_itemID;
  84. protected bool throwErrorOnNotImplemented = true;
  85. protected AsyncCommandManager AsyncCommands = null;
  86. protected float m_ScriptDelayFactor = 1.0f;
  87. protected float m_ScriptDistanceFactor = 1.0f;
  88. protected float m_MinTimerInterval = 0.5f;
  89. protected DateTime m_timer = DateTime.Now;
  90. protected bool m_waitingForScriptAnswer = false;
  91. protected bool m_automaticLinkPermission = false;
  92. protected IMessageTransferModule m_TransferModule = null;
  93. protected int m_notecardLineReadCharsMax = 255;
  94. protected int m_scriptConsoleChannel = 0;
  95. protected bool m_scriptConsoleChannelEnabled = false;
  96. protected IUrlModule m_UrlModule = null;
  97. protected Dictionary<UUID, UserInfoCacheEntry> m_userInfoCache =
  98. new Dictionary<UUID, UserInfoCacheEntry>();
  99. public void Initialize(IScriptEngine ScriptEngine, SceneObjectPart host, uint localID, UUID itemID)
  100. {
  101. m_ScriptEngine = ScriptEngine;
  102. m_host = host;
  103. m_localID = localID;
  104. m_itemID = itemID;
  105. m_ScriptDelayFactor =
  106. m_ScriptEngine.Config.GetFloat("ScriptDelayFactor", 1.0f);
  107. m_ScriptDistanceFactor =
  108. m_ScriptEngine.Config.GetFloat("ScriptDistanceLimitFactor", 1.0f);
  109. m_MinTimerInterval =
  110. m_ScriptEngine.Config.GetFloat("MinTimerInterval", 0.5f);
  111. m_automaticLinkPermission =
  112. m_ScriptEngine.Config.GetBoolean("AutomaticLinkPermission", false);
  113. m_notecardLineReadCharsMax =
  114. m_ScriptEngine.Config.GetInt("NotecardLineReadCharsMax", 255);
  115. if (m_notecardLineReadCharsMax > 65535)
  116. m_notecardLineReadCharsMax = 65535;
  117. m_TransferModule =
  118. m_ScriptEngine.World.RequestModuleInterface<IMessageTransferModule>();
  119. m_UrlModule = m_ScriptEngine.World.RequestModuleInterface<IUrlModule>();
  120. if (m_UrlModule != null)
  121. {
  122. m_ScriptEngine.OnScriptRemoved += m_UrlModule.ScriptRemoved;
  123. m_ScriptEngine.OnObjectRemoved += m_UrlModule.ObjectRemoved;
  124. }
  125. AsyncCommands = new AsyncCommandManager(ScriptEngine);
  126. }
  127. public override Object InitializeLifetimeService()
  128. {
  129. ILease lease = (ILease)base.InitializeLifetimeService();
  130. if (lease.CurrentState == LeaseState.Initial)
  131. {
  132. lease.InitialLeaseTime = TimeSpan.FromMinutes(0);
  133. // lease.RenewOnCallTime = TimeSpan.FromSeconds(10.0);
  134. // lease.SponsorshipTimeout = TimeSpan.FromMinutes(1.0);
  135. }
  136. return lease;
  137. }
  138. protected virtual void ScriptSleep(int delay)
  139. {
  140. delay = (int)((float)delay * m_ScriptDelayFactor);
  141. if (delay == 0)
  142. return;
  143. System.Threading.Thread.Sleep(delay);
  144. }
  145. public Scene World
  146. {
  147. get { return m_ScriptEngine.World; }
  148. }
  149. public void state(string newState)
  150. {
  151. m_ScriptEngine.SetState(m_itemID, newState);
  152. }
  153. /// <summary>
  154. /// Reset the named script. The script must be present
  155. /// in the same prim.
  156. /// </summary>
  157. public void llResetScript()
  158. {
  159. m_host.AddScriptLPS(1);
  160. m_ScriptEngine.ApiResetScript(m_itemID);
  161. }
  162. public void llResetOtherScript(string name)
  163. {
  164. UUID item;
  165. m_host.AddScriptLPS(1);
  166. if ((item = ScriptByName(name)) != UUID.Zero)
  167. m_ScriptEngine.ResetScript(item);
  168. else
  169. ShoutError("llResetOtherScript: script "+name+" not found");
  170. }
  171. public LSL_Integer llGetScriptState(string name)
  172. {
  173. UUID item;
  174. m_host.AddScriptLPS(1);
  175. if ((item = ScriptByName(name)) != UUID.Zero)
  176. {
  177. return m_ScriptEngine.GetScriptState(item) ?1:0;
  178. }
  179. ShoutError("llGetScriptState: script "+name+" not found");
  180. // If we didn't find it, then it's safe to
  181. // assume it is not running.
  182. return 0;
  183. }
  184. public void llSetScriptState(string name, int run)
  185. {
  186. UUID item;
  187. m_host.AddScriptLPS(1);
  188. // These functions are supposed to be robust,
  189. // so get the state one step at a time.
  190. if ((item = ScriptByName(name)) != UUID.Zero)
  191. {
  192. m_ScriptEngine.SetScriptState(item, run == 0 ? false : true);
  193. }
  194. else
  195. {
  196. ShoutError("llSetScriptState: script "+name+" not found");
  197. }
  198. }
  199. public List<SceneObjectPart> GetLinkParts(int linkType)
  200. {
  201. List<SceneObjectPart> ret = new List<SceneObjectPart>();
  202. ret.Add(m_host);
  203. switch (linkType)
  204. {
  205. case ScriptBaseClass.LINK_SET:
  206. if (m_host.ParentGroup != null)
  207. {
  208. return new List<SceneObjectPart>(m_host.ParentGroup.Parts);
  209. }
  210. return ret;
  211. case ScriptBaseClass.LINK_ROOT:
  212. if (m_host.ParentGroup != null)
  213. {
  214. ret = new List<SceneObjectPart>();
  215. ret.Add(m_host.ParentGroup.RootPart);
  216. return ret;
  217. }
  218. return ret;
  219. case ScriptBaseClass.LINK_ALL_OTHERS:
  220. if (m_host.ParentGroup == null)
  221. return new List<SceneObjectPart>();
  222. ret = new List<SceneObjectPart>(m_host.ParentGroup.Parts);
  223. if (ret.Contains(m_host))
  224. ret.Remove(m_host);
  225. return ret;
  226. case ScriptBaseClass.LINK_ALL_CHILDREN:
  227. if (m_host.ParentGroup == null)
  228. return new List<SceneObjectPart>();
  229. ret = new List<SceneObjectPart>(m_host.ParentGroup.Parts);
  230. if (ret.Contains(m_host.ParentGroup.RootPart))
  231. ret.Remove(m_host.ParentGroup.RootPart);
  232. return ret;
  233. case ScriptBaseClass.LINK_THIS:
  234. return ret;
  235. default:
  236. if (linkType < 0 || m_host.ParentGroup == null)
  237. return new List<SceneObjectPart>();
  238. SceneObjectPart target = m_host.ParentGroup.GetLinkNumPart(linkType);
  239. if (target == null)
  240. return new List<SceneObjectPart>();
  241. ret = new List<SceneObjectPart>();
  242. ret.Add(target);
  243. return ret;
  244. }
  245. }
  246. protected UUID InventorySelf()
  247. {
  248. UUID invItemID = new UUID();
  249. lock (m_host.TaskInventory)
  250. {
  251. foreach (KeyValuePair<UUID, TaskInventoryItem> inv in m_host.TaskInventory)
  252. {
  253. if (inv.Value.Type == 10 && inv.Value.ItemID == m_itemID)
  254. {
  255. invItemID = inv.Key;
  256. break;
  257. }
  258. }
  259. }
  260. return invItemID;
  261. }
  262. protected UUID InventoryKey(string name, int type)
  263. {
  264. m_host.AddScriptLPS(1);
  265. lock (m_host.TaskInventory)
  266. {
  267. foreach (KeyValuePair<UUID, TaskInventoryItem> inv in m_host.TaskInventory)
  268. {
  269. if (inv.Value.Name == name)
  270. {
  271. if (inv.Value.Type != type)
  272. return UUID.Zero;
  273. return inv.Value.AssetID;
  274. }
  275. }
  276. }
  277. return UUID.Zero;
  278. }
  279. protected UUID InventoryKey(string name)
  280. {
  281. m_host.AddScriptLPS(1);
  282. lock (m_host.TaskInventory)
  283. {
  284. foreach (KeyValuePair<UUID, TaskInventoryItem> inv in m_host.TaskInventory)
  285. {
  286. if (inv.Value.Name == name)
  287. {
  288. return inv.Value.AssetID;
  289. }
  290. }
  291. }
  292. return UUID.Zero;
  293. }
  294. /// <summary>
  295. /// accepts a valid UUID, -or- a name of an inventory item.
  296. /// Returns a valid UUID or UUID.Zero if key invalid and item not found
  297. /// in prim inventory.
  298. /// </summary>
  299. /// <param name="k"></param>
  300. /// <returns></returns>
  301. protected UUID KeyOrName(string k)
  302. {
  303. UUID key = UUID.Zero;
  304. // if we can parse the string as a key, use it.
  305. if (UUID.TryParse(k, out key))
  306. {
  307. return key;
  308. }
  309. // else try to locate the name in inventory of object. found returns key,
  310. // not found returns UUID.Zero which will translate to the default particle texture
  311. else
  312. {
  313. return InventoryKey(k);
  314. }
  315. }
  316. // convert a LSL_Rotation to a Quaternion
  317. protected Quaternion Rot2Quaternion(LSL_Rotation r)
  318. {
  319. Quaternion q = new Quaternion((float)r.x, (float)r.y, (float)r.z, (float)r.s);
  320. q.Normalize();
  321. return q;
  322. }
  323. //These are the implementations of the various ll-functions used by the LSL scripts.
  324. public LSL_Float llSin(double f)
  325. {
  326. m_host.AddScriptLPS(1);
  327. return (double)Math.Sin(f);
  328. }
  329. public LSL_Float llCos(double f)
  330. {
  331. m_host.AddScriptLPS(1);
  332. return (double)Math.Cos(f);
  333. }
  334. public LSL_Float llTan(double f)
  335. {
  336. m_host.AddScriptLPS(1);
  337. return (double)Math.Tan(f);
  338. }
  339. public LSL_Float llAtan2(double x, double y)
  340. {
  341. m_host.AddScriptLPS(1);
  342. return (double)Math.Atan2(x, y);
  343. }
  344. public LSL_Float llSqrt(double f)
  345. {
  346. m_host.AddScriptLPS(1);
  347. return (double)Math.Sqrt(f);
  348. }
  349. public LSL_Float llPow(double fbase, double fexponent)
  350. {
  351. m_host.AddScriptLPS(1);
  352. return (double)Math.Pow(fbase, fexponent);
  353. }
  354. public LSL_Integer llAbs(int i)
  355. {
  356. // changed to replicate LSL behaviour whereby minimum int value is returned untouched.
  357. m_host.AddScriptLPS(1);
  358. if (i == Int32.MinValue)
  359. return i;
  360. else
  361. return (int)Math.Abs(i);
  362. }
  363. public LSL_Float llFabs(double f)
  364. {
  365. m_host.AddScriptLPS(1);
  366. return (double)Math.Abs(f);
  367. }
  368. public LSL_Float llFrand(double mag)
  369. {
  370. m_host.AddScriptLPS(1);
  371. lock (Util.RandomClass)
  372. {
  373. return Util.RandomClass.NextDouble() * mag;
  374. }
  375. }
  376. public LSL_Integer llFloor(double f)
  377. {
  378. m_host.AddScriptLPS(1);
  379. return (int)Math.Floor(f);
  380. }
  381. public LSL_Integer llCeil(double f)
  382. {
  383. m_host.AddScriptLPS(1);
  384. return (int)Math.Ceiling(f);
  385. }
  386. // Xantor 01/May/2008 fixed midpointrounding (2.5 becomes 3.0 instead of 2.0, default = ToEven)
  387. public LSL_Integer llRound(double f)
  388. {
  389. m_host.AddScriptLPS(1);
  390. return (int)Math.Round(f, MidpointRounding.AwayFromZero);
  391. }
  392. //This next group are vector operations involving squaring and square root. ckrinke
  393. public LSL_Float llVecMag(LSL_Vector v)
  394. {
  395. m_host.AddScriptLPS(1);
  396. return LSL_Vector.Mag(v);
  397. }
  398. public LSL_Vector llVecNorm(LSL_Vector v)
  399. {
  400. m_host.AddScriptLPS(1);
  401. return LSL_Vector.Norm(v);
  402. }
  403. public LSL_Float llVecDist(LSL_Vector a, LSL_Vector b)
  404. {
  405. m_host.AddScriptLPS(1);
  406. double dx = a.x - b.x;
  407. double dy = a.y - b.y;
  408. double dz = a.z - b.z;
  409. return Math.Sqrt(dx * dx + dy * dy + dz * dz);
  410. }
  411. //Now we start getting into quaternions which means sin/cos, matrices and vectors. ckrinke
  412. // Old implementation of llRot2Euler. Normalization not required as Atan2 function will
  413. // only return values >= -PI (-180 degrees) and <= PI (180 degrees).
  414. public LSL_Vector llRot2Euler(LSL_Rotation r)
  415. {
  416. m_host.AddScriptLPS(1);
  417. //This implementation is from http://lslwiki.net/lslwiki/wakka.php?wakka=LibraryRotationFunctions. ckrinke
  418. LSL_Rotation t = new LSL_Rotation(r.x * r.x, r.y * r.y, r.z * r.z, r.s * r.s);
  419. double m = (t.x + t.y + t.z + t.s);
  420. if (m == 0) return new LSL_Vector();
  421. double n = 2 * (r.y * r.s + r.x * r.z);
  422. double p = m * m - n * n;
  423. if (p > 0)
  424. return new LSL_Vector(Math.Atan2(2.0 * (r.x * r.s - r.y * r.z), (-t.x - t.y + t.z + t.s)),
  425. Math.Atan2(n, Math.Sqrt(p)),
  426. Math.Atan2(2.0 * (r.z * r.s - r.x * r.y), (t.x - t.y - t.z + t.s)));
  427. else if (n > 0)
  428. return new LSL_Vector(0.0, Math.PI * 0.5, Math.Atan2((r.z * r.s + r.x * r.y), 0.5 - t.x - t.z));
  429. else
  430. return new LSL_Vector(0.0, -Math.PI * 0.5, Math.Atan2((r.z * r.s + r.x * r.y), 0.5 - t.x - t.z));
  431. }
  432. /* From wiki:
  433. The Euler angle vector (in radians) is converted to a rotation by doing the rotations around the 3 axes
  434. in Z, Y, X order. So llEuler2Rot(<1.0, 2.0, 3.0> * DEG_TO_RAD) generates a rotation by taking the zero rotation,
  435. a vector pointing along the X axis, first rotating it 3 degrees around the global Z axis, then rotating the resulting
  436. vector 2 degrees around the global Y axis, and finally rotating that 1 degree around the global X axis.
  437. */
  438. /* How we arrived at this llEuler2Rot
  439. *
  440. * Experiment in SL to determine conventions:
  441. * llEuler2Rot(<PI,0,0>)=<1,0,0,0>
  442. * llEuler2Rot(<0,PI,0>)=<0,1,0,0>
  443. * llEuler2Rot(<0,0,PI>)=<0,0,1,0>
  444. *
  445. * Important facts about Quaternions
  446. * - multiplication is non-commutative (a*b != b*a)
  447. * - http://en.wikipedia.org/wiki/Quaternion#Basis_multiplication
  448. *
  449. * Above SL experiment gives (c1,c2,c3,s1,s2,s3 as defined in our llEuler2Rot):
  450. * Qx = c1+i*s1
  451. * Qy = c2+j*s2;
  452. * Qz = c3+k*s3;
  453. *
  454. * Rotations applied in order (from above) Z, Y, X
  455. * Q = (Qz * Qy) * Qx
  456. * ((c1+i*s1)*(c2+j*s2))*(c3+k*s3)
  457. * (c1*c2+i*s1*c2+j*c1*s2+ij*s1*s2)*(c3+k*s3)
  458. * (c1*c2+i*s1*c2+j*c1*s2+k*s1*s2)*(c3+k*s3)
  459. * 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
  460. * 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
  461. * regroup: x=i*(s1*c2*c3+c1*s2*s3)
  462. * y=j*(c1*s2*c3-s1*c2*s3)
  463. * z=k*(s1*s2*c3+c1*c2*s3)
  464. * s= c1*c2*c3-s1*s2*s3
  465. *
  466. * This implementation agrees with the functions found here:
  467. * http://lslwiki.net/lslwiki/wakka.php?wakka=LibraryRotationFunctions
  468. * And with the results in SL.
  469. *
  470. * It's also possible to calculate llEuler2Rot by direct multiplication of
  471. * the Qz, Qy, and Qx vectors (as above - and done in the "accurate" function
  472. * from the wiki).
  473. * Apparently in some cases this is better from a numerical precision perspective?
  474. */
  475. public LSL_Rotation llEuler2Rot(LSL_Vector v)
  476. {
  477. m_host.AddScriptLPS(1);
  478. double x,y,z,s;
  479. double c1 = Math.Cos(v.x * 0.5);
  480. double c2 = Math.Cos(v.y * 0.5);
  481. double c3 = Math.Cos(v.z * 0.5);
  482. double s1 = Math.Sin(v.x * 0.5);
  483. double s2 = Math.Sin(v.y * 0.5);
  484. double s3 = Math.Sin(v.z * 0.5);
  485. x = s1 * c2 * c3 + c1 * s2 * s3;
  486. y = c1 * s2 * c3 - s1 * c2 * s3;
  487. z = s1 * s2 * c3 + c1 * c2 * s3;
  488. s = c1 * c2 * c3 - s1 * s2 * s3;
  489. return new LSL_Rotation(x, y, z, s);
  490. }
  491. public LSL_Rotation llAxes2Rot(LSL_Vector fwd, LSL_Vector left, LSL_Vector up)
  492. {
  493. m_host.AddScriptLPS(1);
  494. double s;
  495. double tr = fwd.x + left.y + up.z + 1.0;
  496. if (tr >= 1.0)
  497. {
  498. s = 0.5 / Math.Sqrt(tr);
  499. return new LSL_Rotation(
  500. (left.z - up.y) * s,
  501. (up.x - fwd.z) * s,
  502. (fwd.y - left.x) * s,
  503. 0.25 / s);
  504. }
  505. else
  506. {
  507. double max = (left.y > up.z) ? left.y : up.z;
  508. if (max < fwd.x)
  509. {
  510. s = Math.Sqrt(fwd.x - (left.y + up.z) + 1.0);
  511. double x = s * 0.5;
  512. s = 0.5 / s;
  513. return new LSL_Rotation(
  514. x,
  515. (fwd.y + left.x) * s,
  516. (up.x + fwd.z) * s,
  517. (left.z - up.y) * s);
  518. }
  519. else if (max == left.y)
  520. {
  521. s = Math.Sqrt(left.y - (up.z + fwd.x) + 1.0);
  522. double y = s * 0.5;
  523. s = 0.5 / s;
  524. return new LSL_Rotation(
  525. (fwd.y + left.x) * s,
  526. y,
  527. (left.z + up.y) * s,
  528. (up.x - fwd.z) * s);
  529. }
  530. else
  531. {
  532. s = Math.Sqrt(up.z - (fwd.x + left.y) + 1.0);
  533. double z = s * 0.5;
  534. s = 0.5 / s;
  535. return new LSL_Rotation(
  536. (up.x + fwd.z) * s,
  537. (left.z + up.y) * s,
  538. z,
  539. (fwd.y - left.x) * s);
  540. }
  541. }
  542. }
  543. public LSL_Vector llRot2Fwd(LSL_Rotation r)
  544. {
  545. m_host.AddScriptLPS(1);
  546. double x, y, z, m;
  547. m = r.x * r.x + r.y * r.y + r.z * r.z + r.s * r.s;
  548. // m is always greater than zero
  549. // if m is not equal to 1 then Rotation needs to be normalized
  550. if (Math.Abs(1.0 - m) > 0.000001) // allow a little slop here for calculation precision
  551. {
  552. m = 1.0 / Math.Sqrt(m);
  553. r.x *= m;
  554. r.y *= m;
  555. r.z *= m;
  556. r.s *= m;
  557. }
  558. // Fast Algebric Calculations instead of Vectors & Quaternions Product
  559. x = r.x * r.x - r.y * r.y - r.z * r.z + r.s * r.s;
  560. y = 2 * (r.x * r.y + r.z * r.s);
  561. z = 2 * (r.x * r.z - r.y * r.s);
  562. return (new LSL_Vector(x, y, z));
  563. }
  564. public LSL_Vector llRot2Left(LSL_Rotation r)
  565. {
  566. m_host.AddScriptLPS(1);
  567. double x, y, z, m;
  568. m = r.x * r.x + r.y * r.y + r.z * r.z + r.s * r.s;
  569. // m is always greater than zero
  570. // if m is not equal to 1 then Rotation needs to be normalized
  571. if (Math.Abs(1.0 - m) > 0.000001) // allow a little slop here for calculation precision
  572. {
  573. m = 1.0 / Math.Sqrt(m);
  574. r.x *= m;
  575. r.y *= m;
  576. r.z *= m;
  577. r.s *= m;
  578. }
  579. // Fast Algebric Calculations instead of Vectors & Quaternions Product
  580. x = 2 * (r.x * r.y - r.z * r.s);
  581. y = -r.x * r.x + r.y * r.y - r.z * r.z + r.s * r.s;
  582. z = 2 * (r.x * r.s + r.y * r.z);
  583. return (new LSL_Vector(x, y, z));
  584. }
  585. public LSL_Vector llRot2Up(LSL_Rotation r)
  586. {
  587. m_host.AddScriptLPS(1);
  588. double x, y, z, m;
  589. m = r.x * r.x + r.y * r.y + r.z * r.z + r.s * r.s;
  590. // m is always greater than zero
  591. // if m is not equal to 1 then Rotation needs to be normalized
  592. if (Math.Abs(1.0 - m) > 0.000001) // allow a little slop here for calculation precision
  593. {
  594. m = 1.0 / Math.Sqrt(m);
  595. r.x *= m;
  596. r.y *= m;
  597. r.z *= m;
  598. r.s *= m;
  599. }
  600. // Fast Algebric Calculations instead of Vectors & Quaternions Product
  601. x = 2 * (r.x * r.z + r.y * r.s);
  602. y = 2 * (-r.x * r.s + r.y * r.z);
  603. z = -r.x * r.x - r.y * r.y + r.z * r.z + r.s * r.s;
  604. return (new LSL_Vector(x, y, z));
  605. }
  606. public LSL_Rotation llRotBetween(LSL_Vector a, LSL_Vector b)
  607. {
  608. //A and B should both be normalized
  609. m_host.AddScriptLPS(1);
  610. LSL_Rotation rotBetween;
  611. // Check for zero vectors. If either is zero, return zero rotation. Otherwise,
  612. // continue calculation.
  613. if (a == new LSL_Vector(0.0f, 0.0f, 0.0f) || b == new LSL_Vector(0.0f, 0.0f, 0.0f))
  614. {
  615. rotBetween = new LSL_Rotation(0.0f, 0.0f, 0.0f, 1.0f);
  616. }
  617. else
  618. {
  619. a = LSL_Vector.Norm(a);
  620. b = LSL_Vector.Norm(b);
  621. double dotProduct = LSL_Vector.Dot(a, b);
  622. // There are two degenerate cases possible. These are for vectors 180 or
  623. // 0 degrees apart. These have to be detected and handled individually.
  624. //
  625. // Check for vectors 180 degrees apart.
  626. // A dot product of -1 would mean the angle between vectors is 180 degrees.
  627. if (dotProduct < -0.9999999f)
  628. {
  629. // First assume X axis is orthogonal to the vectors.
  630. LSL_Vector orthoVector = new LSL_Vector(1.0f, 0.0f, 0.0f);
  631. orthoVector = orthoVector - a * (a.x / LSL_Vector.Dot(a, a));
  632. // Check for near zero vector. A very small non-zero number here will create
  633. // a rotation in an undesired direction.
  634. if (LSL_Vector.Mag(orthoVector) > 0.0001)
  635. {
  636. rotBetween = new LSL_Rotation(orthoVector.x, orthoVector.y, orthoVector.z, 0.0f);
  637. }
  638. // If the magnitude of the vector was near zero, then assume the X axis is not
  639. // orthogonal and use the Z axis instead.
  640. else
  641. {
  642. // Set 180 z rotation.
  643. rotBetween = new LSL_Rotation(0.0f, 0.0f, 1.0f, 0.0f);
  644. }
  645. }
  646. // Check for parallel vectors.
  647. // A dot product of 1 would mean the angle between vectors is 0 degrees.
  648. else if (dotProduct > 0.9999999f)
  649. {
  650. // Set zero rotation.
  651. rotBetween = new LSL_Rotation(0.0f, 0.0f, 0.0f, 1.0f);
  652. }
  653. else
  654. {
  655. // All special checks have been performed so get the axis of rotation.
  656. LSL_Vector crossProduct = LSL_Vector.Cross(a, b);
  657. // Quarternion s value is the length of the unit vector + dot product.
  658. double qs = 1.0 + dotProduct;
  659. rotBetween = new LSL_Rotation(crossProduct.x, crossProduct.y, crossProduct.z, qs);
  660. // Normalize the rotation.
  661. double mag = LSL_Rotation.Mag(rotBetween);
  662. // We shouldn't have to worry about a divide by zero here. The qs value will be
  663. // non-zero because we already know if we're here, then the dotProduct is not -1 so
  664. // qs will not be zero. Also, we've already handled the input vectors being zero so the
  665. // crossProduct vector should also not be zero.
  666. rotBetween.x = rotBetween.x / mag;
  667. rotBetween.y = rotBetween.y / mag;
  668. rotBetween.z = rotBetween.z / mag;
  669. rotBetween.s = rotBetween.s / mag;
  670. // Check for undefined values and set zero rotation if any found. This code might not actually be required
  671. // any longer since zero vectors are checked for at the top.
  672. if (Double.IsNaN(rotBetween.x) || Double.IsNaN(rotBetween.y) || Double.IsNaN(rotBetween.z) || Double.IsNaN(rotBetween.s))
  673. {
  674. rotBetween = new LSL_Rotation(0.0f, 0.0f, 0.0f, 1.0f);
  675. }
  676. }
  677. }
  678. return rotBetween;
  679. }
  680. public void llWhisper(int channelID, string text)
  681. {
  682. m_host.AddScriptLPS(1);
  683. if (text.Length > 1023)
  684. text = text.Substring(0, 1023);
  685. World.SimChat(Utils.StringToBytes(text),
  686. ChatTypeEnum.Whisper, channelID, m_host.ParentGroup.RootPart.AbsolutePosition, m_host.Name, m_host.UUID, false);
  687. IWorldComm wComm = m_ScriptEngine.World.RequestModuleInterface<IWorldComm>();
  688. if (wComm != null)
  689. wComm.DeliverMessage(ChatTypeEnum.Whisper, channelID, m_host.Name, m_host.UUID, text);
  690. }
  691. public void llSay(int channelID, string text)
  692. {
  693. m_host.AddScriptLPS(1);
  694. if (m_scriptConsoleChannelEnabled && (channelID == m_scriptConsoleChannel))
  695. {
  696. Console.WriteLine(text);
  697. }
  698. else
  699. {
  700. if (text.Length > 1023)
  701. text = text.Substring(0, 1023);
  702. World.SimChat(Utils.StringToBytes(text),
  703. ChatTypeEnum.Say, channelID, m_host.ParentGroup.RootPart.AbsolutePosition, m_host.Name, m_host.UUID, false);
  704. IWorldComm wComm = m_ScriptEngine.World.RequestModuleInterface<IWorldComm>();
  705. if (wComm != null)
  706. wComm.DeliverMessage(ChatTypeEnum.Say, channelID, m_host.Name, m_host.UUID, text);
  707. }
  708. }
  709. public void llShout(int channelID, string text)
  710. {
  711. m_host.AddScriptLPS(1);
  712. if (text.Length > 1023)
  713. text = text.Substring(0, 1023);
  714. World.SimChat(Utils.StringToBytes(text),
  715. ChatTypeEnum.Shout, channelID, m_host.ParentGroup.RootPart.AbsolutePosition, m_host.Name, m_host.UUID, true);
  716. IWorldComm wComm = m_ScriptEngine.World.RequestModuleInterface<IWorldComm>();
  717. if (wComm != null)
  718. wComm.DeliverMessage(ChatTypeEnum.Shout, channelID, m_host.Name, m_host.UUID, text);
  719. }
  720. public void llRegionSay(int channelID, string text)
  721. {
  722. if (channelID == 0)
  723. {
  724. LSLError("Cannot use llRegionSay() on channel 0");
  725. return;
  726. }
  727. if (text.Length > 1023)
  728. text = text.Substring(0, 1023);
  729. m_host.AddScriptLPS(1);
  730. IWorldComm wComm = m_ScriptEngine.World.RequestModuleInterface<IWorldComm>();
  731. if (wComm != null)
  732. wComm.DeliverMessage(ChatTypeEnum.Region, channelID, m_host.Name, m_host.UUID, text);
  733. }
  734. public LSL_Integer llListen(int channelID, string name, string ID, string msg)
  735. {
  736. m_host.AddScriptLPS(1);
  737. UUID keyID;
  738. UUID.TryParse(ID, out keyID);
  739. IWorldComm wComm = m_ScriptEngine.World.RequestModuleInterface<IWorldComm>();
  740. if (wComm != null)
  741. return wComm.Listen(m_localID, m_itemID, m_host.UUID, channelID, name, keyID, msg);
  742. else
  743. return -1;
  744. }
  745. public void llListenControl(int number, int active)
  746. {
  747. m_host.AddScriptLPS(1);
  748. IWorldComm wComm = m_ScriptEngine.World.RequestModuleInterface<IWorldComm>();
  749. if (wComm != null)
  750. wComm.ListenControl(m_itemID, number, active);
  751. }
  752. public void llListenRemove(int number)
  753. {
  754. m_host.AddScriptLPS(1);
  755. IWorldComm wComm = m_ScriptEngine.World.RequestModuleInterface<IWorldComm>();
  756. if (wComm != null)
  757. wComm.ListenRemove(m_itemID, number);
  758. }
  759. public void llSensor(string name, string id, int type, double range, double arc)
  760. {
  761. m_host.AddScriptLPS(1);
  762. UUID keyID = UUID.Zero;
  763. UUID.TryParse(id, out keyID);
  764. AsyncCommands.SensorRepeatPlugin.SenseOnce(m_localID, m_itemID, name, keyID, type, range, arc, m_host);
  765. }
  766. public void llSensorRepeat(string name, string id, int type, double range, double arc, double rate)
  767. {
  768. m_host.AddScriptLPS(1);
  769. UUID keyID = UUID.Zero;
  770. UUID.TryParse(id, out keyID);
  771. AsyncCommands.SensorRepeatPlugin.SetSenseRepeatEvent(m_localID, m_itemID, name, keyID, type, range, arc, rate, m_host);
  772. }
  773. public void llSensorRemove()
  774. {
  775. m_host.AddScriptLPS(1);
  776. AsyncCommands.SensorRepeatPlugin.UnSetSenseRepeaterEvents(m_localID, m_itemID);
  777. }
  778. public string resolveName(UUID objecUUID)
  779. {
  780. // try avatar username surname
  781. UserAccount account = World.UserAccountService.GetUserAccount(World.RegionInfo.ScopeID, objecUUID);
  782. if (account != null)
  783. {
  784. string avatarname = account.Name;
  785. return avatarname;
  786. }
  787. // try an scene object
  788. SceneObjectPart SOP = World.GetSceneObjectPart(objecUUID);
  789. if (SOP != null)
  790. {
  791. string objectname = SOP.Name;
  792. return objectname;
  793. }
  794. EntityBase SensedObject;
  795. World.Entities.TryGetValue(objecUUID, out SensedObject);
  796. if (SensedObject == null)
  797. {
  798. IGroupsModule groups = World.RequestModuleInterface<IGroupsModule>();
  799. if (groups != null)
  800. {
  801. GroupRecord gr = groups.GetGroupRecord(objecUUID);
  802. if (gr != null)
  803. return gr.GroupName;
  804. }
  805. return String.Empty;
  806. }
  807. return SensedObject.Name;
  808. }
  809. public LSL_String llDetectedName(int number)
  810. {
  811. m_host.AddScriptLPS(1);
  812. DetectParams detectedParams = m_ScriptEngine.GetDetectParams(m_itemID, number);
  813. if (detectedParams == null)
  814. return String.Empty;
  815. return detectedParams.Name;
  816. }
  817. public LSL_String llDetectedKey(int number)
  818. {
  819. m_host.AddScriptLPS(1);
  820. DetectParams detectedParams = m_ScriptEngine.GetDetectParams(m_itemID, number);
  821. if (detectedParams == null)
  822. return String.Empty;
  823. return detectedParams.Key.ToString();
  824. }
  825. public LSL_String llDetectedOwner(int number)
  826. {
  827. m_host.AddScriptLPS(1);
  828. DetectParams detectedParams = m_ScriptEngine.GetDetectParams(m_itemID, number);
  829. if (detectedParams == null)
  830. return String.Empty;
  831. return detectedParams.Owner.ToString();
  832. }
  833. public LSL_Integer llDetectedType(int number)
  834. {
  835. m_host.AddScriptLPS(1);
  836. DetectParams detectedParams = m_ScriptEngine.GetDetectParams(m_itemID, number);
  837. if (detectedParams == null)
  838. return 0;
  839. return new LSL_Integer(detectedParams.Type);
  840. }
  841. public LSL_Vector llDetectedPos(int number)
  842. {
  843. m_host.AddScriptLPS(1);
  844. DetectParams detectedParams = m_ScriptEngine.GetDetectParams(m_itemID, number);
  845. if (detectedParams == null)
  846. return new LSL_Vector();
  847. return detectedParams.Position;
  848. }
  849. public LSL_Vector llDetectedVel(int number)
  850. {
  851. m_host.AddScriptLPS(1);
  852. DetectParams detectedParams = m_ScriptEngine.GetDetectParams(m_itemID, number);
  853. if (detectedParams == null)
  854. return new LSL_Vector();
  855. return detectedParams.Velocity;
  856. }
  857. public LSL_Vector llDetectedGrab(int number)
  858. {
  859. m_host.AddScriptLPS(1);
  860. DetectParams parms = m_ScriptEngine.GetDetectParams(m_itemID, number);
  861. if (parms == null)
  862. return new LSL_Vector(0, 0, 0);
  863. return parms.OffsetPos;
  864. }
  865. public LSL_Rotation llDetectedRot(int number)
  866. {
  867. m_host.AddScriptLPS(1);
  868. DetectParams detectedParams = m_ScriptEngine.GetDetectParams(m_itemID, number);
  869. if (detectedParams == null)
  870. return new LSL_Rotation();
  871. return detectedParams.Rotation;
  872. }
  873. public LSL_Integer llDetectedGroup(int number)
  874. {
  875. m_host.AddScriptLPS(1);
  876. DetectParams detectedParams = m_ScriptEngine.GetDetectParams(m_itemID, number);
  877. if (detectedParams == null)
  878. return new LSL_Integer(0);
  879. if (m_host.GroupID == detectedParams.Group)
  880. return new LSL_Integer(1);
  881. return new LSL_Integer(0);
  882. }
  883. public LSL_Integer llDetectedLinkNumber(int number)
  884. {
  885. m_host.AddScriptLPS(1);
  886. DetectParams parms = m_ScriptEngine.GetDetectParams(m_itemID, number);
  887. if (parms == null)
  888. return new LSL_Integer(0);
  889. return new LSL_Integer(parms.LinkNum);
  890. }
  891. /// <summary>
  892. /// See http://wiki.secondlife.com/wiki/LlDetectedTouchBinormal for details
  893. /// </summary>
  894. public LSL_Vector llDetectedTouchBinormal(int index)
  895. {
  896. m_host.AddScriptLPS(1);
  897. DetectParams detectedParams = m_ScriptEngine.GetDetectParams(m_itemID, index);
  898. if (detectedParams == null)
  899. return new LSL_Vector();
  900. return detectedParams.TouchBinormal;
  901. }
  902. /// <summary>
  903. /// See http://wiki.secondlife.com/wiki/LlDetectedTouchFace for details
  904. /// </summary>
  905. public LSL_Integer llDetectedTouchFace(int index)
  906. {
  907. m_host.AddScriptLPS(1);
  908. DetectParams detectedParams = m_ScriptEngine.GetDetectParams(m_itemID, index);
  909. if (detectedParams == null)
  910. return new LSL_Integer(-1);
  911. return new LSL_Integer(detectedParams.TouchFace);
  912. }
  913. /// <summary>
  914. /// See http://wiki.secondlife.com/wiki/LlDetectedTouchNormal for details
  915. /// </summary>
  916. public LSL_Vector llDetectedTouchNormal(int index)
  917. {
  918. m_host.AddScriptLPS(1);
  919. DetectParams detectedParams = m_ScriptEngine.GetDetectParams(m_itemID, index);
  920. if (detectedParams == null)
  921. return new LSL_Vector();
  922. return detectedParams.TouchNormal;
  923. }
  924. /// <summary>
  925. /// See http://wiki.secondlife.com/wiki/LlDetectedTouchPos for details
  926. /// </summary>
  927. public LSL_Vector llDetectedTouchPos(int index)
  928. {
  929. m_host.AddScriptLPS(1);
  930. DetectParams detectedParams = m_ScriptEngine.GetDetectParams(m_itemID, index);
  931. if (detectedParams == null)
  932. return new LSL_Vector();
  933. return detectedParams.TouchPos;
  934. }
  935. /// <summary>
  936. /// See http://wiki.secondlife.com/wiki/LlDetectedTouchST for details
  937. /// </summary>
  938. public LSL_Vector llDetectedTouchST(int index)
  939. {
  940. m_host.AddScriptLPS(1);
  941. DetectParams detectedParams = m_ScriptEngine.GetDetectParams(m_itemID, index);
  942. if (detectedParams == null)
  943. return new LSL_Vector(-1.0, -1.0, 0.0);
  944. return detectedParams.TouchST;
  945. }
  946. /// <summary>
  947. /// See http://wiki.secondlife.com/wiki/LlDetectedTouchUV for details
  948. /// </summary>
  949. public LSL_Vector llDetectedTouchUV(int index)
  950. {
  951. m_host.AddScriptLPS(1);
  952. DetectParams detectedParams = m_ScriptEngine.GetDetectParams(m_itemID, index);
  953. if (detectedParams == null)
  954. return new LSL_Vector(-1.0, -1.0, 0.0);
  955. return detectedParams.TouchUV;
  956. }
  957. public virtual void llDie()
  958. {
  959. m_host.AddScriptLPS(1);
  960. throw new SelfDeleteException();
  961. }
  962. public LSL_Float llGround(LSL_Vector offset)
  963. {
  964. m_host.AddScriptLPS(1);
  965. Vector3 pos = m_host.GetWorldPosition() + new Vector3((float)offset.x,
  966. (float)offset.y,
  967. (float)offset.z);
  968. //Get the slope normal. This gives us the equation of the plane tangent to the slope.
  969. LSL_Vector vsn = llGroundNormal(offset);
  970. // Clamp to valid position
  971. if (pos.X < 0)
  972. pos.X = 0;
  973. else if (pos.X >= World.Heightmap.Width)
  974. pos.X = World.Heightmap.Width - 1;
  975. if (pos.Y < 0)
  976. pos.Y = 0;
  977. else if (pos.Y >= World.Heightmap.Height)
  978. pos.Y = World.Heightmap.Height - 1;
  979. //Get the height for the integer coordinates from the Heightmap
  980. float baseheight = (float)World.Heightmap[(int)pos.X, (int)pos.Y];
  981. //Calculate the difference between the actual coordinates and the integer coordinates
  982. float xdiff = pos.X - (float)((int)pos.X);
  983. float ydiff = pos.Y - (float)((int)pos.Y);
  984. //Use the equation of the tangent plane to adjust the height to account for slope
  985. return (((vsn.x * xdiff) + (vsn.y * ydiff)) / (-1 * vsn.z)) + baseheight;
  986. }
  987. public LSL_Float llCloud(LSL_Vector offset)
  988. {
  989. m_host.AddScriptLPS(1);
  990. float cloudCover = 0f;
  991. ICloudModule module = World.RequestModuleInterface<ICloudModule>();
  992. if (module != null)
  993. {
  994. Vector3 pos = m_host.GetWorldPosition();
  995. int x = (int)(pos.X + offset.x);
  996. int y = (int)(pos.Y + offset.y);
  997. cloudCover = module.CloudCover(x, y, 0);
  998. }
  999. return cloudCover;
  1000. }
  1001. public LSL_Vector llWind(LSL_Vector offset)
  1002. {
  1003. m_host.AddScriptLPS(1);
  1004. LSL_Vector wind = new LSL_Vector(0, 0, 0);
  1005. IWindModule module = World.RequestModuleInterface<IWindModule>();
  1006. if (module != null)
  1007. {
  1008. Vector3 pos = m_host.GetWorldPosition();
  1009. int x = (int)(pos.X + offset.x);
  1010. int y = (int)(pos.Y + offset.y);
  1011. Vector3 windSpeed = module.WindSpeed(x, y, 0);
  1012. wind.x = windSpeed.X;
  1013. wind.y = windSpeed.Y;
  1014. }
  1015. return wind;
  1016. }
  1017. public void llSetStatus(int status, int value)
  1018. {
  1019. m_host.AddScriptLPS(1);
  1020. int statusrotationaxis = 0;
  1021. if ((status & ScriptBaseClass.STATUS_PHYSICS) == ScriptBaseClass.STATUS_PHYSICS)
  1022. {
  1023. if (value != 0)
  1024. {
  1025. SceneObjectGroup group = m_host.ParentGroup;
  1026. if (group == null)
  1027. return;
  1028. bool allow = true;
  1029. foreach (SceneObjectPart part in group.Parts)
  1030. {
  1031. if (part.Scale.X > World.m_maxPhys || part.Scale.Y > World.m_maxPhys || part.Scale.Z > World.m_maxPhys)
  1032. {
  1033. allow = false;
  1034. break;
  1035. }
  1036. }
  1037. if (!allow)
  1038. return;
  1039. m_host.ScriptSetPhysicsStatus(true);
  1040. }
  1041. else
  1042. m_host.ScriptSetPhysicsStatus(false);
  1043. }
  1044. if ((status & ScriptBaseClass.STATUS_PHANTOM) == ScriptBaseClass.STATUS_PHANTOM)
  1045. {
  1046. if (value != 0)
  1047. m_host.ScriptSetPhantomStatus(true);
  1048. else
  1049. m_host.ScriptSetPhantomStatus(false);
  1050. }
  1051. if ((status & ScriptBaseClass.STATUS_CAST_SHADOWS) == ScriptBaseClass.STATUS_CAST_SHADOWS)
  1052. {
  1053. m_host.AddFlag(PrimFlags.CastShadows);
  1054. }
  1055. if ((status & ScriptBaseClass.STATUS_ROTATE_X) == ScriptBaseClass.STATUS_ROTATE_X)
  1056. {
  1057. statusrotationaxis |= ScriptBaseClass.STATUS_ROTATE_X;
  1058. }
  1059. if ((status & ScriptBaseClass.STATUS_ROTATE_Y) == ScriptBaseClass.STATUS_ROTATE_Y)
  1060. {
  1061. statusrotationaxis |= ScriptBaseClass.STATUS_ROTATE_Y;
  1062. }
  1063. if ((status & ScriptBaseClass.STATUS_ROTATE_Z) == ScriptBaseClass.STATUS_ROTATE_Z)
  1064. {
  1065. statusrotationaxis |= ScriptBaseClass.STATUS_ROTATE_Z;
  1066. }
  1067. if ((status & ScriptBaseClass.STATUS_BLOCK_GRAB) == ScriptBaseClass.STATUS_BLOCK_GRAB)
  1068. {
  1069. if (value != 0)
  1070. m_host.SetBlockGrab(true);
  1071. else
  1072. m_host.SetBlockGrab(false);
  1073. }
  1074. if ((status & ScriptBaseClass.STATUS_DIE_AT_EDGE) == ScriptBaseClass.STATUS_DIE_AT_EDGE)
  1075. {
  1076. if (value != 0)
  1077. m_host.SetDieAtEdge(true);
  1078. else
  1079. m_host.SetDieAtEdge(false);
  1080. }
  1081. if ((status & ScriptBaseClass.STATUS_RETURN_AT_EDGE) == ScriptBaseClass.STATUS_RETURN_AT_EDGE)
  1082. {
  1083. if (value != 0)
  1084. m_host.SetReturnAtEdge(true);
  1085. else
  1086. m_host.SetReturnAtEdge(false);
  1087. }
  1088. if ((status & ScriptBaseClass.STATUS_SANDBOX) == ScriptBaseClass.STATUS_SANDBOX)
  1089. {
  1090. if (value != 0)
  1091. m_host.SetStatusSandbox(true);
  1092. else
  1093. m_host.SetStatusSandbox(false);
  1094. }
  1095. if (statusrotationaxis != 0)
  1096. {
  1097. m_host.SetAxisRotation(statusrotationaxis, value);
  1098. }
  1099. }
  1100. public LSL_Integer llGetStatus(int status)
  1101. {
  1102. m_host.AddScriptLPS(1);
  1103. // m_log.Debug(m_host.ToString() + " status is " + m_host.GetEffectiveObjectFlags().ToString());
  1104. switch (status)
  1105. {
  1106. case ScriptBaseClass.STATUS_PHYSICS:
  1107. if ((m_host.GetEffectiveObjectFlags() & (uint)PrimFlags.Physics) == (uint)PrimFlags.Physics)
  1108. {
  1109. return 1;
  1110. }
  1111. return 0;
  1112. case ScriptBaseClass.STATUS_PHANTOM:
  1113. if ((m_host.GetEffectiveObjectFlags() & (uint)PrimFlags.Phantom) == (uint)PrimFlags.Phantom)
  1114. {
  1115. return 1;
  1116. }
  1117. return 0;
  1118. case ScriptBaseClass.STATUS_CAST_SHADOWS:
  1119. if ((m_host.GetEffectiveObjectFlags() & (uint)PrimFlags.CastShadows) == (uint)PrimFlags.CastShadows)
  1120. {
  1121. return 1;
  1122. }
  1123. return 0;
  1124. case ScriptBaseClass.STATUS_BLOCK_GRAB:
  1125. if (m_host.GetBlockGrab())
  1126. return 1;
  1127. else
  1128. return 0;
  1129. case ScriptBaseClass.STATUS_DIE_AT_EDGE:
  1130. if (m_host.GetDieAtEdge())
  1131. return 1;
  1132. else
  1133. return 0;
  1134. case ScriptBaseClass.STATUS_RETURN_AT_EDGE:
  1135. if (m_host.GetReturnAtEdge())
  1136. return 1;
  1137. else
  1138. return 0;
  1139. case ScriptBaseClass.STATUS_ROTATE_X:
  1140. if (m_host.GetAxisRotation(2) == 2)
  1141. return 1;
  1142. else
  1143. return 0;
  1144. case ScriptBaseClass.STATUS_ROTATE_Y:
  1145. if (m_host.GetAxisRotation(4) == 4)
  1146. return 1;
  1147. else
  1148. return 0;
  1149. case ScriptBaseClass.STATUS_ROTATE_Z:
  1150. if (m_host.GetAxisRotation(8) == 8)
  1151. return 1;
  1152. else
  1153. return 0;
  1154. case ScriptBaseClass.STATUS_SANDBOX:
  1155. if (m_host.GetStatusSandbox())
  1156. return 1;
  1157. else
  1158. return 0;
  1159. }
  1160. return 0;
  1161. }
  1162. public void llSetScale(LSL_Vector scale)
  1163. {
  1164. m_host.AddScriptLPS(1);
  1165. SetScale(m_host, scale);
  1166. }
  1167. protected void SetScale(SceneObjectPart part, LSL_Vector scale)
  1168. {
  1169. // TODO: this needs to trigger a persistance save as well
  1170. if (part == null || part.ParentGroup == null || part.ParentGroup.IsDeleted)
  1171. return;
  1172. if (scale.x < 0.01)
  1173. scale.x = 0.01;
  1174. if (scale.y < 0.01)
  1175. scale.y = 0.01;
  1176. if (scale.z < 0.01)
  1177. scale.z = 0.01;
  1178. if (part.ParentGroup.RootPart.PhysActor != null && part.ParentGroup.RootPart.PhysActor.IsPhysical)
  1179. {
  1180. if (scale.x > World.m_maxPhys)
  1181. scale.x = World.m_maxPhys;
  1182. if (scale.y > World.m_maxPhys)
  1183. scale.y = World.m_maxPhys;
  1184. if (scale.z > World.m_maxPhys)
  1185. scale.z = World.m_maxPhys;
  1186. }
  1187. if (scale.x > World.m_maxNonphys)
  1188. scale.x = World.m_maxNonphys;
  1189. if (scale.y > World.m_maxNonphys)
  1190. scale.y = World.m_maxNonphys;
  1191. if (scale.z > World.m_maxNonphys)
  1192. scale.z = World.m_maxNonphys;
  1193. Vector3 tmp = part.Scale;
  1194. tmp.X = (float)scale.x;
  1195. tmp.Y = (float)scale.y;
  1196. tmp.Z = (float)scale.z;
  1197. part.Scale = tmp;
  1198. part.SendFullUpdateToAllClients();
  1199. }
  1200. public LSL_Vector llGetScale()
  1201. {
  1202. m_host.AddScriptLPS(1);
  1203. return new LSL_Vector(m_host.Scale.X, m_host.Scale.Y, m_host.Scale.Z);
  1204. }
  1205. public void llSetClickAction(int action)
  1206. {
  1207. m_host.AddScriptLPS(1);
  1208. m_host.ClickAction = (byte)action;
  1209. if (m_host.ParentGroup != null) m_host.ParentGroup.HasGroupChanged = true;
  1210. m_host.ScheduleFullUpdate();
  1211. return;
  1212. }
  1213. public void llSetColor(LSL_Vector color, int face)
  1214. {
  1215. m_host.AddScriptLPS(1);
  1216. if (face == ScriptBaseClass.ALL_SIDES)
  1217. face = SceneObjectPart.ALL_SIDES;
  1218. m_host.SetFaceColor(new Vector3((float)color.x, (float)color.y, (float)color.z), face);
  1219. }
  1220. public void SetTexGen(SceneObjectPart part, int face,int style)
  1221. {
  1222. Primitive.TextureEntry tex = part.Shape.Textures;
  1223. MappingType textype;
  1224. textype = MappingType.Default;
  1225. if (style == (int)ScriptBaseClass.PRIM_TEXGEN_PLANAR)
  1226. textype = MappingType.Planar;
  1227. if (face >= 0 && face < GetNumberOfSides(part))
  1228. {
  1229. tex.CreateFace((uint) face);
  1230. tex.FaceTextures[face].TexMapType = textype;
  1231. part.UpdateTexture(tex);
  1232. return;
  1233. }
  1234. else if (face == ScriptBaseClass.ALL_SIDES)
  1235. {
  1236. for (uint i = 0; i < GetNumberOfSides(part); i++)
  1237. {
  1238. if (tex.FaceTextures[i] != null)
  1239. {
  1240. tex.FaceTextures[i].TexMapType = textype;
  1241. }
  1242. tex.DefaultTexture.TexMapType = textype;
  1243. }
  1244. part.UpdateTexture(tex);
  1245. return;
  1246. }
  1247. }
  1248. public void SetGlow(SceneObjectPart part, int face, float glow)
  1249. {
  1250. Primitive.TextureEntry tex = part.Shape.Textures;
  1251. if (face >= 0 && face < GetNumberOfSides(part))
  1252. {
  1253. tex.CreateFace((uint) face);
  1254. tex.FaceTextures[face].Glow = glow;
  1255. part.UpdateTexture(tex);
  1256. return;
  1257. }
  1258. else if (face == ScriptBaseClass.ALL_SIDES)
  1259. {
  1260. for (uint i = 0; i < GetNumberOfSides(part); i++)
  1261. {
  1262. if (tex.FaceTextures[i] != null)
  1263. {
  1264. tex.FaceTextures[i].Glow = glow;
  1265. }
  1266. tex.DefaultTexture.Glow = glow;
  1267. }
  1268. part.UpdateTexture(tex);
  1269. return;
  1270. }
  1271. }
  1272. public void SetShiny(SceneObjectPart part, int face, int shiny, Bumpiness bump)
  1273. {
  1274. Shininess sval = new Shininess();
  1275. switch (shiny)
  1276. {
  1277. case 0:
  1278. sval = Shininess.None;
  1279. break;
  1280. case 1:
  1281. sval = Shininess.Low;
  1282. break;
  1283. case 2:
  1284. sval = Shininess.Medium;
  1285. break;
  1286. case 3:
  1287. sval = Shininess.High;
  1288. break;
  1289. default:
  1290. sval = Shininess.None;
  1291. break;
  1292. }
  1293. Primitive.TextureEntry tex = part.Shape.Textures;
  1294. if (face >= 0 && face < GetNumberOfSides(part))
  1295. {
  1296. tex.CreateFace((uint) face);
  1297. tex.FaceTextures[face].Shiny = sval;
  1298. tex.FaceTextures[face].Bump = bump;
  1299. part.UpdateTexture(tex);
  1300. return;
  1301. }
  1302. else if (face == ScriptBaseClass.ALL_SIDES)
  1303. {
  1304. for (uint i = 0; i < GetNumberOfSides(part); i++)
  1305. {
  1306. if (tex.FaceTextures[i] != null)
  1307. {
  1308. tex.FaceTextures[i].Shiny = sval;
  1309. tex.FaceTextures[i].Bump = bump;;
  1310. }
  1311. tex.DefaultTexture.Shiny = sval;
  1312. tex.DefaultTexture.Bump = bump;
  1313. }
  1314. part.UpdateTexture(tex);
  1315. return;
  1316. }
  1317. }
  1318. public void SetFullBright(SceneObjectPart part, int face, bool bright)
  1319. {
  1320. Primitive.TextureEntry tex = part.Shape.Textures;
  1321. if (face >= 0 && face < GetNumberOfSides(part))
  1322. {
  1323. tex.CreateFace((uint) face);
  1324. tex.FaceTextures[face].Fullbright = bright;
  1325. part.UpdateTexture(tex);
  1326. return;
  1327. }
  1328. else if (face == ScriptBaseClass.ALL_SIDES)
  1329. {
  1330. for (uint i = 0; i < GetNumberOfSides(part); i++)
  1331. {
  1332. if (tex.FaceTextures[i] != null)
  1333. {
  1334. tex.FaceTextures[i].Fullbright = bright;
  1335. }
  1336. }
  1337. tex.DefaultTexture.Fullbright = bright;
  1338. part.UpdateTexture(tex);
  1339. return;
  1340. }
  1341. }
  1342. public LSL_Float llGetAlpha(int face)
  1343. {
  1344. m_host.AddScriptLPS(1);
  1345. return GetAlpha(m_host, face);
  1346. }
  1347. protected LSL_Float GetAlpha(SceneObjectPart part, int face)
  1348. {
  1349. Primitive.TextureEntry tex = part.Shape.Textures;
  1350. if (face == ScriptBaseClass.ALL_SIDES)
  1351. {
  1352. int i;
  1353. double sum = 0.0;
  1354. for (i = 0 ; i < GetNumberOfSides(part); i++)
  1355. sum += (double)tex.GetFace((uint)i).RGBA.A;
  1356. return sum;
  1357. }
  1358. if (face >= 0 && face < GetNumberOfSides(part))
  1359. {
  1360. return (double)tex.GetFace((uint)face).RGBA.A;
  1361. }
  1362. return 0.0;
  1363. }
  1364. public void llSetAlpha(double alpha, int face)
  1365. {
  1366. m_host.AddScriptLPS(1);
  1367. SetAlpha(m_host, alpha, face);
  1368. }
  1369. public void llSetLinkAlpha(int linknumber, double alpha, int face)
  1370. {
  1371. m_host.AddScriptLPS(1);
  1372. List<SceneObjectPart> parts = GetLinkParts(linknumber);
  1373. foreach (SceneObjectPart part in parts)
  1374. SetAlpha(part, alpha, face);
  1375. }
  1376. protected void SetAlpha(SceneObjectPart part, double alpha, int face)
  1377. {
  1378. Primitive.TextureEntry tex = part.Shape.Textures;
  1379. Color4 texcolor;
  1380. if (face >= 0 && face < GetNumberOfSides(part))
  1381. {
  1382. texcolor = tex.CreateFace((uint)face).RGBA;
  1383. texcolor.A = Util.Clip((float)alpha, 0.0f, 1.0f);
  1384. tex.FaceTextures[face].RGBA = texcolor;
  1385. part.UpdateTexture(tex);
  1386. return;
  1387. }
  1388. else if (face == ScriptBaseClass.ALL_SIDES)
  1389. {
  1390. for (int i = 0; i < GetNumberOfSides(part); i++)
  1391. {
  1392. if (tex.FaceTextures[i] != null)
  1393. {
  1394. texcolor = tex.FaceTextures[i].RGBA;
  1395. texcolor.A = Util.Clip((float)alpha, 0.0f, 1.0f);
  1396. tex.FaceTextures[i].RGBA = texcolor;
  1397. }
  1398. }
  1399. texcolor = tex.DefaultTexture.RGBA;
  1400. texcolor.A = Util.Clip((float)alpha, 0.0f, 1.0f);
  1401. tex.DefaultTexture.RGBA = texcolor;
  1402. part.UpdateTexture(tex);
  1403. return;
  1404. }
  1405. }
  1406. /// <summary>
  1407. /// Set flexi parameters of a part.
  1408. ///
  1409. /// FIXME: Much of this code should probably be within the part itself.
  1410. /// </summary>
  1411. /// <param name="part"></param>
  1412. /// <param name="flexi"></param>
  1413. /// <param name="softness"></param>
  1414. /// <param name="gravity"></param>
  1415. /// <param name="friction"></param>
  1416. /// <param name="wind"></param>
  1417. /// <param name="tension"></param>
  1418. /// <param name="Force"></param>
  1419. protected void SetFlexi(SceneObjectPart part, bool flexi, int softness, float gravity, float friction,
  1420. float wind, float tension, LSL_Vector Force)
  1421. {
  1422. if (part == null)
  1423. return;
  1424. if (flexi)
  1425. {
  1426. part.Shape.FlexiEntry = true; // this setting flexi true isn't working, but the below parameters do
  1427. // work once the prim is already flexi
  1428. part.Shape.FlexiSoftness = softness;
  1429. part.Shape.FlexiGravity = gravity;
  1430. part.Shape.FlexiDrag = friction;
  1431. part.Shape.FlexiWind = wind;
  1432. part.Shape.FlexiTension = tension;
  1433. part.Shape.FlexiForceX = (float)Force.x;
  1434. part.Shape.FlexiForceY = (float)Force.y;
  1435. part.Shape.FlexiForceZ = (float)Force.z;
  1436. part.Shape.PathCurve = 0x80;
  1437. }
  1438. part.ParentGroup.HasGroupChanged = true;
  1439. part.ScheduleFullUpdate();
  1440. }
  1441. /// <summary>
  1442. /// Set a light point on a part
  1443. /// </summary>
  1444. /// FIXME: Much of this code should probably be in SceneObjectGroup
  1445. ///
  1446. /// <param name="part"></param>
  1447. /// <param name="light"></param>
  1448. /// <param name="color"></param>
  1449. /// <param name="intensity"></param>
  1450. /// <param name="radius"></param>
  1451. /// <param name="falloff"></param>
  1452. protected void SetPointLight(SceneObjectPart part, bool light, LSL_Vector color, float intensity, float radius, float falloff)
  1453. {
  1454. if (part == null)
  1455. return;
  1456. if (light)
  1457. {
  1458. part.Shape.LightEntry = true;
  1459. part.Shape.LightColorR = Util.Clip((float)color.x, 0.0f, 1.0f);
  1460. part.Shape.LightColorG = Util.Clip((float)color.y, 0.0f, 1.0f);
  1461. part.Shape.LightColorB = Util.Clip((float)color.z, 0.0f, 1.0f);
  1462. part.Shape.LightIntensity = intensity;
  1463. part.Shape.LightRadius = radius;
  1464. part.Shape.LightFalloff = falloff;
  1465. }
  1466. else
  1467. {
  1468. part.Shape.LightEntry = false;
  1469. }
  1470. part.ParentGroup.HasGroupChanged = true;
  1471. part.ScheduleFullUpdate();
  1472. }
  1473. public LSL_Vector llGetColor(int face)
  1474. {
  1475. m_host.AddScriptLPS(1);
  1476. return GetColor(m_host, face);
  1477. }
  1478. protected LSL_Vector GetColor(SceneObjectPart part, int face)
  1479. {
  1480. Primitive.TextureEntry tex = part.Shape.Textures;
  1481. Color4 texcolor;
  1482. LSL_Vector rgb = new LSL_Vector();
  1483. if (face == ScriptBaseClass.ALL_SIDES)
  1484. {
  1485. int i;
  1486. for (i = 0 ; i < GetNumberOfSides(part); i++)
  1487. {
  1488. texcolor = tex.GetFace((uint)i).RGBA;
  1489. rgb.x += texcolor.R;
  1490. rgb.y += texcolor.G;
  1491. rgb.z += texcolor.B;
  1492. }
  1493. rgb.x /= (float)GetNumberOfSides(part);
  1494. rgb.y /= (float)GetNumberOfSides(part);
  1495. rgb.z /= (float)GetNumberOfSides(part);
  1496. return rgb;
  1497. }
  1498. if (face >= 0 && face < GetNumberOfSides(part))
  1499. {
  1500. texcolor = tex.GetFace((uint)face).RGBA;
  1501. rgb.x = texcolor.R;
  1502. rgb.y = texcolor.G;
  1503. rgb.z = texcolor.B;
  1504. return rgb;
  1505. }
  1506. else
  1507. {
  1508. return new LSL_Vector();
  1509. }
  1510. }
  1511. public void llSetTexture(string texture, int face)
  1512. {
  1513. m_host.AddScriptLPS(1);
  1514. SetTexture(m_host, texture, face);
  1515. ScriptSleep(200);
  1516. }
  1517. public void llSetLinkTexture(int linknumber, string texture, int face)
  1518. {
  1519. m_host.AddScriptLPS(1);
  1520. List<SceneObjectPart> parts = GetLinkParts(linknumber);
  1521. foreach (SceneObjectPart part in parts)
  1522. SetTexture(part, texture, face);
  1523. ScriptSleep(200);
  1524. }
  1525. protected void SetTexture(SceneObjectPart part, string texture, int face)
  1526. {
  1527. UUID textureID=new UUID();
  1528. if (!UUID.TryParse(texture, out textureID))
  1529. {
  1530. textureID=InventoryKey(texture, (int)AssetType.Texture);
  1531. }
  1532. if (textureID == UUID.Zero)
  1533. return;
  1534. Primitive.TextureEntry tex = part.Shape.Textures;
  1535. if (face >= 0 && face < GetNumberOfSides(part))
  1536. {
  1537. Primitive.TextureEntryFace texface = tex.CreateFace((uint)face);
  1538. texface.TextureID = textureID;
  1539. tex.FaceTextures[face] = texface;
  1540. part.UpdateTexture(tex);
  1541. return;
  1542. }
  1543. else if (face == ScriptBaseClass.ALL_SIDES)
  1544. {
  1545. for (uint i = 0; i < GetNumberOfSides(part); i++)
  1546. {
  1547. if (tex.FaceTextures[i] != null)
  1548. {
  1549. tex.FaceTextures[i].TextureID = textureID;
  1550. }
  1551. }
  1552. tex.DefaultTexture.TextureID = textureID;
  1553. part.UpdateTexture(tex);
  1554. return;
  1555. }
  1556. }
  1557. public void llScaleTexture(double u, double v, int face)
  1558. {
  1559. m_host.AddScriptLPS(1);
  1560. ScaleTexture(m_host, u, v, face);
  1561. ScriptSleep(200);
  1562. }
  1563. protected void ScaleTexture(SceneObjectPart part, double u, double v, int face)
  1564. {
  1565. Primitive.TextureEntry tex = part.Shape.Textures;
  1566. if (face >= 0 && face < GetNumberOfSides(part))
  1567. {
  1568. Primitive.TextureEntryFace texface = tex.CreateFace((uint)face);
  1569. texface.RepeatU = (float)u;
  1570. texface.RepeatV = (float)v;
  1571. tex.FaceTextures[face] = texface;
  1572. part.UpdateTexture(tex);
  1573. return;
  1574. }
  1575. if (face == ScriptBaseClass.ALL_SIDES)
  1576. {
  1577. for (int i = 0; i < GetNumberOfSides(part); i++)
  1578. {
  1579. if (tex.FaceTextures[i] != null)
  1580. {
  1581. tex.FaceTextures[i].RepeatU = (float)u;
  1582. tex.FaceTextures[i].RepeatV = (float)v;
  1583. }
  1584. }
  1585. tex.DefaultTexture.RepeatU = (float)u;
  1586. tex.DefaultTexture.RepeatV = (float)v;
  1587. part.UpdateTexture(tex);
  1588. return;
  1589. }
  1590. }
  1591. public void llOffsetTexture(double u, double v, int face)
  1592. {
  1593. m_host.AddScriptLPS(1);
  1594. OffsetTexture(m_host, u, v, face);
  1595. ScriptSleep(200);
  1596. }
  1597. protected void OffsetTexture(SceneObjectPart part, double u, double v, int face)
  1598. {
  1599. Primitive.TextureEntry tex = part.Shape.Textures;
  1600. if (face >= 0 && face < GetNumberOfSides(part))
  1601. {
  1602. Primitive.TextureEntryFace texface = tex.CreateFace((uint)face);
  1603. texface.OffsetU = (float)u;
  1604. texface.OffsetV = (float)v;
  1605. tex.FaceTextures[face] = texface;
  1606. part.UpdateTexture(tex);
  1607. return;
  1608. }
  1609. if (face == ScriptBaseClass.ALL_SIDES)
  1610. {
  1611. for (int i = 0; i < GetNumberOfSides(part); i++)
  1612. {
  1613. if (tex.FaceTextures[i] != null)
  1614. {
  1615. tex.FaceTextures[i].OffsetU = (float)u;
  1616. tex.FaceTextures[i].OffsetV = (float)v;
  1617. }
  1618. }
  1619. tex.DefaultTexture.OffsetU = (float)u;
  1620. tex.DefaultTexture.OffsetV = (float)v;
  1621. part.UpdateTexture(tex);
  1622. return;
  1623. }
  1624. }
  1625. public void llRotateTexture(double rotation, int face)
  1626. {
  1627. m_host.AddScriptLPS(1);
  1628. RotateTexture(m_host, rotation, face);
  1629. ScriptSleep(200);
  1630. }
  1631. protected void RotateTexture(SceneObjectPart part, double rotation, int face)
  1632. {
  1633. Primitive.TextureEntry tex = part.Shape.Textures;
  1634. if (face >= 0 && face < GetNumberOfSides(part))
  1635. {
  1636. Primitive.TextureEntryFace texface = tex.CreateFace((uint)face);
  1637. texface.Rotation = (float)rotation;
  1638. tex.FaceTextures[face] = texface;
  1639. part.UpdateTexture(tex);
  1640. return;
  1641. }
  1642. if (face == ScriptBaseClass.ALL_SIDES)
  1643. {
  1644. for (int i = 0; i < GetNumberOfSides(part); i++)
  1645. {
  1646. if (tex.FaceTextures[i] != null)
  1647. {
  1648. tex.FaceTextures[i].Rotation = (float)rotation;
  1649. }
  1650. }
  1651. tex.DefaultTexture.Rotation = (float)rotation;
  1652. part.UpdateTexture(tex);
  1653. return;
  1654. }
  1655. }
  1656. public LSL_String llGetTexture(int face)
  1657. {
  1658. m_host.AddScriptLPS(1);
  1659. return GetTexture(m_host, face);
  1660. }
  1661. protected LSL_String GetTexture(SceneObjectPart part, int face)
  1662. {
  1663. Primitive.TextureEntry tex = part.Shape.Textures;
  1664. if (face == ScriptBaseClass.ALL_SIDES)
  1665. {
  1666. face = 0;
  1667. }
  1668. if (face >= 0 && face < GetNumberOfSides(part))
  1669. {
  1670. Primitive.TextureEntryFace texface;
  1671. texface = tex.GetFace((uint)face);
  1672. return texface.TextureID.ToString();
  1673. }
  1674. else
  1675. {
  1676. return String.Empty;
  1677. }
  1678. }
  1679. public void llSetPos(LSL_Vector pos)
  1680. {
  1681. m_host.AddScriptLPS(1);
  1682. SetPos(m_host, pos);
  1683. ScriptSleep(200);
  1684. }
  1685. // Capped movemment if distance > 10m (http://wiki.secondlife.com/wiki/LlSetPos)
  1686. // note linked setpos is capped "differently"
  1687. private LSL_Vector SetPosAdjust(LSL_Vector start, LSL_Vector end)
  1688. {
  1689. if (llVecDist(start, end) > 10.0f * m_ScriptDistanceFactor)
  1690. return start + m_ScriptDistanceFactor * 10.0f * llVecNorm(end - start);
  1691. else
  1692. return end;
  1693. }
  1694. protected void SetPos(SceneObjectPart part, LSL_Vector targetPos)
  1695. {
  1696. // Capped movemment if distance > 10m (http://wiki.secondlife.com/wiki/LlSetPos)
  1697. LSL_Vector currentPos = GetPartLocalPos(part);
  1698. float ground = World.GetGroundHeight((float)targetPos.x, (float)targetPos.y);
  1699. bool disable_underground_movement = m_ScriptEngine.Config.GetBoolean("DisableUndergroundMovement", true);
  1700. if (part.ParentGroup.RootPart == part)
  1701. {
  1702. if ((targetPos.z < ground) && disable_underground_movement && m_host.AttachmentPoint == 0)
  1703. targetPos.z = ground;
  1704. SceneObjectGroup parent = part.ParentGroup;
  1705. LSL_Vector real_vec = SetPosAdjust(currentPos, targetPos);
  1706. parent.UpdateGroupPosition(new Vector3((float)real_vec.x, (float)real_vec.y, (float)real_vec.z));
  1707. }
  1708. else
  1709. {
  1710. LSL_Vector rel_vec = SetPosAdjust(currentPos, targetPos);
  1711. part.OffsetPosition = new Vector3((float)rel_vec.x, (float)rel_vec.y, (float)rel_vec.z);
  1712. SceneObjectGroup parent = part.ParentGroup;
  1713. parent.HasGroupChanged = true;
  1714. parent.ScheduleGroupForTerseUpdate();
  1715. }
  1716. }
  1717. public LSL_Vector llGetPos()
  1718. {
  1719. m_host.AddScriptLPS(1);
  1720. Vector3 pos = m_host.GetWorldPosition();
  1721. return new LSL_Vector(pos.X, pos.Y, pos.Z);
  1722. }
  1723. public LSL_Vector llGetLocalPos()
  1724. {
  1725. m_host.AddScriptLPS(1);
  1726. return GetPartLocalPos(m_host);
  1727. }
  1728. protected LSL_Vector GetPartLocalPos(SceneObjectPart part)
  1729. {
  1730. m_host.AddScriptLPS(1);
  1731. if (part.ParentID == 0)
  1732. {
  1733. return new LSL_Vector(part.AbsolutePosition.X,
  1734. part.AbsolutePosition.Y,
  1735. part.AbsolutePosition.Z);
  1736. }
  1737. else
  1738. {
  1739. if (m_host.IsRoot)
  1740. {
  1741. return new LSL_Vector(m_host.AttachedPos.X,
  1742. m_host.AttachedPos.Y,
  1743. m_host.AttachedPos.Z);
  1744. }
  1745. else
  1746. {
  1747. return new LSL_Vector(part.OffsetPosition.X,
  1748. part.OffsetPosition.Y,
  1749. part.OffsetPosition.Z);
  1750. }
  1751. }
  1752. }
  1753. public void llSetRot(LSL_Rotation rot)
  1754. {
  1755. m_host.AddScriptLPS(1);
  1756. // try to let this work as in SL...
  1757. if (m_host.ParentID == 0)
  1758. {
  1759. // special case: If we are root, rotate complete SOG to new rotation
  1760. SetRot(m_host, Rot2Quaternion(rot));
  1761. }
  1762. else
  1763. {
  1764. // we are a child. The rotation values will be set to the one of root modified by rot, as in SL. Don't ask.
  1765. SceneObjectGroup group = m_host.ParentGroup;
  1766. if (group != null) // a bit paranoid, maybe
  1767. {
  1768. SceneObjectPart rootPart = group.RootPart;
  1769. if (rootPart != null) // again, better safe than sorry
  1770. {
  1771. SetRot(m_host, rootPart.RotationOffset * Rot2Quaternion(rot));
  1772. }
  1773. }
  1774. }
  1775. ScriptSleep(200);
  1776. }
  1777. public void llSetLocalRot(LSL_Rotation rot)
  1778. {
  1779. m_host.AddScriptLPS(1);
  1780. SetRot(m_host, Rot2Quaternion(rot));
  1781. ScriptSleep(200);
  1782. }
  1783. protected void SetRot(SceneObjectPart part, Quaternion rot)
  1784. {
  1785. part.UpdateRotation(rot);
  1786. // Update rotation does not move the object in the physics scene if it's a linkset.
  1787. //KF: Do NOT use this next line if using ODE physics engine. This need a switch based on .ini Phys Engine type
  1788. // part.ParentGroup.AbsolutePosition = part.ParentGroup.AbsolutePosition;
  1789. // So, after thinking about this for a bit, the issue with the part.ParentGroup.AbsolutePosition = part.ParentGroup.AbsolutePosition line
  1790. // is it isn't compatible with vehicles because it causes the vehicle body to have to be broken down and rebuilt
  1791. // It's perfectly okay when the object is not an active physical body though.
  1792. // So, part.ParentGroup.ResetChildPrimPhysicsPositions(); does the thing that Kitto is warning against
  1793. // but only if the object is not physial and active. This is important for rotating doors.
  1794. // without the absoluteposition = absoluteposition happening, the doors do not move in the physics
  1795. // scene
  1796. if (part.PhysActor != null && !part.PhysActor.IsPhysical)
  1797. {
  1798. part.ParentGroup.ResetChildPrimPhysicsPositions();
  1799. }
  1800. }
  1801. /// <summary>
  1802. /// See http://lslwiki.net/lslwiki/wakka.php?wakka=ChildRotation
  1803. /// </summary>
  1804. public LSL_Rotation llGetRot()
  1805. {
  1806. // unlinked or root prim then use llRootRotation
  1807. // see llRootRotaion for references.
  1808. if (m_host.LinkNum == 0 || m_host.LinkNum == 1)
  1809. {
  1810. return llGetRootRotation();
  1811. }
  1812. m_host.AddScriptLPS(1);
  1813. Quaternion q = m_host.GetWorldRotation();
  1814. return new LSL_Rotation(q.X, q.Y, q.Z, q.W);
  1815. }
  1816. private LSL_Rotation GetPartRot(SceneObjectPart part)
  1817. {
  1818. Quaternion q;
  1819. if (part.LinkNum == 0 || part.LinkNum == 1) // unlinked or root prim
  1820. {
  1821. if (part.ParentGroup.RootPart.AttachmentPoint != 0)
  1822. {
  1823. ScenePresence avatar = World.GetScenePresence(part.AttachedAvatar);
  1824. if (avatar != null)
  1825. {
  1826. if ((avatar.AgentControlFlags & (uint)AgentManager.ControlFlags.AGENT_CONTROL_MOUSELOOK) != 0)
  1827. q = avatar.CameraRotation; // Mouselook
  1828. else
  1829. q = avatar.Rotation; // Currently infrequently updated so may be inaccurate
  1830. }
  1831. else
  1832. q = part.ParentGroup.GroupRotation; // Likely never get here but just in case
  1833. }
  1834. else
  1835. q = part.ParentGroup.GroupRotation; // just the group rotation
  1836. return new LSL_Rotation(q.X, q.Y, q.Z, q.W);
  1837. }
  1838. q = part.GetWorldRotation();
  1839. return new LSL_Rotation(q.X, q.Y, q.Z, q.W);
  1840. }
  1841. public LSL_Rotation llGetLocalRot()
  1842. {
  1843. m_host.AddScriptLPS(1);
  1844. return new LSL_Rotation(m_host.RotationOffset.X, m_host.RotationOffset.Y, m_host.RotationOffset.Z, m_host.RotationOffset.W);
  1845. }
  1846. public void llSetForce(LSL_Vector force, int local)
  1847. {
  1848. m_host.AddScriptLPS(1);
  1849. if (m_host.ParentGroup != null)
  1850. {
  1851. if (!m_host.ParentGroup.IsDeleted)
  1852. {
  1853. if (local != 0)
  1854. force *= llGetRot();
  1855. m_host.ParentGroup.RootPart.SetForce(new Vector3((float)force.x, (float)force.y, (float)force.z));
  1856. }
  1857. }
  1858. }
  1859. public LSL_Vector llGetForce()
  1860. {
  1861. LSL_Vector force = new LSL_Vector(0.0, 0.0, 0.0);
  1862. m_host.AddScriptLPS(1);
  1863. if (m_host.ParentGroup != null)
  1864. {
  1865. if (!m_host.ParentGroup.IsDeleted)
  1866. {
  1867. Vector3 tmpForce = m_host.ParentGroup.RootPart.GetForce();
  1868. force.x = tmpForce.X;
  1869. force.y = tmpForce.Y;
  1870. force.z = tmpForce.Z;
  1871. }
  1872. }
  1873. return force;
  1874. }
  1875. public LSL_Integer llTarget(LSL_Vector position, double range)
  1876. {
  1877. m_host.AddScriptLPS(1);
  1878. return m_host.registerTargetWaypoint(new Vector3((float)position.x, (float)position.y, (float)position.z), (float)range);
  1879. }
  1880. public void llTargetRemove(int number)
  1881. {
  1882. m_host.AddScriptLPS(1);
  1883. m_host.unregisterTargetWaypoint(number);
  1884. }
  1885. public LSL_Integer llRotTarget(LSL_Rotation rot, double error)
  1886. {
  1887. m_host.AddScriptLPS(1);
  1888. return m_host.registerRotTargetWaypoint(new Quaternion((float)rot.x, (float)rot.y, (float)rot.z, (float)rot.s), (float)error);
  1889. }
  1890. public void llRotTargetRemove(int number)
  1891. {
  1892. m_host.AddScriptLPS(1);
  1893. m_host.unregisterRotTargetWaypoint(number);
  1894. }
  1895. public void llMoveToTarget(LSL_Vector target, double tau)
  1896. {
  1897. m_host.AddScriptLPS(1);
  1898. m_host.MoveToTarget(new Vector3((float)target.x, (float)target.y, (float)target.z), (float)tau);
  1899. }
  1900. public void llStopMoveToTarget()
  1901. {
  1902. m_host.AddScriptLPS(1);
  1903. m_host.StopMoveToTarget();
  1904. }
  1905. public void llApplyImpulse(LSL_Vector force, int local)
  1906. {
  1907. m_host.AddScriptLPS(1);
  1908. //No energy force yet
  1909. Vector3 v = new Vector3((float)force.x, (float)force.y, (float)force.z);
  1910. if (v.Length() > 20000.0f)
  1911. {
  1912. v.Normalize();
  1913. v = v * 20000.0f;
  1914. }
  1915. m_host.ApplyImpulse(v, local != 0);
  1916. }
  1917. public void llApplyRotationalImpulse(LSL_Vector force, int local)
  1918. {
  1919. m_host.AddScriptLPS(1);
  1920. m_host.ApplyAngularImpulse(new Vector3((float)force.x, (float)force.y, (float)force.z), local != 0);
  1921. }
  1922. public void llSetTorque(LSL_Vector torque, int local)
  1923. {
  1924. m_host.AddScriptLPS(1);
  1925. m_host.SetAngularImpulse(new Vector3((float)torque.x, (float)torque.y, (float)torque.z), local != 0);
  1926. }
  1927. public LSL_Vector llGetTorque()
  1928. {
  1929. m_host.AddScriptLPS(1);
  1930. Vector3 torque = m_host.GetTorque();
  1931. return new LSL_Vector(torque.X,torque.Y,torque.Z);
  1932. }
  1933. public void llSetForceAndTorque(LSL_Vector force, LSL_Vector torque, int local)
  1934. {
  1935. m_host.AddScriptLPS(1);
  1936. llSetForce(force, local);
  1937. llSetTorque(torque, local);
  1938. }
  1939. public LSL_Vector llGetVel()
  1940. {
  1941. m_host.AddScriptLPS(1);
  1942. return new LSL_Vector(m_host.Velocity.X, m_host.Velocity.Y, m_host.Velocity.Z);
  1943. }
  1944. public LSL_Vector llGetAccel()
  1945. {
  1946. m_host.AddScriptLPS(1);
  1947. return new LSL_Vector(m_host.Acceleration.X, m_host.Acceleration.Y, m_host.Acceleration.Z);
  1948. }
  1949. public LSL_Vector llGetOmega()
  1950. {
  1951. m_host.AddScriptLPS(1);
  1952. return new LSL_Vector(m_host.AngularVelocity.X, m_host.AngularVelocity.Y, m_host.AngularVelocity.Z);
  1953. }
  1954. public LSL_Float llGetTimeOfDay()
  1955. {
  1956. m_host.AddScriptLPS(1);
  1957. return (double)((DateTime.Now.TimeOfDay.TotalMilliseconds / 1000) % (3600 * 4));
  1958. }
  1959. public LSL_Float llGetWallclock()
  1960. {
  1961. m_host.AddScriptLPS(1);
  1962. return DateTime.Now.TimeOfDay.TotalSeconds;
  1963. }
  1964. public LSL_Float llGetTime()
  1965. {
  1966. m_host.AddScriptLPS(1);
  1967. TimeSpan ScriptTime = DateTime.Now - m_timer;
  1968. return (double)(ScriptTime.TotalMilliseconds / 1000);
  1969. }
  1970. public void llResetTime()
  1971. {
  1972. m_host.AddScriptLPS(1);
  1973. m_timer = DateTime.Now;
  1974. }
  1975. public LSL_Float llGetAndResetTime()
  1976. {
  1977. m_host.AddScriptLPS(1);
  1978. TimeSpan ScriptTime = DateTime.Now - m_timer;
  1979. m_timer = DateTime.Now;
  1980. return (double)(ScriptTime.TotalMilliseconds / 1000);
  1981. }
  1982. public void llSound(string sound, double volume, int queue, int loop)
  1983. {
  1984. m_host.AddScriptLPS(1);
  1985. // This function has been deprecated
  1986. // see http://www.lslwiki.net/lslwiki/wakka.php?wakka=llSound
  1987. Deprecated("llSound");
  1988. }
  1989. // Xantor 20080528 PlaySound updated so it accepts an objectinventory name -or- a key to a sound
  1990. // 20080530 Updated to remove code duplication
  1991. public void llPlaySound(string sound, double volume)
  1992. {
  1993. m_host.AddScriptLPS(1);
  1994. // send the sound, once, to all clients in range
  1995. m_host.SendSound(KeyOrName(sound).ToString(), volume, false, 0, 0, false, false);
  1996. }
  1997. // Xantor 20080528 we should do this differently.
  1998. // 1) apply the sound to the object
  1999. // 2) schedule full update
  2000. // just sending the sound out once doesn't work so well when other avatars come in view later on
  2001. // or when the prim gets moved, changed, sat on, whatever
  2002. // see large number of mantises (mantes?)
  2003. // 20080530 Updated to remove code duplication
  2004. // 20080530 Stop sound if there is one, otherwise volume only changes don't work
  2005. public void llLoopSound(string sound, double volume)
  2006. {
  2007. m_host.AddScriptLPS(1);
  2008. if (m_host.Sound != UUID.Zero)
  2009. llStopSound();
  2010. m_host.Sound = KeyOrName(sound);
  2011. m_host.SoundGain = volume;
  2012. m_host.SoundFlags = 1; // looping
  2013. m_host.SoundRadius = 20; // Magic number, 20 seems reasonable. Make configurable?
  2014. m_host.ScheduleFullUpdate();
  2015. m_host.SendFullUpdateToAllClients();
  2016. }
  2017. public void llLoopSoundMaster(string sound, double volume)
  2018. {
  2019. m_host.AddScriptLPS(1);
  2020. m_host.ParentGroup.LoopSoundMasterPrim = m_host;
  2021. lock (m_host.ParentGroup.LoopSoundSlavePrims)
  2022. {
  2023. foreach (SceneObjectPart prim in m_host.ParentGroup.LoopSoundSlavePrims)
  2024. {
  2025. if (prim.Sound != UUID.Zero)
  2026. llStopSound();
  2027. prim.Sound = KeyOrName(sound);
  2028. prim.SoundGain = volume;
  2029. prim.SoundFlags = 1; // looping
  2030. prim.SoundRadius = 20; // Magic number, 20 seems reasonable. Make configurable?
  2031. prim.ScheduleFullUpdate();
  2032. prim.SendFullUpdateToAllClients();
  2033. }
  2034. }
  2035. if (m_host.Sound != UUID.Zero)
  2036. llStopSound();
  2037. m_host.Sound = KeyOrName(sound);
  2038. m_host.SoundGain = volume;
  2039. m_host.SoundFlags = 1; // looping
  2040. m_host.SoundRadius = 20; // Magic number, 20 seems reasonable. Make configurable?
  2041. m_host.ScheduleFullUpdate();
  2042. m_host.SendFullUpdateToAllClients();
  2043. }
  2044. public void llLoopSoundSlave(string sound, double volume)
  2045. {
  2046. m_host.AddScriptLPS(1);
  2047. lock (m_host.ParentGroup.LoopSoundSlavePrims)
  2048. {
  2049. m_host.ParentGroup.LoopSoundSlavePrims.Add(m_host);
  2050. }
  2051. }
  2052. public void llPlaySoundSlave(string sound, double volume)
  2053. {
  2054. m_host.AddScriptLPS(1);
  2055. // send the sound, once, to all clients in range
  2056. m_host.SendSound(KeyOrName(sound).ToString(), volume, false, 0, 0, true, false);
  2057. }
  2058. public void llTriggerSound(string sound, double volume)
  2059. {
  2060. m_host.AddScriptLPS(1);
  2061. // send the sound, once, to all clients in range
  2062. m_host.SendSound(KeyOrName(sound).ToString(), volume, true, 0, 0, false, false);
  2063. }
  2064. // Xantor 20080528: Clear prim data of sound instead
  2065. public void llStopSound()
  2066. {
  2067. m_host.AddScriptLPS(1);
  2068. if (m_host.ParentGroup.LoopSoundSlavePrims.Contains(m_host))
  2069. {
  2070. if (m_host.ParentGroup.LoopSoundMasterPrim == m_host)
  2071. {
  2072. foreach (SceneObjectPart part in m_host.ParentGroup.LoopSoundSlavePrims)
  2073. {
  2074. part.Sound = UUID.Zero;
  2075. part.SoundGain = 0;
  2076. part.SoundFlags = 0;
  2077. part.SoundRadius = 0;
  2078. part.ScheduleFullUpdate();
  2079. part.SendFullUpdateToAllClients();
  2080. }
  2081. m_host.ParentGroup.LoopSoundMasterPrim = null;
  2082. m_host.ParentGroup.LoopSoundSlavePrims.Clear();
  2083. }
  2084. else
  2085. {
  2086. m_host.Sound = UUID.Zero;
  2087. m_host.SoundGain = 0;
  2088. m_host.SoundFlags = 0;
  2089. m_host.SoundRadius = 0;
  2090. m_host.ScheduleFullUpdate();
  2091. m_host.SendFullUpdateToAllClients();
  2092. }
  2093. }
  2094. else
  2095. {
  2096. m_host.Sound = UUID.Zero;
  2097. m_host.SoundGain = 0;
  2098. m_host.SoundFlags = 0;
  2099. m_host.SoundRadius = 0;
  2100. m_host.ScheduleFullUpdate();
  2101. m_host.SendFullUpdateToAllClients();
  2102. }
  2103. }
  2104. public void llPreloadSound(string sound)
  2105. {
  2106. m_host.AddScriptLPS(1);
  2107. m_host.PreloadSound(sound);
  2108. ScriptSleep(1000);
  2109. }
  2110. /// <summary>
  2111. /// Return a portion of the designated string bounded by
  2112. /// inclusive indices (start and end). As usual, the negative
  2113. /// indices, and the tolerance for out-of-bound values, makes
  2114. /// this more complicated than it might otherwise seem.
  2115. /// </summary>
  2116. public LSL_String llGetSubString(string src, int start, int end)
  2117. {
  2118. m_host.AddScriptLPS(1);
  2119. // Normalize indices (if negative).
  2120. // After normlaization they may still be
  2121. // negative, but that is now relative to
  2122. // the start, rather than the end, of the
  2123. // sequence.
  2124. if (start < 0)
  2125. {
  2126. start = src.Length+start;
  2127. }
  2128. if (end < 0)
  2129. {
  2130. end = src.Length+end;
  2131. }
  2132. // Conventional substring
  2133. if (start <= end)
  2134. {
  2135. // Implies both bounds are out-of-range.
  2136. if (end < 0 || start >= src.Length)
  2137. {
  2138. return String.Empty;
  2139. }
  2140. // If end is positive, then it directly
  2141. // corresponds to the lengt of the substring
  2142. // needed (plus one of course). BUT, it
  2143. // must be within bounds.
  2144. if (end >= src.Length)
  2145. {
  2146. end = src.Length-1;
  2147. }
  2148. if (start < 0)
  2149. {
  2150. return src.Substring(0,end+1);
  2151. }
  2152. // Both indices are positive
  2153. return src.Substring(start, (end+1) - start);
  2154. }
  2155. // Inverted substring (end < start)
  2156. else
  2157. {
  2158. // Implies both indices are below the
  2159. // lower bound. In the inverted case, that
  2160. // means the entire string will be returned
  2161. // unchanged.
  2162. if (start < 0)
  2163. {
  2164. return src;
  2165. }
  2166. // If both indices are greater than the upper
  2167. // bound the result may seem initially counter
  2168. // intuitive.
  2169. if (end >= src.Length)
  2170. {
  2171. return src;
  2172. }
  2173. if (end < 0)
  2174. {
  2175. if (start < src.Length)
  2176. {
  2177. return src.Substring(start);
  2178. }
  2179. else
  2180. {
  2181. return String.Empty;
  2182. }
  2183. }
  2184. else
  2185. {
  2186. if (start < src.Length)
  2187. {
  2188. return src.Substring(0,end+1) + src.Substring(start);
  2189. }
  2190. else
  2191. {
  2192. return src.Substring(0,end+1);
  2193. }
  2194. }
  2195. }
  2196. }
  2197. /// <summary>
  2198. /// Delete substring removes the specified substring bounded
  2199. /// by the inclusive indices start and end. Indices may be
  2200. /// negative (indicating end-relative) and may be inverted,
  2201. /// i.e. end < start.
  2202. /// </summary>
  2203. public LSL_String llDeleteSubString(string src, int start, int end)
  2204. {
  2205. m_host.AddScriptLPS(1);
  2206. // Normalize indices (if negative).
  2207. // After normlaization they may still be
  2208. // negative, but that is now relative to
  2209. // the start, rather than the end, of the
  2210. // sequence.
  2211. if (start < 0)
  2212. {
  2213. start = src.Length+start;
  2214. }
  2215. if (end < 0)
  2216. {
  2217. end = src.Length+end;
  2218. }
  2219. // Conventionally delimited substring
  2220. if (start <= end)
  2221. {
  2222. // If both bounds are outside of the existing
  2223. // string, then return unchanges.
  2224. if (end < 0 || start >= src.Length)
  2225. {
  2226. return src;
  2227. }
  2228. // At least one bound is in-range, so we
  2229. // need to clip the out-of-bound argument.
  2230. if (start < 0)
  2231. {
  2232. start = 0;
  2233. }
  2234. if (end >= src.Length)
  2235. {
  2236. end = src.Length-1;
  2237. }
  2238. return src.Remove(start,end-start+1);
  2239. }
  2240. // Inverted substring
  2241. else
  2242. {
  2243. // In this case, out of bounds means that
  2244. // the existing string is part of the cut.
  2245. if (start < 0 || end >= src.Length)
  2246. {
  2247. return String.Empty;
  2248. }
  2249. if (end > 0)
  2250. {
  2251. if (start < src.Length)
  2252. {
  2253. return src.Remove(start).Remove(0,end+1);
  2254. }
  2255. else
  2256. {
  2257. return src.Remove(0,end+1);
  2258. }
  2259. }
  2260. else
  2261. {
  2262. if (start < src.Length)
  2263. {
  2264. return src.Remove(start);
  2265. }
  2266. else
  2267. {
  2268. return src;
  2269. }
  2270. }
  2271. }
  2272. }
  2273. /// <summary>
  2274. /// Insert string inserts the specified string identified by src
  2275. /// at the index indicated by index. Index may be negative, in
  2276. /// which case it is end-relative. The index may exceed either
  2277. /// string bound, with the result being a concatenation.
  2278. /// </summary>
  2279. public LSL_String llInsertString(string dest, int index, string src)
  2280. {
  2281. m_host.AddScriptLPS(1);
  2282. // Normalize indices (if negative).
  2283. // After normlaization they may still be
  2284. // negative, but that is now relative to
  2285. // the start, rather than the end, of the
  2286. // sequence.
  2287. if (index < 0)
  2288. {
  2289. index = dest.Length+index;
  2290. // Negative now means it is less than the lower
  2291. // bound of the string.
  2292. if (index < 0)
  2293. {
  2294. return src+dest;
  2295. }
  2296. }
  2297. if (index >= dest.Length)
  2298. {
  2299. return dest+src;
  2300. }
  2301. // The index is in bounds.
  2302. // In this case the index refers to the index that will
  2303. // be assigned to the first character of the inserted string.
  2304. // So unlike the other string operations, we do not add one
  2305. // to get the correct string length.
  2306. return dest.Substring(0,index)+src+dest.Substring(index);
  2307. }
  2308. public LSL_String llToUpper(string src)
  2309. {
  2310. m_host.AddScriptLPS(1);
  2311. return src.ToUpper();
  2312. }
  2313. public LSL_String llToLower(string src)
  2314. {
  2315. m_host.AddScriptLPS(1);
  2316. return src.ToLower();
  2317. }
  2318. public LSL_Integer llGiveMoney(string destination, int amount)
  2319. {
  2320. UUID invItemID=InventorySelf();
  2321. if (invItemID == UUID.Zero)
  2322. return 0;
  2323. m_host.AddScriptLPS(1);
  2324. TaskInventoryItem item = m_host.TaskInventory[invItemID];
  2325. lock (m_host.TaskInventory)
  2326. {
  2327. item = m_host.TaskInventory[invItemID];
  2328. }
  2329. if (item.PermsGranter == UUID.Zero)
  2330. return 0;
  2331. if ((item.PermsMask & ScriptBaseClass.PERMISSION_DEBIT) == 0)
  2332. {
  2333. LSLError("No permissions to give money");
  2334. return 0;
  2335. }
  2336. UUID toID = new UUID();
  2337. if (!UUID.TryParse(destination, out toID))
  2338. {
  2339. LSLError("Bad key in llGiveMoney");
  2340. return 0;
  2341. }
  2342. IMoneyModule money = World.RequestModuleInterface<IMoneyModule>();
  2343. if (money == null)
  2344. {
  2345. NotImplemented("llGiveMoney");
  2346. return 0;
  2347. }
  2348. bool result = money.ObjectGiveMoney(
  2349. m_host.ParentGroup.RootPart.UUID, m_host.ParentGroup.RootPart.OwnerID, toID, amount);
  2350. if (result)
  2351. return 1;
  2352. return 0;
  2353. }
  2354. public void llMakeExplosion(int particles, double scale, double vel, double lifetime, double arc, string texture, LSL_Vector offset)
  2355. {
  2356. m_host.AddScriptLPS(1);
  2357. Deprecated("llMakeExplosion");
  2358. ScriptSleep(100);
  2359. }
  2360. public void llMakeFountain(int particles, double scale, double vel, double lifetime, double arc, int bounce, string texture, LSL_Vector offset, double bounce_offset)
  2361. {
  2362. m_host.AddScriptLPS(1);
  2363. Deprecated("llMakeFountain");
  2364. ScriptSleep(100);
  2365. }
  2366. public void llMakeSmoke(int particles, double scale, double vel, double lifetime, double arc, string texture, LSL_Vector offset)
  2367. {
  2368. m_host.AddScriptLPS(1);
  2369. Deprecated("llMakeSmoke");
  2370. ScriptSleep(100);
  2371. }
  2372. public void llMakeFire(int particles, double scale, double vel, double lifetime, double arc, string texture, LSL_Vector offset)
  2373. {
  2374. m_host.AddScriptLPS(1);
  2375. Deprecated("llMakeFire");
  2376. ScriptSleep(100);
  2377. }
  2378. public void llRezAtRoot(string inventory, LSL_Vector pos, LSL_Vector vel, LSL_Rotation rot, int param)
  2379. {
  2380. m_host.AddScriptLPS(1);
  2381. if (Double.IsNaN(rot.x) || Double.IsNaN(rot.y) || Double.IsNaN(rot.z) || Double.IsNaN(rot.s))
  2382. return;
  2383. float dist = (float)llVecDist(llGetPos(), pos);
  2384. if (dist > m_ScriptDistanceFactor * 10.0f)
  2385. return;
  2386. TaskInventoryDictionary partInventory = (TaskInventoryDictionary)m_host.TaskInventory.Clone();
  2387. foreach (KeyValuePair<UUID, TaskInventoryItem> inv in partInventory)
  2388. {
  2389. if (inv.Value.Name == inventory)
  2390. {
  2391. // make sure we're an object.
  2392. if (inv.Value.InvType != (int)InventoryType.Object)
  2393. {
  2394. llSay(0, "Unable to create requested object. Object is missing from database.");
  2395. return;
  2396. }
  2397. Vector3 llpos = new Vector3((float)pos.x, (float)pos.y, (float)pos.z);
  2398. Vector3 llvel = new Vector3((float)vel.x, (float)vel.y, (float)vel.z);
  2399. // need the magnitude later
  2400. float velmag = (float)Util.GetMagnitude(llvel);
  2401. SceneObjectGroup new_group = World.RezObject(m_host, inv.Value, llpos, Rot2Quaternion(rot), llvel, param);
  2402. // If either of these are null, then there was an unknown error.
  2403. if (new_group == null)
  2404. continue;
  2405. if (new_group.RootPart == null)
  2406. continue;
  2407. // objects rezzed with this method are die_at_edge by default.
  2408. new_group.RootPart.SetDieAtEdge(true);
  2409. new_group.ResumeScripts();
  2410. m_ScriptEngine.PostObjectEvent(m_host.LocalId, new EventParams(
  2411. "object_rez", new Object[] {
  2412. new LSL_String(
  2413. new_group.RootPart.UUID.ToString()) },
  2414. new DetectParams[0]));
  2415. float groupmass = new_group.GetMass();
  2416. if (new_group.RootPart.PhysActor != null && new_group.RootPart.PhysActor.IsPhysical && llvel != Vector3.Zero)
  2417. {
  2418. //Recoil.
  2419. llApplyImpulse(new LSL_Vector(llvel.X * groupmass, llvel.Y * groupmass, llvel.Z * groupmass), 0);
  2420. }
  2421. // Variable script delay? (see (http://wiki.secondlife.com/wiki/LSL_Delay)
  2422. ScriptSleep((int)((groupmass * velmag) / 10));
  2423. ScriptSleep(100);
  2424. return;
  2425. }
  2426. }
  2427. llSay(0, "Could not find object " + inventory);
  2428. }
  2429. public void llRezObject(string inventory, LSL_Vector pos, LSL_Vector vel, LSL_Rotation rot, int param)
  2430. {
  2431. llRezAtRoot(inventory, pos, vel, rot, param);
  2432. }
  2433. public void llLookAt(LSL_Vector target, double strength, double damping)
  2434. {
  2435. m_host.AddScriptLPS(1);
  2436. // Determine where we are looking from
  2437. LSL_Vector from = llGetPos();
  2438. // Work out the normalised vector from the source to the target
  2439. LSL_Vector delta = llVecNorm(target - from);
  2440. LSL_Vector angle = new LSL_Vector(0,0,0);
  2441. // Calculate the yaw
  2442. // subtracting PI_BY_TWO is required to compensate for the odd SL co-ordinate system
  2443. angle.x = llAtan2(delta.z, delta.y) - ScriptBaseClass.PI_BY_TWO;
  2444. // Calculate pitch
  2445. angle.y = llAtan2(delta.x, llSqrt((delta.y * delta.y) + (delta.z * delta.z)));
  2446. // we need to convert from a vector describing
  2447. // the angles of rotation in radians into rotation value
  2448. LSL_Types.Quaternion rot = llEuler2Rot(angle);
  2449. Quaternion rotation = new Quaternion((float)rot.x, (float)rot.y, (float)rot.z, (float)rot.s);
  2450. m_host.startLookAt(rotation, (float)damping, (float)strength);
  2451. // Orient the object to the angle calculated
  2452. //llSetRot(rot);
  2453. }
  2454. public void llStopLookAt()
  2455. {
  2456. m_host.AddScriptLPS(1);
  2457. // NotImplemented("llStopLookAt");
  2458. m_host.StopLookAt();
  2459. }
  2460. public void llSetTimerEvent(double sec)
  2461. {
  2462. if (sec != 0.0 && sec < m_MinTimerInterval)
  2463. sec = m_MinTimerInterval;
  2464. m_host.AddScriptLPS(1);
  2465. // Setting timer repeat
  2466. AsyncCommands.TimerPlugin.SetTimerEvent(m_localID, m_itemID, sec);
  2467. }
  2468. public virtual void llSleep(double sec)
  2469. {
  2470. m_host.AddScriptLPS(1);
  2471. Thread.Sleep((int)(sec * 1000));
  2472. }
  2473. public LSL_Float llGetMass()
  2474. {
  2475. m_host.AddScriptLPS(1);
  2476. return m_host.GetMass();
  2477. }
  2478. public void llCollisionFilter(string name, string id, int accept)
  2479. {
  2480. m_host.AddScriptLPS(1);
  2481. m_host.CollisionFilter.Clear();
  2482. if (id != null)
  2483. {
  2484. m_host.CollisionFilter.Add(accept,id);
  2485. }
  2486. else
  2487. {
  2488. m_host.CollisionFilter.Add(accept,name);
  2489. }
  2490. }
  2491. public void llTakeControls(int controls, int accept, int pass_on)
  2492. {
  2493. TaskInventoryItem item;
  2494. lock (m_host.TaskInventory)
  2495. {
  2496. if (!m_host.TaskInventory.ContainsKey(InventorySelf()))
  2497. return;
  2498. else
  2499. item = m_host.TaskInventory[InventorySelf()];
  2500. }
  2501. if (item.PermsGranter != UUID.Zero)
  2502. {
  2503. ScenePresence presence = World.GetScenePresence(item.PermsGranter);
  2504. if (presence != null)
  2505. {
  2506. if ((item.PermsMask & ScriptBaseClass.PERMISSION_TAKE_CONTROLS) != 0)
  2507. {
  2508. presence.RegisterControlEventsToScript(controls, accept, pass_on, m_localID, m_itemID);
  2509. }
  2510. }
  2511. }
  2512. m_host.AddScriptLPS(1);
  2513. }
  2514. public void llReleaseControls()
  2515. {
  2516. TaskInventoryItem item;
  2517. lock (m_host.TaskInventory)
  2518. {
  2519. if (!m_host.TaskInventory.ContainsKey(InventorySelf()))
  2520. return;
  2521. else
  2522. item = m_host.TaskInventory[InventorySelf()];
  2523. }
  2524. m_host.AddScriptLPS(1);
  2525. if (item.PermsGranter != UUID.Zero)
  2526. {
  2527. ScenePresence presence = World.GetScenePresence(item.PermsGranter);
  2528. if (presence != null)
  2529. {
  2530. if ((item.PermsMask & ScriptBaseClass.PERMISSION_TAKE_CONTROLS) != 0)
  2531. {
  2532. // Unregister controls from Presence
  2533. presence.UnRegisterControlEventsToScript(m_localID, m_itemID);
  2534. // Remove Take Control permission.
  2535. item.PermsMask &= ~ScriptBaseClass.PERMISSION_TAKE_CONTROLS;
  2536. }
  2537. }
  2538. }
  2539. }
  2540. public void llReleaseURL(string url)
  2541. {
  2542. m_host.AddScriptLPS(1);
  2543. if (m_UrlModule != null)
  2544. m_UrlModule.ReleaseURL(url);
  2545. }
  2546. public void llAttachToAvatar(int attachment)
  2547. {
  2548. m_host.AddScriptLPS(1);
  2549. if (m_host.ParentGroup.RootPart.AttachmentPoint == 0)
  2550. return;
  2551. TaskInventoryItem item;
  2552. lock (m_host.TaskInventory)
  2553. {
  2554. if (!m_host.TaskInventory.ContainsKey(InventorySelf()))
  2555. return;
  2556. else
  2557. item = m_host.TaskInventory[InventorySelf()];
  2558. }
  2559. if (item.PermsGranter != m_host.OwnerID)
  2560. return;
  2561. if ((item.PermsMask & ScriptBaseClass.PERMISSION_ATTACH) != 0)
  2562. {
  2563. SceneObjectGroup grp = m_host.ParentGroup;
  2564. ScenePresence presence = World.GetScenePresence(m_host.OwnerID);
  2565. IAttachmentsModule attachmentsModule = m_ScriptEngine.World.AttachmentsModule;
  2566. if (attachmentsModule != null)
  2567. attachmentsModule.AttachObject(presence.ControllingClient,
  2568. grp, (uint)attachment, false);
  2569. }
  2570. }
  2571. public void llDetachFromAvatar()
  2572. {
  2573. m_host.AddScriptLPS(1);
  2574. if (m_host.ParentGroup.RootPart.AttachmentPoint == 0)
  2575. return;
  2576. TaskInventoryItem item;
  2577. lock (m_host.TaskInventory)
  2578. {
  2579. if (!m_host.TaskInventory.ContainsKey(InventorySelf()))
  2580. return;
  2581. else
  2582. item = m_host.TaskInventory[InventorySelf()];
  2583. }
  2584. if (item.PermsGranter != m_host.OwnerID)
  2585. return;
  2586. if ((item.PermsMask & ScriptBaseClass.PERMISSION_ATTACH) != 0)
  2587. {
  2588. IAttachmentsModule attachmentsModule = m_ScriptEngine.World.AttachmentsModule;
  2589. if (attachmentsModule != null)
  2590. Util.FireAndForget(DetachWrapper, m_host);
  2591. }
  2592. }
  2593. private void DetachWrapper(object o)
  2594. {
  2595. SceneObjectPart host = (SceneObjectPart)o;
  2596. SceneObjectGroup grp = host.ParentGroup;
  2597. UUID itemID = grp.GetFromItemID();
  2598. ScenePresence presence = World.GetScenePresence(host.OwnerID);
  2599. IAttachmentsModule attachmentsModule = m_ScriptEngine.World.AttachmentsModule;
  2600. if (attachmentsModule != null)
  2601. attachmentsModule.ShowDetachInUserInventory(itemID, presence.ControllingClient);
  2602. }
  2603. public void llTakeCamera(string avatar)
  2604. {
  2605. m_host.AddScriptLPS(1);
  2606. Deprecated("llTakeCamera");
  2607. }
  2608. public void llReleaseCamera(string avatar)
  2609. {
  2610. m_host.AddScriptLPS(1);
  2611. Deprecated("llReleaseCamera");
  2612. }
  2613. public LSL_String llGetOwner()
  2614. {
  2615. m_host.AddScriptLPS(1);
  2616. return m_host.OwnerID.ToString();
  2617. }
  2618. public void llInstantMessage(string user, string message)
  2619. {
  2620. m_host.AddScriptLPS(1);
  2621. // We may be able to use ClientView.SendInstantMessage here, but we need a client instance.
  2622. // InstantMessageModule.OnInstantMessage searches through a list of scenes for a client matching the toAgent,
  2623. // but I don't think we have a list of scenes available from here.
  2624. // (We also don't want to duplicate the code in OnInstantMessage if we can avoid it.)
  2625. // user is a UUID
  2626. // TODO: figure out values for client, fromSession, and imSessionID
  2627. // client.SendInstantMessage(m_host.UUID, fromSession, message, user, imSessionID, m_host.Name, AgentManager.InstantMessageDialog.MessageFromAgent, (uint)Util.UnixTimeSinceEpoch());
  2628. UUID friendTransactionID = UUID.Random();
  2629. //m_pendingFriendRequests.Add(friendTransactionID, fromAgentID);
  2630. GridInstantMessage msg = new GridInstantMessage();
  2631. msg.fromAgentID = new Guid(m_host.UUID.ToString()); // fromAgentID.Guid;
  2632. msg.toAgentID = new Guid(user); // toAgentID.Guid;
  2633. msg.imSessionID = new Guid(friendTransactionID.ToString()); // This is the item we're mucking with here
  2634. // m_log.Debug("[Scripting IM]: From:" + msg.fromAgentID.ToString() + " To: " + msg.toAgentID.ToString() + " Session:" + msg.imSessionID.ToString() + " Message:" + message);
  2635. // m_log.Debug("[Scripting IM]: Filling Session: " + msg.imSessionID.ToString());
  2636. msg.timestamp = (uint)Util.UnixTimeSinceEpoch();// timestamp;
  2637. //if (client != null)
  2638. //{
  2639. msg.fromAgentName = m_host.Name;//client.FirstName + " " + client.LastName;// fromAgentName;
  2640. //}
  2641. //else
  2642. //{
  2643. // msg.fromAgentName = "(hippos)";// Added for posterity. This means that we can't figure out who sent it
  2644. //}
  2645. // Cap the message length at 1024.
  2646. if (message != null && message.Length > 1024)
  2647. msg.message = message.Substring(0, 1024);
  2648. else
  2649. msg.message = message;
  2650. msg.dialog = (byte)19; // messgage from script ??? // dialog;
  2651. msg.fromGroup = false;// fromGroup;
  2652. msg.offline = (byte)0; //offline;
  2653. msg.ParentEstateID = 0; //ParentEstateID;
  2654. msg.Position = Vector3.Zero;// new Vector3(m_host.AbsolutePosition);
  2655. msg.RegionID = World.RegionInfo.RegionID.Guid;//RegionID.Guid;
  2656. msg.binaryBucket = new byte[0];// binaryBucket;
  2657. if (m_TransferModule != null)
  2658. {
  2659. m_TransferModule.SendInstantMessage(msg, delegate(bool success) {});
  2660. }
  2661. ScriptSleep(2000);
  2662. }
  2663. public void llEmail(string address, string subject, string message)
  2664. {
  2665. m_host.AddScriptLPS(1);
  2666. IEmailModule emailModule = m_ScriptEngine.World.RequestModuleInterface<IEmailModule>();
  2667. if (emailModule == null)
  2668. {
  2669. ShoutError("llEmail: email module not configured");
  2670. return;
  2671. }
  2672. emailModule.SendEmail(m_host.UUID, address, subject, message);
  2673. ScriptSleep(20000);
  2674. }
  2675. public void llGetNextEmail(string address, string subject)
  2676. {
  2677. m_host.AddScriptLPS(1);
  2678. IEmailModule emailModule = m_ScriptEngine.World.RequestModuleInterface<IEmailModule>();
  2679. if (emailModule == null)
  2680. {
  2681. ShoutError("llGetNextEmail: email module not configured");
  2682. return;
  2683. }
  2684. Email email;
  2685. email = emailModule.GetNextEmail(m_host.UUID, address, subject);
  2686. if (email == null)
  2687. return;
  2688. m_ScriptEngine.PostObjectEvent(m_host.LocalId,
  2689. new EventParams("email",
  2690. new Object[] {
  2691. new LSL_String(email.time),
  2692. new LSL_String(email.sender),
  2693. new LSL_String(email.subject),
  2694. new LSL_String(email.message),
  2695. new LSL_Integer(email.numLeft)},
  2696. new DetectParams[0]));
  2697. }
  2698. public LSL_String llGetKey()
  2699. {
  2700. m_host.AddScriptLPS(1);
  2701. return m_host.UUID.ToString();
  2702. }
  2703. public void llSetBuoyancy(double buoyancy)
  2704. {
  2705. m_host.AddScriptLPS(1);
  2706. if (m_host.ParentGroup != null)
  2707. {
  2708. if (!m_host.ParentGroup.IsDeleted)
  2709. {
  2710. m_host.ParentGroup.RootPart.SetBuoyancy((float)buoyancy);
  2711. }
  2712. }
  2713. }
  2714. /// <summary>
  2715. /// Attempt to clamp the object on the Z axis at the given height over tau seconds.
  2716. /// </summary>
  2717. /// <param name="height">Height to hover. Height of zero disables hover.</param>
  2718. /// <param name="water">False if height is calculated just from ground, otherwise uses ground or water depending on whichever is higher</param>
  2719. /// <param name="tau">Number of seconds over which to reach target</param>
  2720. public void llSetHoverHeight(double height, int water, double tau)
  2721. {
  2722. m_host.AddScriptLPS(1);
  2723. if (m_host.PhysActor != null)
  2724. {
  2725. PIDHoverType hoverType = PIDHoverType.Ground;
  2726. if (water != 0)
  2727. {
  2728. hoverType = PIDHoverType.GroundAndWater;
  2729. }
  2730. m_host.SetHoverHeight((float)height, hoverType, (float)tau);
  2731. }
  2732. }
  2733. public void llStopHover()
  2734. {
  2735. m_host.AddScriptLPS(1);
  2736. if (m_host.PhysActor != null)
  2737. {
  2738. m_host.SetHoverHeight(0f, PIDHoverType.Ground, 0f);
  2739. }
  2740. }
  2741. public void llMinEventDelay(double delay)
  2742. {
  2743. m_host.AddScriptLPS(1);
  2744. try
  2745. {
  2746. m_ScriptEngine.SetMinEventDelay(m_itemID, delay);
  2747. }
  2748. catch (NotImplementedException)
  2749. {
  2750. // Currently not implemented in DotNetEngine only XEngine
  2751. NotImplemented("llMinEventDelay in DotNetEngine");
  2752. }
  2753. }
  2754. /// <summary>
  2755. /// llSoundPreload is deprecated. In SL this appears to do absolutely nothing
  2756. /// and is documented to have no delay.
  2757. /// </summary>
  2758. public void llSoundPreload(string sound)
  2759. {
  2760. m_host.AddScriptLPS(1);
  2761. }
  2762. public void llRotLookAt(LSL_Rotation target, double strength, double damping)
  2763. {
  2764. m_host.AddScriptLPS(1);
  2765. Quaternion rot = new Quaternion((float)target.x, (float)target.y, (float)target.z, (float)target.s);
  2766. m_host.RotLookAt(rot, (float)strength, (float)damping);
  2767. }
  2768. public LSL_Integer llStringLength(string str)
  2769. {
  2770. m_host.AddScriptLPS(1);
  2771. if (str.Length > 0)
  2772. {
  2773. return str.Length;
  2774. }
  2775. else
  2776. {
  2777. return 0;
  2778. }
  2779. }
  2780. public void llStartAnimation(string anim)
  2781. {
  2782. m_host.AddScriptLPS(1);
  2783. UUID invItemID = InventorySelf();
  2784. if (invItemID == UUID.Zero)
  2785. return;
  2786. TaskInventoryItem item;
  2787. lock (m_host.TaskInventory)
  2788. {
  2789. if (!m_host.TaskInventory.ContainsKey(InventorySelf()))
  2790. return;
  2791. else
  2792. item = m_host.TaskInventory[InventorySelf()];
  2793. }
  2794. if (item.PermsGranter == UUID.Zero)
  2795. return;
  2796. if ((item.PermsMask & ScriptBaseClass.PERMISSION_TRIGGER_ANIMATION) != 0)
  2797. {
  2798. ScenePresence presence = World.GetScenePresence(item.PermsGranter);
  2799. if (presence != null)
  2800. {
  2801. // Do NOT try to parse UUID, animations cannot be triggered by ID
  2802. UUID animID = InventoryKey(anim, (int)AssetType.Animation);
  2803. if (animID == UUID.Zero)
  2804. presence.Animator.AddAnimation(anim, m_host.UUID);
  2805. else
  2806. presence.Animator.AddAnimation(animID, m_host.UUID);
  2807. }
  2808. }
  2809. }
  2810. public void llStopAnimation(string anim)
  2811. {
  2812. m_host.AddScriptLPS(1);
  2813. UUID invItemID=InventorySelf();
  2814. if (invItemID == UUID.Zero)
  2815. return;
  2816. TaskInventoryItem item;
  2817. lock (m_host.TaskInventory)
  2818. {
  2819. if (!m_host.TaskInventory.ContainsKey(InventorySelf()))
  2820. return;
  2821. else
  2822. item = m_host.TaskInventory[InventorySelf()];
  2823. }
  2824. if (item.PermsGranter == UUID.Zero)
  2825. return;
  2826. if ((item.PermsMask & ScriptBaseClass.PERMISSION_TRIGGER_ANIMATION) != 0)
  2827. {
  2828. UUID animID = new UUID();
  2829. if (!UUID.TryParse(anim, out animID))
  2830. {
  2831. animID=InventoryKey(anim);
  2832. }
  2833. ScenePresence presence = World.GetScenePresence(item.PermsGranter);
  2834. if (presence != null)
  2835. {
  2836. if (animID == UUID.Zero)
  2837. presence.Animator.RemoveAnimation(anim);
  2838. else
  2839. presence.Animator.RemoveAnimation(animID);
  2840. }
  2841. }
  2842. }
  2843. public void llPointAt(LSL_Vector pos)
  2844. {
  2845. m_host.AddScriptLPS(1);
  2846. }
  2847. public void llStopPointAt()
  2848. {
  2849. m_host.AddScriptLPS(1);
  2850. }
  2851. public void llTargetOmega(LSL_Vector axis, double spinrate, double gain)
  2852. {
  2853. m_host.AddScriptLPS(1);
  2854. m_host.AngularVelocity = new Vector3((float)(axis.x * spinrate), (float)(axis.y * spinrate), (float)(axis.z * spinrate));
  2855. m_host.ScheduleTerseUpdate();
  2856. m_host.SendTerseUpdateToAllClients();
  2857. m_host.ParentGroup.HasGroupChanged = true;
  2858. }
  2859. public LSL_Integer llGetStartParameter()
  2860. {
  2861. m_host.AddScriptLPS(1);
  2862. return m_ScriptEngine.GetStartParameter(m_itemID);
  2863. }
  2864. public void llGodLikeRezObject(string inventory, LSL_Vector pos)
  2865. {
  2866. m_host.AddScriptLPS(1);
  2867. NotImplemented("llGodLikeRezObject");
  2868. }
  2869. public void llRequestPermissions(string agent, int perm)
  2870. {
  2871. UUID agentID = new UUID();
  2872. if (!UUID.TryParse(agent, out agentID))
  2873. return;
  2874. UUID invItemID = InventorySelf();
  2875. if (invItemID == UUID.Zero)
  2876. return; // Not in a prim? How??
  2877. TaskInventoryItem item;
  2878. lock (m_host.TaskInventory)
  2879. {
  2880. item = m_host.TaskInventory[invItemID];
  2881. }
  2882. if (agentID == UUID.Zero || perm == 0) // Releasing permissions
  2883. {
  2884. llReleaseControls();
  2885. item.PermsGranter = UUID.Zero;
  2886. item.PermsMask = 0;
  2887. m_ScriptEngine.PostScriptEvent(m_itemID, new EventParams(
  2888. "run_time_permissions", new Object[] {
  2889. new LSL_Integer(0) },
  2890. new DetectParams[0]));
  2891. return;
  2892. }
  2893. if (item.PermsGranter != agentID || (perm & ScriptBaseClass.PERMISSION_TAKE_CONTROLS) == 0)
  2894. llReleaseControls();
  2895. m_host.AddScriptLPS(1);
  2896. if (m_host.ParentGroup.IsAttachment && (UUID)agent == m_host.ParentGroup.RootPart.AttachedAvatar)
  2897. {
  2898. // When attached, certain permissions are implicit if requested from owner
  2899. int implicitPerms = ScriptBaseClass.PERMISSION_TAKE_CONTROLS |
  2900. ScriptBaseClass.PERMISSION_TRIGGER_ANIMATION |
  2901. ScriptBaseClass.PERMISSION_CONTROL_CAMERA |
  2902. ScriptBaseClass.PERMISSION_ATTACH;
  2903. if ((perm & (~implicitPerms)) == 0) // Requested only implicit perms
  2904. {
  2905. lock (m_host.TaskInventory)
  2906. {
  2907. m_host.TaskInventory[invItemID].PermsGranter = agentID;
  2908. m_host.TaskInventory[invItemID].PermsMask = perm;
  2909. }
  2910. m_ScriptEngine.PostScriptEvent(m_itemID, new EventParams(
  2911. "run_time_permissions", new Object[] {
  2912. new LSL_Integer(perm) },
  2913. new DetectParams[0]));
  2914. return;
  2915. }
  2916. }
  2917. else if (m_host.SitTargetAvatar == agentID) // Sitting avatar
  2918. {
  2919. // When agent is sitting, certain permissions are implicit if requested from sitting agent
  2920. int implicitPerms = ScriptBaseClass.PERMISSION_TRIGGER_ANIMATION |
  2921. ScriptBaseClass.PERMISSION_CONTROL_CAMERA |
  2922. ScriptBaseClass.PERMISSION_TRACK_CAMERA |
  2923. ScriptBaseClass.PERMISSION_TAKE_CONTROLS;
  2924. if ((perm & (~implicitPerms)) == 0) // Requested only implicit perms
  2925. {
  2926. lock (m_host.TaskInventory)
  2927. {
  2928. m_host.TaskInventory[invItemID].PermsGranter = agentID;
  2929. m_host.TaskInventory[invItemID].PermsMask = perm;
  2930. }
  2931. m_ScriptEngine.PostScriptEvent(m_itemID, new EventParams(
  2932. "run_time_permissions", new Object[] {
  2933. new LSL_Integer(perm) },
  2934. new DetectParams[0]));
  2935. return;
  2936. }
  2937. }
  2938. ScenePresence presence = World.GetScenePresence(agentID);
  2939. if (presence != null)
  2940. {
  2941. string ownerName = resolveName(m_host.ParentGroup.RootPart.OwnerID);
  2942. if (ownerName == String.Empty)
  2943. ownerName = "(hippos)";
  2944. if (!m_waitingForScriptAnswer)
  2945. {
  2946. lock (m_host.TaskInventory)
  2947. {
  2948. m_host.TaskInventory[invItemID].PermsGranter = agentID;
  2949. m_host.TaskInventory[invItemID].PermsMask = 0;
  2950. }
  2951. presence.ControllingClient.OnScriptAnswer += handleScriptAnswer;
  2952. m_waitingForScriptAnswer=true;
  2953. }
  2954. presence.ControllingClient.SendScriptQuestion(
  2955. m_host.UUID, m_host.ParentGroup.RootPart.Name, ownerName, invItemID, perm);
  2956. return;
  2957. }
  2958. // Requested agent is not in range, refuse perms
  2959. m_ScriptEngine.PostScriptEvent(m_itemID, new EventParams(
  2960. "run_time_permissions", new Object[] {
  2961. new LSL_Integer(0) },
  2962. new DetectParams[0]));
  2963. }
  2964. void handleScriptAnswer(IClientAPI client, UUID taskID, UUID itemID, int answer)
  2965. {
  2966. if (taskID != m_host.UUID)
  2967. return;
  2968. UUID invItemID = InventorySelf();
  2969. if (invItemID == UUID.Zero)
  2970. return;
  2971. client.OnScriptAnswer-=handleScriptAnswer;
  2972. m_waitingForScriptAnswer=false;
  2973. if ((answer & ScriptBaseClass.PERMISSION_TAKE_CONTROLS) == 0)
  2974. llReleaseControls();
  2975. lock (m_host.TaskInventory)
  2976. {
  2977. m_host.TaskInventory[invItemID].PermsMask = answer;
  2978. }
  2979. m_ScriptEngine.PostScriptEvent(m_itemID, new EventParams(
  2980. "run_time_permissions", new Object[] {
  2981. new LSL_Integer(answer) },
  2982. new DetectParams[0]));
  2983. }
  2984. public LSL_String llGetPermissionsKey()
  2985. {
  2986. m_host.AddScriptLPS(1);
  2987. lock (m_host.TaskInventory)
  2988. {
  2989. foreach (TaskInventoryItem item in m_host.TaskInventory.Values)
  2990. {
  2991. if (item.Type == 10 && item.ItemID == m_itemID)
  2992. {
  2993. return item.PermsGranter.ToString();
  2994. }
  2995. }
  2996. }
  2997. return UUID.Zero.ToString();
  2998. }
  2999. public LSL_Integer llGetPermissions()
  3000. {
  3001. m_host.AddScriptLPS(1);
  3002. lock (m_host.TaskInventory)
  3003. {
  3004. foreach (TaskInventoryItem item in m_host.TaskInventory.Values)
  3005. {
  3006. if (item.Type == 10 && item.ItemID == m_itemID)
  3007. {
  3008. int perms = item.PermsMask;
  3009. if (m_automaticLinkPermission)
  3010. perms |= ScriptBaseClass.PERMISSION_CHANGE_LINKS;
  3011. return perms;
  3012. }
  3013. }
  3014. }
  3015. return 0;
  3016. }
  3017. public LSL_Integer llGetLinkNumber()
  3018. {
  3019. m_host.AddScriptLPS(1);
  3020. if (m_host.ParentGroup.PrimCount > 1)
  3021. {
  3022. return m_host.LinkNum;
  3023. }
  3024. else
  3025. {
  3026. return 0;
  3027. }
  3028. }
  3029. public void llSetLinkColor(int linknumber, LSL_Vector color, int face)
  3030. {
  3031. List<SceneObjectPart> parts = GetLinkParts(linknumber);
  3032. foreach (SceneObjectPart part in parts)
  3033. part.SetFaceColor(new Vector3((float)color.x, (float)color.y, (float)color.z), face);
  3034. }
  3035. public void llCreateLink(string target, int parent)
  3036. {
  3037. m_host.AddScriptLPS(1);
  3038. UUID invItemID = InventorySelf();
  3039. UUID targetID;
  3040. if (!UUID.TryParse(target, out targetID))
  3041. return;
  3042. TaskInventoryItem item;
  3043. lock (m_host.TaskInventory)
  3044. {
  3045. item = m_host.TaskInventory[invItemID];
  3046. }
  3047. if ((item.PermsMask & ScriptBaseClass.PERMISSION_CHANGE_LINKS) == 0
  3048. && !m_automaticLinkPermission)
  3049. {
  3050. ShoutError("Script trying to link but PERMISSION_CHANGE_LINKS permission not set!");
  3051. return;
  3052. }
  3053. IClientAPI client = null;
  3054. ScenePresence sp = World.GetScenePresence(item.PermsGranter);
  3055. if (sp != null)
  3056. client = sp.ControllingClient;
  3057. SceneObjectPart targetPart = World.GetSceneObjectPart((UUID)targetID);
  3058. if (targetPart.ParentGroup.RootPart.AttachmentPoint != 0)
  3059. return; // Fail silently if attached
  3060. SceneObjectGroup parentPrim = null, childPrim = null;
  3061. if (targetPart != null)
  3062. {
  3063. if (parent != 0) {
  3064. parentPrim = m_host.ParentGroup;
  3065. childPrim = targetPart.ParentGroup;
  3066. }
  3067. else
  3068. {
  3069. parentPrim = targetPart.ParentGroup;
  3070. childPrim = m_host.ParentGroup;
  3071. }
  3072. // byte uf = childPrim.RootPart.UpdateFlag;
  3073. childPrim.RootPart.UpdateFlag = 0;
  3074. parentPrim.LinkToGroup(childPrim);
  3075. // if (uf != (Byte)0)
  3076. // parent.RootPart.UpdateFlag = uf;
  3077. }
  3078. parentPrim.TriggerScriptChangedEvent(Changed.LINK);
  3079. parentPrim.RootPart.CreateSelected = true;
  3080. parentPrim.HasGroupChanged = true;
  3081. parentPrim.ScheduleGroupForFullUpdate();
  3082. if (client != null)
  3083. parentPrim.GetProperties(client);
  3084. ScriptSleep(1000);
  3085. }
  3086. public void llBreakLink(int linknum)
  3087. {
  3088. m_host.AddScriptLPS(1);
  3089. UUID invItemID = InventorySelf();
  3090. lock (m_host.TaskInventory)
  3091. {
  3092. if ((m_host.TaskInventory[invItemID].PermsMask & ScriptBaseClass.PERMISSION_CHANGE_LINKS) == 0
  3093. && !m_automaticLinkPermission)
  3094. {
  3095. ShoutError("Script trying to link but PERMISSION_CHANGE_LINKS permission not set!");
  3096. return;
  3097. }
  3098. }
  3099. if (linknum < ScriptBaseClass.LINK_THIS)
  3100. return;
  3101. SceneObjectGroup parentPrim = m_host.ParentGroup;
  3102. if (parentPrim.RootPart.AttachmentPoint != 0)
  3103. return; // Fail silently if attached
  3104. SceneObjectPart childPrim = null;
  3105. switch (linknum)
  3106. {
  3107. case ScriptBaseClass.LINK_ROOT:
  3108. break;
  3109. case ScriptBaseClass.LINK_SET:
  3110. case ScriptBaseClass.LINK_ALL_OTHERS:
  3111. case ScriptBaseClass.LINK_ALL_CHILDREN:
  3112. case ScriptBaseClass.LINK_THIS:
  3113. foreach (SceneObjectPart part in parentPrim.Parts)
  3114. {
  3115. if (part.UUID != m_host.UUID)
  3116. {
  3117. childPrim = part;
  3118. break;
  3119. }
  3120. }
  3121. break;
  3122. default:
  3123. childPrim = parentPrim.GetLinkNumPart(linknum);
  3124. if (childPrim.UUID == m_host.UUID)
  3125. childPrim = null;
  3126. break;
  3127. }
  3128. if (linknum == ScriptBaseClass.LINK_ROOT)
  3129. {
  3130. // Restructuring Multiple Prims.
  3131. List<SceneObjectPart> parts = new List<SceneObjectPart>(parentPrim.Parts);
  3132. parts.Remove(parentPrim.RootPart);
  3133. foreach (SceneObjectPart part in parts)
  3134. {
  3135. parentPrim.DelinkFromGroup(part.LocalId, true);
  3136. }
  3137. parentPrim.HasGroupChanged = true;
  3138. parentPrim.ScheduleGroupForFullUpdate();
  3139. parentPrim.TriggerScriptChangedEvent(Changed.LINK);
  3140. if (parts.Count > 0)
  3141. {
  3142. SceneObjectPart newRoot = parts[0];
  3143. parts.Remove(newRoot);
  3144. foreach (SceneObjectPart part in parts)
  3145. {
  3146. part.UpdateFlag = 0;
  3147. newRoot.ParentGroup.LinkToGroup(part.ParentGroup);
  3148. }
  3149. newRoot.ParentGroup.HasGroupChanged = true;
  3150. newRoot.ParentGroup.ScheduleGroupForFullUpdate();
  3151. }
  3152. }
  3153. else
  3154. {
  3155. if (childPrim == null)
  3156. return;
  3157. parentPrim.DelinkFromGroup(childPrim.LocalId, true);
  3158. parentPrim.HasGroupChanged = true;
  3159. parentPrim.ScheduleGroupForFullUpdate();
  3160. parentPrim.TriggerScriptChangedEvent(Changed.LINK);
  3161. }
  3162. }
  3163. public void llBreakAllLinks()
  3164. {
  3165. m_host.AddScriptLPS(1);
  3166. SceneObjectGroup parentPrim = m_host.ParentGroup;
  3167. if (parentPrim.RootPart.AttachmentPoint != 0)
  3168. return; // Fail silently if attached
  3169. List<SceneObjectPart> parts = new List<SceneObjectPart>(parentPrim.Parts);
  3170. parts.Remove(parentPrim.RootPart);
  3171. foreach (SceneObjectPart part in parts)
  3172. {
  3173. parentPrim.DelinkFromGroup(part.LocalId, true);
  3174. parentPrim.TriggerScriptChangedEvent(Changed.LINK);
  3175. }
  3176. parentPrim.HasGroupChanged = true;
  3177. parentPrim.ScheduleGroupForFullUpdate();
  3178. }
  3179. public LSL_String llGetLinkKey(int linknum)
  3180. {
  3181. m_host.AddScriptLPS(1);
  3182. SceneObjectPart part = m_host.ParentGroup.GetLinkNumPart(linknum);
  3183. if (part != null)
  3184. {
  3185. return part.UUID.ToString();
  3186. }
  3187. else
  3188. {
  3189. return UUID.Zero.ToString();
  3190. }
  3191. }
  3192. /// <summary>
  3193. /// The rules governing the returned name are not simple. The only
  3194. /// time a blank name is returned is if the target prim has a blank
  3195. /// name. If no prim with the given link number can be found then
  3196. /// usually NULL_KEY is returned but there are exceptions.
  3197. ///
  3198. /// In a single unlinked prim, A call with 0 returns the name, all
  3199. /// other values for link number return NULL_KEY
  3200. ///
  3201. /// In link sets it is more complicated.
  3202. ///
  3203. /// If the script is in the root prim:-
  3204. /// A zero link number returns NULL_KEY.
  3205. /// Positive link numbers return the name of the prim, or NULL_KEY
  3206. /// if a prim does not exist at that position.
  3207. /// Negative link numbers return the name of the first child prim.
  3208. ///
  3209. /// If the script is in a child prim:-
  3210. /// Link numbers 0 or 1 return the name of the root prim.
  3211. /// Positive link numbers return the name of the prim or NULL_KEY
  3212. /// if a prim does not exist at that position.
  3213. /// Negative numbers return the name of the root prim.
  3214. ///
  3215. /// References
  3216. /// http://lslwiki.net/lslwiki/wakka.php?wakka=llGetLinkName
  3217. /// Mentions NULL_KEY being returned
  3218. /// http://wiki.secondlife.com/wiki/LlGetLinkName
  3219. /// Mentions using the LINK_* constants, some of which are negative
  3220. /// </summary>
  3221. public LSL_String llGetLinkName(int linknum)
  3222. {
  3223. m_host.AddScriptLPS(1);
  3224. // simplest case, this prims link number
  3225. if (m_host.LinkNum == linknum)
  3226. return m_host.Name;
  3227. // Single prim
  3228. if (m_host.LinkNum == 0)
  3229. {
  3230. if (linknum == 0)
  3231. return m_host.Name;
  3232. else
  3233. return UUID.Zero.ToString();
  3234. }
  3235. // Link set
  3236. SceneObjectPart part = null;
  3237. if (m_host.LinkNum == 1) // this is the Root prim
  3238. {
  3239. if (linknum < 0)
  3240. part = m_host.ParentGroup.GetLinkNumPart(2);
  3241. else
  3242. part = m_host.ParentGroup.GetLinkNumPart(linknum);
  3243. }
  3244. else // this is a child prim
  3245. {
  3246. if (linknum < 2)
  3247. part = m_host.ParentGroup.GetLinkNumPart(1);
  3248. else
  3249. part = m_host.ParentGroup.GetLinkNumPart(linknum);
  3250. }
  3251. if (part != null)
  3252. return part.Name;
  3253. else
  3254. return UUID.Zero.ToString();
  3255. }
  3256. public LSL_Integer llGetInventoryNumber(int type)
  3257. {
  3258. m_host.AddScriptLPS(1);
  3259. int count = 0;
  3260. lock (m_host.TaskInventory)
  3261. {
  3262. foreach (KeyValuePair<UUID, TaskInventoryItem> inv in m_host.TaskInventory)
  3263. {
  3264. if (inv.Value.Type == type || type == -1)
  3265. {
  3266. count = count + 1;
  3267. }
  3268. }
  3269. }
  3270. return count;
  3271. }
  3272. public LSL_String llGetInventoryName(int type, int number)
  3273. {
  3274. m_host.AddScriptLPS(1);
  3275. ArrayList keys = new ArrayList();
  3276. lock (m_host.TaskInventory)
  3277. {
  3278. foreach (KeyValuePair<UUID, TaskInventoryItem> inv in m_host.TaskInventory)
  3279. {
  3280. if (inv.Value.Type == type || type == -1)
  3281. {
  3282. keys.Add(inv.Value.Name);
  3283. }
  3284. }
  3285. }
  3286. if (keys.Count == 0)
  3287. {
  3288. return String.Empty;
  3289. }
  3290. keys.Sort();
  3291. if (keys.Count > number)
  3292. {
  3293. return (string)keys[number];
  3294. }
  3295. return String.Empty;
  3296. }
  3297. public LSL_Float llGetEnergy()
  3298. {
  3299. m_host.AddScriptLPS(1);
  3300. // TODO: figure out real energy value
  3301. return 1.0f;
  3302. }
  3303. public void llGiveInventory(string destination, string inventory)
  3304. {
  3305. m_host.AddScriptLPS(1);
  3306. bool found = false;
  3307. UUID destId = UUID.Zero;
  3308. UUID objId = UUID.Zero;
  3309. int assetType = 0;
  3310. string objName = String.Empty;
  3311. if (!UUID.TryParse(destination, out destId))
  3312. {
  3313. llSay(0, "Could not parse key " + destination);
  3314. return;
  3315. }
  3316. // move the first object found with this inventory name
  3317. lock (m_host.TaskInventory)
  3318. {
  3319. foreach (KeyValuePair<UUID, TaskInventoryItem> inv in m_host.TaskInventory)
  3320. {
  3321. if (inv.Value.Name == inventory)
  3322. {
  3323. found = true;
  3324. objId = inv.Key;
  3325. assetType = inv.Value.Type;
  3326. objName = inv.Value.Name;
  3327. break;
  3328. }
  3329. }
  3330. }
  3331. if (!found)
  3332. {
  3333. llSay(0, String.Format("Could not find object '{0}'", inventory));
  3334. throw new Exception(String.Format("The inventory object '{0}' could not be found", inventory));
  3335. }
  3336. // check if destination is an avatar
  3337. if (World.GetScenePresence(destId) != null)
  3338. {
  3339. // destination is an avatar
  3340. InventoryItemBase agentItem = World.MoveTaskInventoryItem(destId, UUID.Zero, m_host, objId);
  3341. if (agentItem == null)
  3342. return;
  3343. byte[] bucket = new byte[17];
  3344. bucket[0] = (byte)assetType;
  3345. byte[] objBytes = agentItem.ID.GetBytes();
  3346. Array.Copy(objBytes, 0, bucket, 1, 16);
  3347. GridInstantMessage msg = new GridInstantMessage(World,
  3348. m_host.UUID, m_host.Name+", an object owned by "+
  3349. resolveName(m_host.OwnerID)+",", destId,
  3350. (byte)InstantMessageDialog.InventoryOffered,
  3351. false, objName+"\n"+m_host.Name+" is located at "+
  3352. World.RegionInfo.RegionName+" "+
  3353. m_host.AbsolutePosition.ToString(),
  3354. agentItem.ID, true, m_host.AbsolutePosition,
  3355. bucket);
  3356. if (m_TransferModule != null)
  3357. m_TransferModule.SendInstantMessage(msg, delegate(bool success) {});
  3358. }
  3359. else
  3360. {
  3361. // destination is an object
  3362. World.MoveTaskInventoryItem(destId, m_host, objId);
  3363. }
  3364. ScriptSleep(3000);
  3365. }
  3366. public void llRemoveInventory(string name)
  3367. {
  3368. m_host.AddScriptLPS(1);
  3369. lock (m_host.TaskInventory)
  3370. {
  3371. foreach (TaskInventoryItem item in m_host.TaskInventory.Values)
  3372. {
  3373. if (item.Name == name)
  3374. {
  3375. if (item.ItemID == m_itemID)
  3376. throw new ScriptDeleteException();
  3377. else
  3378. m_host.Inventory.RemoveInventoryItem(item.ItemID);
  3379. return;
  3380. }
  3381. }
  3382. }
  3383. }
  3384. public void llSetText(string text, LSL_Vector color, double alpha)
  3385. {
  3386. m_host.AddScriptLPS(1);
  3387. Vector3 av3 = new Vector3(Util.Clip((float)color.x, 0.0f, 1.0f),
  3388. Util.Clip((float)color.y, 0.0f, 1.0f),
  3389. Util.Clip((float)color.z, 0.0f, 1.0f));
  3390. m_host.SetText(text, av3, Util.Clip((float)alpha, 0.0f, 1.0f));
  3391. m_host.ParentGroup.HasGroupChanged = true;
  3392. m_host.ParentGroup.ScheduleGroupForFullUpdate();
  3393. }
  3394. public LSL_Float llWater(LSL_Vector offset)
  3395. {
  3396. m_host.AddScriptLPS(1);
  3397. return World.RegionInfo.RegionSettings.WaterHeight;
  3398. }
  3399. public void llPassTouches(int pass)
  3400. {
  3401. m_host.AddScriptLPS(1);
  3402. if (pass != 0)
  3403. m_host.PassTouches = true;
  3404. else
  3405. m_host.PassTouches = false;
  3406. }
  3407. public LSL_String llRequestAgentData(string id, int data)
  3408. {
  3409. m_host.AddScriptLPS(1);
  3410. UUID uuid = (UUID)id;
  3411. PresenceInfo pinfo = null;
  3412. UserAccount account;
  3413. UserInfoCacheEntry ce;
  3414. if (!m_userInfoCache.TryGetValue(uuid, out ce))
  3415. {
  3416. account = World.UserAccountService.GetUserAccount(World.RegionInfo.ScopeID, uuid);
  3417. if (account == null)
  3418. {
  3419. m_userInfoCache[uuid] = null; // Cache negative
  3420. return UUID.Zero.ToString();
  3421. }
  3422. PresenceInfo[] pinfos = World.PresenceService.GetAgents(new string[] { uuid.ToString() });
  3423. if (pinfos != null && pinfos.Length > 0)
  3424. {
  3425. foreach (PresenceInfo p in pinfos)
  3426. {
  3427. if (p.RegionID != UUID.Zero)
  3428. {
  3429. pinfo = p;
  3430. }
  3431. }
  3432. }
  3433. ce = new UserInfoCacheEntry();
  3434. ce.time = Util.EnvironmentTickCount();
  3435. ce.account = account;
  3436. ce.pinfo = pinfo;
  3437. }
  3438. else
  3439. {
  3440. if (ce == null)
  3441. return UUID.Zero.ToString();
  3442. account = ce.account;
  3443. pinfo = ce.pinfo;
  3444. }
  3445. if (Util.EnvironmentTickCount() < ce.time || (Util.EnvironmentTickCount() - ce.time) >= 20000)
  3446. {
  3447. PresenceInfo[] pinfos = World.PresenceService.GetAgents(new string[] { uuid.ToString() });
  3448. if (pinfos != null && pinfos.Length > 0)
  3449. {
  3450. foreach (PresenceInfo p in pinfos)
  3451. {
  3452. if (p.RegionID != UUID.Zero)
  3453. {
  3454. pinfo = p;
  3455. }
  3456. }
  3457. }
  3458. else
  3459. pinfo = null;
  3460. ce.time = Util.EnvironmentTickCount();
  3461. ce.pinfo = pinfo;
  3462. }
  3463. string reply = String.Empty;
  3464. switch (data)
  3465. {
  3466. case 1: // DATA_ONLINE (0|1)
  3467. if (pinfo != null && pinfo.RegionID != UUID.Zero)
  3468. reply = "1";
  3469. else
  3470. reply = "0";
  3471. break;
  3472. case 2: // DATA_NAME (First Last)
  3473. reply = account.FirstName + " " + account.LastName;
  3474. break;
  3475. case 3: // DATA_BORN (YYYY-MM-DD)
  3476. DateTime born = new DateTime(1970, 1, 1, 0, 0, 0, 0);
  3477. born = born.AddSeconds(account.Created);
  3478. reply = born.ToString("yyyy-MM-dd");
  3479. break;
  3480. case 4: // DATA_RATING (0,0,0,0,0,0)
  3481. reply = "0,0,0,0,0,0";
  3482. break;
  3483. case 8: // DATA_PAYINFO (0|1|2|3)
  3484. reply = "0";
  3485. break;
  3486. default:
  3487. return UUID.Zero.ToString(); // Raise no event
  3488. }
  3489. UUID rq = UUID.Random();
  3490. UUID tid = AsyncCommands.
  3491. DataserverPlugin.RegisterRequest(m_localID,
  3492. m_itemID, rq.ToString());
  3493. AsyncCommands.
  3494. DataserverPlugin.DataserverReply(rq.ToString(), reply);
  3495. ScriptSleep(100);
  3496. return tid.ToString();
  3497. }
  3498. public LSL_String llRequestInventoryData(string name)
  3499. {
  3500. m_host.AddScriptLPS(1);
  3501. TaskInventoryDictionary itemDictionary = (TaskInventoryDictionary)m_host.TaskInventory.Clone();
  3502. foreach (TaskInventoryItem item in itemDictionary.Values)
  3503. {
  3504. if (item.Type == 3 && item.Name == name)
  3505. {
  3506. UUID tid = AsyncCommands.
  3507. DataserverPlugin.RegisterRequest(m_localID,
  3508. m_itemID, item.AssetID.ToString());
  3509. Vector3 region = new Vector3(
  3510. World.RegionInfo.RegionLocX * Constants.RegionSize,
  3511. World.RegionInfo.RegionLocY * Constants.RegionSize,
  3512. 0);
  3513. World.AssetService.Get(item.AssetID.ToString(), this,
  3514. delegate(string i, object sender, AssetBase a)
  3515. {
  3516. AssetLandmark lm = new AssetLandmark(a);
  3517. float rx = (uint)(lm.RegionHandle >> 32);
  3518. float ry = (uint)lm.RegionHandle;
  3519. region = lm.Position + new Vector3(rx, ry, 0) - region;
  3520. string reply = region.ToString();
  3521. AsyncCommands.
  3522. DataserverPlugin.DataserverReply(i.ToString(),
  3523. reply);
  3524. });
  3525. ScriptSleep(1000);
  3526. return tid.ToString();
  3527. }
  3528. }
  3529. ScriptSleep(1000);
  3530. return String.Empty;
  3531. }
  3532. public void llSetDamage(double damage)
  3533. {
  3534. m_host.AddScriptLPS(1);
  3535. m_host.ParentGroup.Damage = (float)damage;
  3536. }
  3537. public void llTeleportAgentHome(string agent)
  3538. {
  3539. m_host.AddScriptLPS(1);
  3540. UUID agentId = new UUID();
  3541. if (UUID.TryParse(agent, out agentId))
  3542. {
  3543. ScenePresence presence = World.GetScenePresence(agentId);
  3544. if (presence != null)
  3545. {
  3546. // agent must be over the owners land
  3547. if (m_host.OwnerID == World.LandChannel.GetLandObject(
  3548. presence.AbsolutePosition.X, presence.AbsolutePosition.Y).LandData.OwnerID)
  3549. {
  3550. World.TeleportClientHome(agentId, presence.ControllingClient);
  3551. }
  3552. }
  3553. }
  3554. ScriptSleep(5000);
  3555. }
  3556. public void llTextBox(string agent, string message, int chatChannel)
  3557. {
  3558. IDialogModule dm = World.RequestModuleInterface<IDialogModule>();
  3559. if (dm == null)
  3560. return;
  3561. m_host.AddScriptLPS(1);
  3562. UUID av = new UUID();
  3563. if (!UUID.TryParse(agent,out av))
  3564. {
  3565. LSLError("First parameter to llDialog needs to be a key");
  3566. return;
  3567. }
  3568. if (message == string.Empty)
  3569. {
  3570. ShoutError("Trying to use llTextBox with empty message.");
  3571. }
  3572. else if (message.Length > 512)
  3573. {
  3574. ShoutError("Trying to use llTextBox with message over 512 characters.");
  3575. }
  3576. else
  3577. {
  3578. dm.SendTextBoxToUser(av, message, chatChannel, m_host.Name, m_host.UUID, m_host.OwnerID);
  3579. ScriptSleep(1000);
  3580. }
  3581. }
  3582. public void llModifyLand(int action, int brush)
  3583. {
  3584. m_host.AddScriptLPS(1);
  3585. ITerrainModule tm = m_ScriptEngine.World.RequestModuleInterface<ITerrainModule>();
  3586. if (tm != null)
  3587. {
  3588. tm.ModifyTerrain(m_host.OwnerID, m_host.AbsolutePosition, (byte) brush, (byte) action, m_host.OwnerID);
  3589. }
  3590. }
  3591. public void llCollisionSound(string impact_sound, double impact_volume)
  3592. {
  3593. m_host.AddScriptLPS(1);
  3594. // TODO: Parameter check logic required.
  3595. UUID soundId = UUID.Zero;
  3596. if (!UUID.TryParse(impact_sound, out soundId))
  3597. {
  3598. lock (m_host.TaskInventory)
  3599. {
  3600. foreach (TaskInventoryItem item in m_host.TaskInventory.Values)
  3601. {
  3602. if (item.Type == (int)AssetType.Sound && item.Name == impact_sound)
  3603. {
  3604. soundId = item.AssetID;
  3605. break;
  3606. }
  3607. }
  3608. }
  3609. }
  3610. m_host.CollisionSound = soundId;
  3611. m_host.CollisionSoundVolume = (float)impact_volume;
  3612. }
  3613. public void llCollisionSprite(string impact_sprite)
  3614. {
  3615. m_host.AddScriptLPS(1);
  3616. NotImplemented("llCollisionSprite");
  3617. }
  3618. public LSL_String llGetAnimation(string id)
  3619. {
  3620. // This should only return a value if the avatar is in the same region
  3621. m_host.AddScriptLPS(1);
  3622. UUID avatar = (UUID)id;
  3623. ScenePresence presence = World.GetScenePresence(avatar);
  3624. if (presence == null)
  3625. return "";
  3626. if (m_host.RegionHandle == presence.RegionHandle)
  3627. {
  3628. Dictionary<UUID, string> animationstateNames = AnimationSet.Animations.AnimStateNames;
  3629. if (presence != null)
  3630. {
  3631. AnimationSet currentAnims = presence.Animator.Animations;
  3632. string currentAnimationState = String.Empty;
  3633. if (animationstateNames.TryGetValue(currentAnims.DefaultAnimation.AnimID, out currentAnimationState))
  3634. return currentAnimationState;
  3635. }
  3636. }
  3637. return String.Empty;
  3638. }
  3639. public void llMessageLinked(int linknumber, int num, string msg, string id)
  3640. {
  3641. m_host.AddScriptLPS(1);
  3642. List<SceneObjectPart> parts = GetLinkParts(linknumber);
  3643. UUID partItemID;
  3644. foreach (SceneObjectPart part in parts)
  3645. {
  3646. TaskInventoryDictionary itemsDictionary = (TaskInventoryDictionary)part.TaskInventory.Clone();
  3647. foreach (TaskInventoryItem item in itemsDictionary.Values)
  3648. {
  3649. if (item.Type == ScriptBaseClass.INVENTORY_SCRIPT)
  3650. {
  3651. partItemID = item.ItemID;
  3652. int linkNumber = m_host.LinkNum;
  3653. if (m_host.ParentGroup.PrimCount == 1)
  3654. linkNumber = 0;
  3655. object[] resobj = new object[]
  3656. {
  3657. new LSL_Integer(linkNumber), new LSL_Integer(num), new LSL_String(msg), new LSL_String(id)
  3658. };
  3659. m_ScriptEngine.PostScriptEvent(partItemID,
  3660. new EventParams("link_message",
  3661. resobj, new DetectParams[0]));
  3662. }
  3663. }
  3664. }
  3665. }
  3666. public void llPushObject(string target, LSL_Vector impulse, LSL_Vector ang_impulse, int local)
  3667. {
  3668. m_host.AddScriptLPS(1);
  3669. bool pushrestricted = World.RegionInfo.RegionSettings.RestrictPushing;
  3670. bool pushAllowed = false;
  3671. bool pusheeIsAvatar = false;
  3672. UUID targetID = UUID.Zero;
  3673. if (!UUID.TryParse(target,out targetID))
  3674. return;
  3675. ScenePresence pusheeav = null;
  3676. Vector3 PusheePos = Vector3.Zero;
  3677. SceneObjectPart pusheeob = null;
  3678. ScenePresence avatar = World.GetScenePresence(targetID);
  3679. if (avatar != null)
  3680. {
  3681. pusheeIsAvatar = true;
  3682. // Pushee doesn't have a physics actor
  3683. if (avatar.PhysicsActor == null)
  3684. return;
  3685. // Pushee is in GodMode this pushing object isn't owned by them
  3686. if (avatar.GodLevel > 0 && m_host.OwnerID != targetID)
  3687. return;
  3688. pusheeav = avatar;
  3689. // Find pushee position
  3690. // Pushee Linked?
  3691. if (pusheeav.ParentID != 0)
  3692. {
  3693. SceneObjectPart parentobj = World.GetSceneObjectPart(pusheeav.ParentID);
  3694. if (parentobj != null)
  3695. {
  3696. PusheePos = parentobj.AbsolutePosition;
  3697. }
  3698. else
  3699. {
  3700. PusheePos = pusheeav.AbsolutePosition;
  3701. }
  3702. }
  3703. else
  3704. {
  3705. PusheePos = pusheeav.AbsolutePosition;
  3706. }
  3707. }
  3708. if (!pusheeIsAvatar)
  3709. {
  3710. // not an avatar so push is not affected by parcel flags
  3711. pusheeob = World.GetSceneObjectPart((UUID)target);
  3712. // We can't find object
  3713. if (pusheeob == null)
  3714. return;
  3715. // Object not pushable. Not an attachment and has no physics component
  3716. if (!pusheeob.IsAttachment && pusheeob.PhysActor == null)
  3717. return;
  3718. PusheePos = pusheeob.AbsolutePosition;
  3719. pushAllowed = true;
  3720. }
  3721. else
  3722. {
  3723. if (pushrestricted)
  3724. {
  3725. ILandObject targetlandObj = World.LandChannel.GetLandObject(PusheePos.X, PusheePos.Y);
  3726. // We didn't find the parcel but region is push restricted so assume it is NOT ok
  3727. if (targetlandObj == null)
  3728. return;
  3729. // Need provisions for Group Owned here
  3730. if (m_host.OwnerID == targetlandObj.LandData.OwnerID ||
  3731. targetlandObj.LandData.IsGroupOwned || m_host.OwnerID == targetID)
  3732. {
  3733. pushAllowed = true;
  3734. }
  3735. }
  3736. else
  3737. {
  3738. ILandObject targetlandObj = World.LandChannel.GetLandObject(PusheePos.X, PusheePos.Y);
  3739. if (targetlandObj == null)
  3740. {
  3741. // We didn't find the parcel but region isn't push restricted so assume it's ok
  3742. pushAllowed = true;
  3743. }
  3744. else
  3745. {
  3746. // Parcel push restriction
  3747. if ((targetlandObj.LandData.Flags & (uint)ParcelFlags.RestrictPushObject) == (uint)ParcelFlags.RestrictPushObject)
  3748. {
  3749. // Need provisions for Group Owned here
  3750. if (m_host.OwnerID == targetlandObj.LandData.OwnerID ||
  3751. targetlandObj.LandData.IsGroupOwned ||
  3752. m_host.OwnerID == targetID)
  3753. {
  3754. pushAllowed = true;
  3755. }
  3756. //ParcelFlags.RestrictPushObject
  3757. //pushAllowed = true;
  3758. }
  3759. else
  3760. {
  3761. // Parcel isn't push restricted
  3762. pushAllowed = true;
  3763. }
  3764. }
  3765. }
  3766. }
  3767. if (pushAllowed)
  3768. {
  3769. float distance = (PusheePos - m_host.AbsolutePosition).Length();
  3770. float distance_term = distance * distance * distance; // Script Energy
  3771. float pusher_mass = m_host.GetMass();
  3772. float PUSH_ATTENUATION_DISTANCE = 17f;
  3773. float PUSH_ATTENUATION_SCALE = 5f;
  3774. float distance_attenuation = 1f;
  3775. if (distance > PUSH_ATTENUATION_DISTANCE)
  3776. {
  3777. float normalized_units = 1f + (distance - PUSH_ATTENUATION_DISTANCE) / PUSH_ATTENUATION_SCALE;
  3778. distance_attenuation = 1f / normalized_units;
  3779. }
  3780. Vector3 applied_linear_impulse = new Vector3((float)impulse.x, (float)impulse.y, (float)impulse.z);
  3781. {
  3782. float impulse_length = applied_linear_impulse.Length();
  3783. float desired_energy = impulse_length * pusher_mass;
  3784. if (desired_energy > 0f)
  3785. desired_energy += distance_term;
  3786. float scaling_factor = 1f;
  3787. scaling_factor *= distance_attenuation;
  3788. applied_linear_impulse *= scaling_factor;
  3789. }
  3790. if (pusheeIsAvatar)
  3791. {
  3792. if (pusheeav != null)
  3793. {
  3794. if (pusheeav.PhysicsActor != null)
  3795. {
  3796. if (local != 0)
  3797. {
  3798. applied_linear_impulse *= m_host.GetWorldRotation();
  3799. }
  3800. pusheeav.PhysicsActor.AddForce(applied_linear_impulse, true);
  3801. }
  3802. }
  3803. }
  3804. else
  3805. {
  3806. if (pusheeob != null)
  3807. {
  3808. if (pusheeob.PhysActor != null)
  3809. {
  3810. pusheeob.ApplyImpulse(applied_linear_impulse, local != 0);
  3811. }
  3812. }
  3813. }
  3814. }
  3815. }
  3816. public void llPassCollisions(int pass)
  3817. {
  3818. m_host.AddScriptLPS(1);
  3819. if (pass == 0)
  3820. {
  3821. m_host.ParentGroup.PassCollision = false;
  3822. }
  3823. else
  3824. {
  3825. m_host.ParentGroup.PassCollision = true;
  3826. }
  3827. }
  3828. public LSL_String llGetScriptName()
  3829. {
  3830. string result = String.Empty;
  3831. m_host.AddScriptLPS(1);
  3832. lock (m_host.TaskInventory)
  3833. {
  3834. foreach (TaskInventoryItem item in m_host.TaskInventory.Values)
  3835. {
  3836. if (item.Type == 10 && item.ItemID == m_itemID)
  3837. {
  3838. result = item.Name != null ? item.Name : String.Empty;
  3839. break;
  3840. }
  3841. }
  3842. }
  3843. return result;
  3844. }
  3845. public LSL_Integer llGetNumberOfSides()
  3846. {
  3847. m_host.AddScriptLPS(1);
  3848. return GetNumberOfSides(m_host);
  3849. }
  3850. protected int GetNumberOfSides(SceneObjectPart part)
  3851. {
  3852. int sides = part.GetNumberOfSides();
  3853. if (part.GetPrimType() == PrimType.SPHERE && part.Shape.ProfileHollow > 0)
  3854. {
  3855. // Make up for a bug where LSL shows 4 sides rather than 2
  3856. sides += 2;
  3857. }
  3858. return sides;
  3859. }
  3860. /* The new / changed functions were tested with the following LSL script:
  3861. default
  3862. {
  3863. state_entry()
  3864. {
  3865. rotation rot = llEuler2Rot(<0,70,0> * DEG_TO_RAD);
  3866. llOwnerSay("to get here, we rotate over: "+ (string) llRot2Axis(rot));
  3867. llOwnerSay("and we rotate for: "+ (llRot2Angle(rot) * RAD_TO_DEG));
  3868. // convert back and forth between quaternion <-> vector and angle
  3869. rotation newrot = llAxisAngle2Rot(llRot2Axis(rot),llRot2Angle(rot));
  3870. llOwnerSay("Old rotation was: "+(string) rot);
  3871. llOwnerSay("re-converted rotation is: "+(string) newrot);
  3872. llSetRot(rot); // to check the parameters in the prim
  3873. }
  3874. }
  3875. */
  3876. // Xantor 29/apr/2008
  3877. // Returns rotation described by rotating angle radians about axis.
  3878. // q = cos(a/2) + i (x * sin(a/2)) + j (y * sin(a/2)) + k (z * sin(a/2))
  3879. public LSL_Rotation llAxisAngle2Rot(LSL_Vector axis, double angle)
  3880. {
  3881. m_host.AddScriptLPS(1);
  3882. double x, y, z, s, t;
  3883. s = Math.Cos(angle * 0.5);
  3884. t = Math.Sin(angle * 0.5); // temp value to avoid 2 more sin() calcs
  3885. x = axis.x * t;
  3886. y = axis.y * t;
  3887. z = axis.z * t;
  3888. return new LSL_Rotation(x,y,z,s);
  3889. }
  3890. // Xantor 29/apr/2008
  3891. // converts a Quaternion to X,Y,Z axis rotations
  3892. public LSL_Vector llRot2Axis(LSL_Rotation rot)
  3893. {
  3894. m_host.AddScriptLPS(1);
  3895. double x,y,z;
  3896. if (rot.s > 1) // normalization needed
  3897. {
  3898. double length = Math.Sqrt(rot.x * rot.x + rot.y * rot.y +
  3899. rot.z * rot.z + rot.s * rot.s);
  3900. rot.x /= length;
  3901. rot.y /= length;
  3902. rot.z /= length;
  3903. rot.s /= length;
  3904. }
  3905. // double angle = 2 * Math.Acos(rot.s);
  3906. double s = Math.Sqrt(1 - rot.s * rot.s);
  3907. if (s < 0.001)
  3908. {
  3909. x = 1;
  3910. y = z = 0;
  3911. }
  3912. else
  3913. {
  3914. x = rot.x / s; // normalise axis
  3915. y = rot.y / s;
  3916. z = rot.z / s;
  3917. }
  3918. return new LSL_Vector(x,y,z);
  3919. }
  3920. // Returns the angle of a quaternion (see llRot2Axis for the axis)
  3921. public LSL_Float llRot2Angle(LSL_Rotation rot)
  3922. {
  3923. m_host.AddScriptLPS(1);
  3924. if (rot.s > 1) // normalization needed
  3925. {
  3926. double length = Math.Sqrt(rot.x * rot.x + rot.y * rot.y +
  3927. rot.z * rot.z + rot.s * rot.s);
  3928. rot.x /= length;
  3929. rot.y /= length;
  3930. rot.z /= length;
  3931. rot.s /= length;
  3932. }
  3933. double angle = 2 * Math.Acos(rot.s);
  3934. return angle;
  3935. }
  3936. public LSL_Float llAcos(double val)
  3937. {
  3938. m_host.AddScriptLPS(1);
  3939. return (double)Math.Acos(val);
  3940. }
  3941. public LSL_Float llAsin(double val)
  3942. {
  3943. m_host.AddScriptLPS(1);
  3944. return (double)Math.Asin(val);
  3945. }
  3946. // Xantor 30/apr/2008
  3947. public LSL_Float llAngleBetween(LSL_Rotation a, LSL_Rotation b)
  3948. {
  3949. m_host.AddScriptLPS(1);
  3950. double angle = Math.Acos(a.x * b.x + a.y * b.y + a.z * b.z + a.s * b.s) * 2;
  3951. if (angle < 0) angle = -angle;
  3952. if (angle > Math.PI) return (Math.PI * 2 - angle);
  3953. return angle;
  3954. }
  3955. public LSL_String llGetInventoryKey(string name)
  3956. {
  3957. m_host.AddScriptLPS(1);
  3958. lock (m_host.TaskInventory)
  3959. {
  3960. foreach (KeyValuePair<UUID, TaskInventoryItem> inv in m_host.TaskInventory)
  3961. {
  3962. if (inv.Value.Name == name)
  3963. {
  3964. if ((inv.Value.CurrentPermissions & (uint)(PermissionMask.Copy | PermissionMask.Transfer | PermissionMask.Modify)) == (uint)(PermissionMask.Copy | PermissionMask.Transfer | PermissionMask.Modify))
  3965. {
  3966. return inv.Value.AssetID.ToString();
  3967. }
  3968. else
  3969. {
  3970. return UUID.Zero.ToString();
  3971. }
  3972. }
  3973. }
  3974. }
  3975. return UUID.Zero.ToString();
  3976. }
  3977. public void llAllowInventoryDrop(int add)
  3978. {
  3979. m_host.AddScriptLPS(1);
  3980. if (add != 0)
  3981. m_host.ParentGroup.RootPart.AllowedDrop = true;
  3982. else
  3983. m_host.ParentGroup.RootPart.AllowedDrop = false;
  3984. // Update the object flags
  3985. m_host.ParentGroup.RootPart.aggregateScriptEvents();
  3986. }
  3987. public LSL_Vector llGetSunDirection()
  3988. {
  3989. m_host.AddScriptLPS(1);
  3990. LSL_Vector SunDoubleVector3;
  3991. Vector3 SunFloatVector3;
  3992. // sunPosition estate setting is set in OpenSim.Region.CoreModules.SunModule
  3993. // have to convert from Vector3 (float) to LSL_Vector (double)
  3994. SunFloatVector3 = World.RegionInfo.RegionSettings.SunVector;
  3995. SunDoubleVector3.x = (double)SunFloatVector3.X;
  3996. SunDoubleVector3.y = (double)SunFloatVector3.Y;
  3997. SunDoubleVector3.z = (double)SunFloatVector3.Z;
  3998. return SunDoubleVector3;
  3999. }
  4000. public LSL_Vector llGetTextureOffset(int face)
  4001. {
  4002. m_host.AddScriptLPS(1);
  4003. return GetTextureOffset(m_host, face);
  4004. }
  4005. protected LSL_Vector GetTextureOffset(SceneObjectPart part, int face)
  4006. {
  4007. Primitive.TextureEntry tex = part.Shape.Textures;
  4008. LSL_Vector offset = new LSL_Vector();
  4009. if (face == ScriptBaseClass.ALL_SIDES)
  4010. {
  4011. face = 0;
  4012. }
  4013. if (face >= 0 && face < GetNumberOfSides(part))
  4014. {
  4015. offset.x = tex.GetFace((uint)face).OffsetU;
  4016. offset.y = tex.GetFace((uint)face).OffsetV;
  4017. offset.z = 0.0;
  4018. return offset;
  4019. }
  4020. else
  4021. {
  4022. return offset;
  4023. }
  4024. }
  4025. public LSL_Vector llGetTextureScale(int side)
  4026. {
  4027. m_host.AddScriptLPS(1);
  4028. Primitive.TextureEntry tex = m_host.Shape.Textures;
  4029. LSL_Vector scale;
  4030. if (side == -1)
  4031. {
  4032. side = 0;
  4033. }
  4034. scale.x = tex.GetFace((uint)side).RepeatU;
  4035. scale.y = tex.GetFace((uint)side).RepeatV;
  4036. scale.z = 0.0;
  4037. return scale;
  4038. }
  4039. public LSL_Float llGetTextureRot(int face)
  4040. {
  4041. m_host.AddScriptLPS(1);
  4042. return GetTextureRot(m_host, face);
  4043. }
  4044. protected LSL_Float GetTextureRot(SceneObjectPart part, int face)
  4045. {
  4046. Primitive.TextureEntry tex = part.Shape.Textures;
  4047. if (face == -1)
  4048. {
  4049. face = 0;
  4050. }
  4051. if (face >= 0 && face < GetNumberOfSides(part))
  4052. {
  4053. return tex.GetFace((uint)face).Rotation;
  4054. }
  4055. else
  4056. {
  4057. return 0.0;
  4058. }
  4059. }
  4060. public LSL_Integer llSubStringIndex(string source, string pattern)
  4061. {
  4062. m_host.AddScriptLPS(1);
  4063. return source.IndexOf(pattern);
  4064. }
  4065. public LSL_String llGetOwnerKey(string id)
  4066. {
  4067. m_host.AddScriptLPS(1);
  4068. UUID key = new UUID();
  4069. if (UUID.TryParse(id, out key))
  4070. {
  4071. try
  4072. {
  4073. SceneObjectPart obj = World.GetSceneObjectPart(key);
  4074. if (obj == null)
  4075. return id; // the key is for an agent so just return the key
  4076. else
  4077. return obj.OwnerID.ToString();
  4078. }
  4079. catch (KeyNotFoundException)
  4080. {
  4081. return id; // The Object/Agent not in the region so just return the key
  4082. }
  4083. }
  4084. else
  4085. {
  4086. return UUID.Zero.ToString();
  4087. }
  4088. }
  4089. public LSL_Vector llGetCenterOfMass()
  4090. {
  4091. m_host.AddScriptLPS(1);
  4092. Vector3 center = m_host.GetGeometricCenter();
  4093. return new LSL_Vector(center.X,center.Y,center.Z);
  4094. }
  4095. public LSL_List llListSort(LSL_List src, int stride, int ascending)
  4096. {
  4097. m_host.AddScriptLPS(1);
  4098. if (stride <= 0)
  4099. {
  4100. stride = 1;
  4101. }
  4102. return src.Sort(stride, ascending);
  4103. }
  4104. public LSL_Integer llGetListLength(LSL_List src)
  4105. {
  4106. m_host.AddScriptLPS(1);
  4107. if (src == null)
  4108. {
  4109. return 0;
  4110. }
  4111. else
  4112. {
  4113. return src.Length;
  4114. }
  4115. }
  4116. public LSL_Integer llList2Integer(LSL_List src, int index)
  4117. {
  4118. m_host.AddScriptLPS(1);
  4119. if (index < 0)
  4120. {
  4121. index = src.Length + index;
  4122. }
  4123. if (index >= src.Length || index < 0)
  4124. {
  4125. return 0;
  4126. }
  4127. try
  4128. {
  4129. if (src.Data[index] is LSL_Integer)
  4130. return (LSL_Integer) src.Data[index];
  4131. else if (src.Data[index] is LSL_Float)
  4132. return Convert.ToInt32(((LSL_Float) src.Data[index]).value);
  4133. return new LSL_Integer(src.Data[index].ToString());
  4134. }
  4135. catch (FormatException)
  4136. {
  4137. return 0;
  4138. }
  4139. }
  4140. public LSL_Float llList2Float(LSL_List src, int index)
  4141. {
  4142. m_host.AddScriptLPS(1);
  4143. if (index < 0)
  4144. {
  4145. index = src.Length + index;
  4146. }
  4147. if (index >= src.Length || index < 0)
  4148. {
  4149. return 0.0;
  4150. }
  4151. try
  4152. {
  4153. if (src.Data[index] is LSL_Integer)
  4154. return Convert.ToDouble(((LSL_Integer) src.Data[index]).value);
  4155. else if (src.Data[index] is LSL_Float)
  4156. return Convert.ToDouble(((LSL_Float) src.Data[index]).value);
  4157. else if (src.Data[index] is LSL_String)
  4158. return Convert.ToDouble(((LSL_String) src.Data[index]).m_string);
  4159. return Convert.ToDouble(src.Data[index]);
  4160. }
  4161. catch (FormatException)
  4162. {
  4163. return 0.0;
  4164. }
  4165. }
  4166. public LSL_String llList2String(LSL_List src, int index)
  4167. {
  4168. m_host.AddScriptLPS(1);
  4169. if (index < 0)
  4170. {
  4171. index = src.Length + index;
  4172. }
  4173. if (index >= src.Length || index < 0)
  4174. {
  4175. return String.Empty;
  4176. }
  4177. return src.Data[index].ToString();
  4178. }
  4179. public LSL_String llList2Key(LSL_List src, int index)
  4180. {
  4181. m_host.AddScriptLPS(1);
  4182. if (index < 0)
  4183. {
  4184. index = src.Length + index;
  4185. }
  4186. if (index >= src.Length || index < 0)
  4187. {
  4188. return "";
  4189. }
  4190. return src.Data[index].ToString();
  4191. }
  4192. public LSL_Vector llList2Vector(LSL_List src, int index)
  4193. {
  4194. m_host.AddScriptLPS(1);
  4195. if (index < 0)
  4196. {
  4197. index = src.Length + index;
  4198. }
  4199. if (index >= src.Length || index < 0)
  4200. {
  4201. return new LSL_Vector(0, 0, 0);
  4202. }
  4203. if (src.Data[index].GetType() == typeof(LSL_Vector))
  4204. {
  4205. return (LSL_Vector)src.Data[index];
  4206. }
  4207. else
  4208. {
  4209. return new LSL_Vector(src.Data[index].ToString());
  4210. }
  4211. }
  4212. public LSL_Rotation llList2Rot(LSL_List src, int index)
  4213. {
  4214. m_host.AddScriptLPS(1);
  4215. if (index < 0)
  4216. {
  4217. index = src.Length + index;
  4218. }
  4219. if (index >= src.Length || index < 0)
  4220. {
  4221. return new LSL_Rotation(0, 0, 0, 1);
  4222. }
  4223. if (src.Data[index].GetType() == typeof(LSL_Rotation))
  4224. {
  4225. return (LSL_Rotation)src.Data[index];
  4226. }
  4227. else
  4228. {
  4229. return new LSL_Rotation(src.Data[index].ToString());
  4230. }
  4231. }
  4232. public LSL_List llList2List(LSL_List src, int start, int end)
  4233. {
  4234. m_host.AddScriptLPS(1);
  4235. return src.GetSublist(start, end);
  4236. }
  4237. public LSL_List llDeleteSubList(LSL_List src, int start, int end)
  4238. {
  4239. return src.DeleteSublist(start, end);
  4240. }
  4241. public LSL_Integer llGetListEntryType(LSL_List src, int index)
  4242. {
  4243. m_host.AddScriptLPS(1);
  4244. if (index < 0)
  4245. {
  4246. index = src.Length + index;
  4247. }
  4248. if (index >= src.Length)
  4249. {
  4250. return 0;
  4251. }
  4252. if (src.Data[index] is LSL_Integer || src.Data[index] is Int32)
  4253. return 1;
  4254. if (src.Data[index] is LSL_Float || src.Data[index] is Single || src.Data[index] is Double)
  4255. return 2;
  4256. if (src.Data[index] is LSL_String || src.Data[index] is String)
  4257. {
  4258. UUID tuuid;
  4259. if (UUID.TryParse(src.Data[index].ToString(), out tuuid))
  4260. {
  4261. return 4;
  4262. }
  4263. else
  4264. {
  4265. return 3;
  4266. }
  4267. }
  4268. if (src.Data[index] is LSL_Vector)
  4269. return 5;
  4270. if (src.Data[index] is LSL_Rotation)
  4271. return 6;
  4272. if (src.Data[index] is LSL_List)
  4273. return 7;
  4274. return 0;
  4275. }
  4276. /// <summary>
  4277. /// Process the supplied list and return the
  4278. /// content of the list formatted as a comma
  4279. /// separated list. There is a space after
  4280. /// each comma.
  4281. /// </summary>
  4282. public LSL_String llList2CSV(LSL_List src)
  4283. {
  4284. string ret = String.Empty;
  4285. int x = 0;
  4286. m_host.AddScriptLPS(1);
  4287. if (src.Data.Length > 0)
  4288. {
  4289. ret = src.Data[x++].ToString();
  4290. for (; x < src.Data.Length; x++)
  4291. {
  4292. ret += ", "+src.Data[x].ToString();
  4293. }
  4294. }
  4295. return ret;
  4296. }
  4297. /// <summary>
  4298. /// The supplied string is scanned for commas
  4299. /// and converted into a list. Commas are only
  4300. /// effective if they are encountered outside
  4301. /// of '<' '>' delimiters. Any whitespace
  4302. /// before or after an element is trimmed.
  4303. /// </summary>
  4304. public LSL_List llCSV2List(string src)
  4305. {
  4306. LSL_List result = new LSL_List();
  4307. int parens = 0;
  4308. int start = 0;
  4309. int length = 0;
  4310. m_host.AddScriptLPS(1);
  4311. for (int i = 0; i < src.Length; i++)
  4312. {
  4313. switch (src[i])
  4314. {
  4315. case '<':
  4316. parens++;
  4317. length++;
  4318. break;
  4319. case '>':
  4320. if (parens > 0)
  4321. parens--;
  4322. length++;
  4323. break;
  4324. case ',':
  4325. if (parens == 0)
  4326. {
  4327. result.Add(new LSL_String(src.Substring(start,length).Trim()));
  4328. start += length+1;
  4329. length = 0;
  4330. }
  4331. else
  4332. {
  4333. length++;
  4334. }
  4335. break;
  4336. default:
  4337. length++;
  4338. break;
  4339. }
  4340. }
  4341. result.Add(src.Substring(start,length).Trim());
  4342. return result;
  4343. }
  4344. /// <summary>
  4345. /// Randomizes the list, be arbitrarily reordering
  4346. /// sublists of stride elements. As the stride approaches
  4347. /// the size of the list, the options become very
  4348. /// limited.
  4349. /// </summary>
  4350. /// <remarks>
  4351. /// This could take a while for very large list
  4352. /// sizes.
  4353. /// </remarks>
  4354. public LSL_List llListRandomize(LSL_List src, int stride)
  4355. {
  4356. LSL_List result;
  4357. Random rand = new Random();
  4358. int chunkk;
  4359. int[] chunks;
  4360. m_host.AddScriptLPS(1);
  4361. if (stride <= 0)
  4362. {
  4363. stride = 1;
  4364. }
  4365. // Stride MUST be a factor of the list length
  4366. // If not, then return the src list. This also
  4367. // traps those cases where stride > length.
  4368. if (src.Length != stride && src.Length%stride == 0)
  4369. {
  4370. chunkk = src.Length/stride;
  4371. chunks = new int[chunkk];
  4372. for (int i = 0; i < chunkk; i++)
  4373. chunks[i] = i;
  4374. // Knuth shuffle the chunkk index
  4375. for (int i = chunkk - 1; i >= 1; i--)
  4376. {
  4377. // Elect an unrandomized chunk to swap
  4378. int index = rand.Next(i + 1);
  4379. int tmp;
  4380. // and swap position with first unrandomized chunk
  4381. tmp = chunks[i];
  4382. chunks[i] = chunks[index];
  4383. chunks[index] = tmp;
  4384. }
  4385. // Construct the randomized list
  4386. result = new LSL_List();
  4387. for (int i = 0; i < chunkk; i++)
  4388. {
  4389. for (int j = 0; j < stride; j++)
  4390. {
  4391. result.Add(src.Data[chunks[i]*stride+j]);
  4392. }
  4393. }
  4394. }
  4395. else {
  4396. object[] array = new object[src.Length];
  4397. Array.Copy(src.Data, 0, array, 0, src.Length);
  4398. result = new LSL_List(array);
  4399. }
  4400. return result;
  4401. }
  4402. /// <summary>
  4403. /// Elements in the source list starting with 0 and then
  4404. /// every i+stride. If the stride is negative then the scan
  4405. /// is backwards producing an inverted result.
  4406. /// Only those elements that are also in the specified
  4407. /// range are included in the result.
  4408. /// </summary>
  4409. public LSL_List llList2ListStrided(LSL_List src, int start, int end, int stride)
  4410. {
  4411. LSL_List result = new LSL_List();
  4412. int[] si = new int[2];
  4413. int[] ei = new int[2];
  4414. bool twopass = false;
  4415. m_host.AddScriptLPS(1);
  4416. // First step is always to deal with negative indices
  4417. if (start < 0)
  4418. start = src.Length+start;
  4419. if (end < 0)
  4420. end = src.Length+end;
  4421. // Out of bounds indices are OK, just trim them
  4422. // accordingly
  4423. if (start > src.Length)
  4424. start = src.Length;
  4425. if (end > src.Length)
  4426. end = src.Length;
  4427. if (stride == 0)
  4428. stride = 1;
  4429. // There may be one or two ranges to be considered
  4430. if (start != end)
  4431. {
  4432. if (start <= end)
  4433. {
  4434. si[0] = start;
  4435. ei[0] = end;
  4436. }
  4437. else
  4438. {
  4439. si[1] = start;
  4440. ei[1] = src.Length;
  4441. si[0] = 0;
  4442. ei[0] = end;
  4443. twopass = true;
  4444. }
  4445. // The scan always starts from the beginning of the
  4446. // source list, but members are only selected if they
  4447. // fall within the specified sub-range. The specified
  4448. // range values are inclusive.
  4449. // A negative stride reverses the direction of the
  4450. // scan producing an inverted list as a result.
  4451. if (stride > 0)
  4452. {
  4453. for (int i = 0; i < src.Length; i += stride)
  4454. {
  4455. if (i<=ei[0] && i>=si[0])
  4456. result.Add(src.Data[i]);
  4457. if (twopass && i>=si[1] && i<=ei[1])
  4458. result.Add(src.Data[i]);
  4459. }
  4460. }
  4461. else if (stride < 0)
  4462. {
  4463. for (int i = src.Length - 1; i >= 0; i += stride)
  4464. {
  4465. if (i <= ei[0] && i >= si[0])
  4466. result.Add(src.Data[i]);
  4467. if (twopass && i >= si[1] && i <= ei[1])
  4468. result.Add(src.Data[i]);
  4469. }
  4470. }
  4471. }
  4472. else
  4473. {
  4474. if (start%stride == 0)
  4475. {
  4476. result.Add(src.Data[start]);
  4477. }
  4478. }
  4479. return result;
  4480. }
  4481. public LSL_Integer llGetRegionAgentCount()
  4482. {
  4483. m_host.AddScriptLPS(1);
  4484. return new LSL_Integer(World.GetRootAgentCount());
  4485. }
  4486. public LSL_Vector llGetRegionCorner()
  4487. {
  4488. m_host.AddScriptLPS(1);
  4489. return new LSL_Vector(World.RegionInfo.RegionLocX * Constants.RegionSize, World.RegionInfo.RegionLocY * Constants.RegionSize, 0);
  4490. }
  4491. /// <summary>
  4492. /// Insert the list identified by <src> into the
  4493. /// list designated by <dest> such that the first
  4494. /// new element has the index specified by <index>
  4495. /// </summary>
  4496. public LSL_List llListInsertList(LSL_List dest, LSL_List src, int index)
  4497. {
  4498. LSL_List pref = null;
  4499. LSL_List suff = null;
  4500. m_host.AddScriptLPS(1);
  4501. if (index < 0)
  4502. {
  4503. index = index+dest.Length;
  4504. if (index < 0)
  4505. {
  4506. index = 0;
  4507. }
  4508. }
  4509. if (index != 0)
  4510. {
  4511. pref = dest.GetSublist(0,index-1);
  4512. if (index < dest.Length)
  4513. {
  4514. suff = dest.GetSublist(index,-1);
  4515. return pref + src + suff;
  4516. }
  4517. else
  4518. {
  4519. return pref + src;
  4520. }
  4521. }
  4522. else
  4523. {
  4524. if (index < dest.Length)
  4525. {
  4526. suff = dest.GetSublist(index,-1);
  4527. return src + suff;
  4528. }
  4529. else
  4530. {
  4531. return src;
  4532. }
  4533. }
  4534. }
  4535. /// <summary>
  4536. /// Returns the index of the first occurrence of test
  4537. /// in src.
  4538. /// </summary>
  4539. public LSL_Integer llListFindList(LSL_List src, LSL_List test)
  4540. {
  4541. int index = -1;
  4542. int length = src.Length - test.Length + 1;
  4543. m_host.AddScriptLPS(1);
  4544. // If either list is empty, do not match
  4545. if (src.Length != 0 && test.Length != 0)
  4546. {
  4547. for (int i = 0; i < length; i++)
  4548. {
  4549. if (src.Data[i].Equals(test.Data[0]))
  4550. {
  4551. int j;
  4552. for (j = 1; j < test.Length; j++)
  4553. if (!src.Data[i+j].Equals(test.Data[j]))
  4554. break;
  4555. if (j == test.Length)
  4556. {
  4557. index = i;
  4558. break;
  4559. }
  4560. }
  4561. }
  4562. }
  4563. return index;
  4564. }
  4565. public LSL_String llGetObjectName()
  4566. {
  4567. m_host.AddScriptLPS(1);
  4568. return m_host.Name!=null?m_host.Name:String.Empty;
  4569. }
  4570. public void llSetObjectName(string name)
  4571. {
  4572. m_host.AddScriptLPS(1);
  4573. m_host.Name = name!=null?name:String.Empty;
  4574. }
  4575. public LSL_String llGetDate()
  4576. {
  4577. m_host.AddScriptLPS(1);
  4578. DateTime date = DateTime.Now.ToUniversalTime();
  4579. string result = date.ToString("yyyy-MM-dd");
  4580. return result;
  4581. }
  4582. public LSL_Integer llEdgeOfWorld(LSL_Vector pos, LSL_Vector dir)
  4583. {
  4584. m_host.AddScriptLPS(1);
  4585. // edge will be used to pass the Region Coordinates offset
  4586. // we want to check for a neighboring sim
  4587. LSL_Vector edge = new LSL_Vector(0, 0, 0);
  4588. if (dir.x == 0)
  4589. {
  4590. if (dir.y == 0)
  4591. {
  4592. // Direction vector is 0,0 so return
  4593. // false since we're staying in the sim
  4594. return 0;
  4595. }
  4596. else
  4597. {
  4598. // Y is the only valid direction
  4599. edge.y = dir.y / Math.Abs(dir.y);
  4600. }
  4601. }
  4602. else
  4603. {
  4604. LSL_Float mag;
  4605. if (dir.x > 0)
  4606. {
  4607. mag = (Constants.RegionSize - pos.x) / dir.x;
  4608. }
  4609. else
  4610. {
  4611. mag = (pos.x/dir.x);
  4612. }
  4613. mag = Math.Abs(mag);
  4614. edge.y = pos.y + (dir.y * mag);
  4615. if (edge.y > Constants.RegionSize || edge.y < 0)
  4616. {
  4617. // Y goes out of bounds first
  4618. edge.y = dir.y / Math.Abs(dir.y);
  4619. }
  4620. else
  4621. {
  4622. // X goes out of bounds first or its a corner exit
  4623. edge.y = 0;
  4624. edge.x = dir.x / Math.Abs(dir.x);
  4625. }
  4626. }
  4627. List<GridRegion> neighbors = World.GridService.GetNeighbours(World.RegionInfo.ScopeID, World.RegionInfo.RegionID);
  4628. uint neighborX = World.RegionInfo.RegionLocX + (uint)dir.x;
  4629. uint neighborY = World.RegionInfo.RegionLocY + (uint)dir.y;
  4630. foreach (GridRegion sri in neighbors)
  4631. {
  4632. if (sri.RegionLocX == neighborX && sri.RegionLocY == neighborY)
  4633. return 0;
  4634. }
  4635. return 1;
  4636. }
  4637. /// <summary>
  4638. /// Not fully implemented yet. Still to do:-
  4639. /// AGENT_BUSY
  4640. /// Remove as they are done
  4641. /// </summary>
  4642. public LSL_Integer llGetAgentInfo(string id)
  4643. {
  4644. m_host.AddScriptLPS(1);
  4645. UUID key = new UUID();
  4646. if (!UUID.TryParse(id, out key))
  4647. {
  4648. return 0;
  4649. }
  4650. int flags = 0;
  4651. ScenePresence agent = World.GetScenePresence(key);
  4652. if (agent == null)
  4653. {
  4654. return 0;
  4655. }
  4656. if (agent.IsChildAgent)
  4657. return 0; // Fail if they are not in the same region
  4658. // note: in OpenSim, sitting seems to cancel AGENT_ALWAYS_RUN, unlike SL
  4659. if (agent.SetAlwaysRun)
  4660. {
  4661. flags |= ScriptBaseClass.AGENT_ALWAYS_RUN;
  4662. }
  4663. if (agent.HasAttachments())
  4664. {
  4665. flags |= ScriptBaseClass.AGENT_ATTACHMENTS;
  4666. if (agent.HasScriptedAttachments())
  4667. flags |= ScriptBaseClass.AGENT_SCRIPTED;
  4668. }
  4669. if ((agent.AgentControlFlags & (uint)AgentManager.ControlFlags.AGENT_CONTROL_FLY) != 0)
  4670. {
  4671. flags |= ScriptBaseClass.AGENT_FLYING;
  4672. flags |= ScriptBaseClass.AGENT_IN_AIR; // flying always implies in-air, even if colliding with e.g. a wall
  4673. }
  4674. if ((agent.AgentControlFlags & (uint)AgentManager.ControlFlags.AGENT_CONTROL_AWAY) != 0)
  4675. {
  4676. flags |= ScriptBaseClass.AGENT_AWAY;
  4677. }
  4678. // seems to get unset, even if in mouselook, when avatar is sitting on a prim???
  4679. if ((agent.AgentControlFlags & (uint)AgentManager.ControlFlags.AGENT_CONTROL_MOUSELOOK) != 0)
  4680. {
  4681. flags |= ScriptBaseClass.AGENT_MOUSELOOK;
  4682. }
  4683. if ((agent.State & (byte)AgentState.Typing) != (byte)0)
  4684. {
  4685. flags |= ScriptBaseClass.AGENT_TYPING;
  4686. }
  4687. string agentMovementAnimation = agent.Animator.GetMovementAnimation();
  4688. if (agentMovementAnimation == "CROUCH")
  4689. {
  4690. flags |= ScriptBaseClass.AGENT_CROUCHING;
  4691. }
  4692. if (agentMovementAnimation == "WALK" || agentMovementAnimation == "CROUCHWALK")
  4693. {
  4694. flags |= ScriptBaseClass.AGENT_WALKING;
  4695. }
  4696. // not colliding implies in air. Note: flying also implies in-air, even if colliding (see above)
  4697. // note: AGENT_IN_AIR and AGENT_WALKING seem to be mutually exclusive states in SL.
  4698. // note: this may need some tweaking when walking downhill. you "fall down" for a brief instant
  4699. // and don't collide when walking downhill, which instantly registers as in-air, briefly. should
  4700. // there be some minimum non-collision threshold time before claiming the avatar is in-air?
  4701. if ((flags & ScriptBaseClass.AGENT_WALKING) == 0 &&
  4702. agent.PhysicsActor != null &&
  4703. !agent.PhysicsActor.IsColliding)
  4704. {
  4705. flags |= ScriptBaseClass.AGENT_IN_AIR;
  4706. }
  4707. if (agent.ParentID != 0)
  4708. {
  4709. flags |= ScriptBaseClass.AGENT_ON_OBJECT;
  4710. flags |= ScriptBaseClass.AGENT_SITTING;
  4711. }
  4712. if (agent.Animator.Animations.DefaultAnimation.AnimID
  4713. == AnimationSet.Animations.AnimsUUID["SIT_GROUND_CONSTRAINED"])
  4714. {
  4715. flags |= ScriptBaseClass.AGENT_SITTING;
  4716. }
  4717. return flags;
  4718. }
  4719. public LSL_String llGetAgentLanguage(string id)
  4720. {
  4721. // This should only return a value if the avatar is in the same region
  4722. //ckrinke 1-30-09 : This needs to parse the XMLRPC language field supplied
  4723. //by the client at login. Currently returning only en-us until our I18N
  4724. //effort gains momentum
  4725. m_host.AddScriptLPS(1);
  4726. return "en-us";
  4727. }
  4728. public void llAdjustSoundVolume(double volume)
  4729. {
  4730. m_host.AddScriptLPS(1);
  4731. m_host.AdjustSoundGain(volume);
  4732. ScriptSleep(100);
  4733. }
  4734. public void llSetSoundQueueing(int queue)
  4735. {
  4736. m_host.AddScriptLPS(1);
  4737. NotImplemented("llSetSoundQueueing");
  4738. }
  4739. public void llSetSoundRadius(double radius)
  4740. {
  4741. m_host.AddScriptLPS(1);
  4742. m_host.SoundRadius = radius;
  4743. }
  4744. public LSL_String llKey2Name(string id)
  4745. {
  4746. m_host.AddScriptLPS(1);
  4747. UUID key = new UUID();
  4748. if (UUID.TryParse(id,out key))
  4749. {
  4750. ScenePresence presence = World.GetScenePresence(key);
  4751. if (presence != null)
  4752. {
  4753. return presence.ControllingClient.Name;
  4754. //return presence.Name;
  4755. }
  4756. if (World.GetSceneObjectPart(key) != null)
  4757. {
  4758. return World.GetSceneObjectPart(key).Name;
  4759. }
  4760. }
  4761. return String.Empty;
  4762. }
  4763. public void llSetTextureAnim(int mode, int face, int sizex, int sizey, double start, double length, double rate)
  4764. {
  4765. m_host.AddScriptLPS(1);
  4766. SetTextureAnim(m_host, mode, face, sizex, sizey, start, length, rate);
  4767. }
  4768. public void llSetLinkTextureAnim(int linknumber, int mode, int face, int sizex, int sizey, double start, double length, double rate)
  4769. {
  4770. m_host.AddScriptLPS(1);
  4771. List<SceneObjectPart> parts = GetLinkParts(linknumber);
  4772. foreach (var part in parts)
  4773. {
  4774. SetTextureAnim(part, mode, face, sizex, sizey, start, length, rate);
  4775. }
  4776. }
  4777. private void SetTextureAnim(SceneObjectPart part, int mode, int face, int sizex, int sizey, double start, double length, double rate)
  4778. {
  4779. Primitive.TextureAnimation pTexAnim = new Primitive.TextureAnimation();
  4780. pTexAnim.Flags = (Primitive.TextureAnimMode)mode;
  4781. //ALL_SIDES
  4782. if (face == ScriptBaseClass.ALL_SIDES)
  4783. face = 255;
  4784. pTexAnim.Face = (uint)face;
  4785. pTexAnim.Length = (float)length;
  4786. pTexAnim.Rate = (float)rate;
  4787. pTexAnim.SizeX = (uint)sizex;
  4788. pTexAnim.SizeY = (uint)sizey;
  4789. pTexAnim.Start = (float)start;
  4790. part.AddTextureAnimation(pTexAnim);
  4791. part.SendFullUpdateToAllClients();
  4792. part.ParentGroup.HasGroupChanged = true;
  4793. }
  4794. public void llTriggerSoundLimited(string sound, double volume, LSL_Vector top_north_east,
  4795. LSL_Vector bottom_south_west)
  4796. {
  4797. m_host.AddScriptLPS(1);
  4798. float radius1 = (float)llVecDist(llGetPos(), top_north_east);
  4799. float radius2 = (float)llVecDist(llGetPos(), bottom_south_west);
  4800. float radius = Math.Abs(radius1 - radius2);
  4801. m_host.SendSound(KeyOrName(sound).ToString(), volume, true, 0, radius, false, false);
  4802. }
  4803. public void llEjectFromLand(string pest)
  4804. {
  4805. m_host.AddScriptLPS(1);
  4806. UUID agentId = new UUID();
  4807. if (UUID.TryParse(pest, out agentId))
  4808. {
  4809. ScenePresence presence = World.GetScenePresence(agentId);
  4810. if (presence != null)
  4811. {
  4812. // agent must be over the owners land
  4813. if (m_host.OwnerID == World.LandChannel.GetLandObject(
  4814. presence.AbsolutePosition.X, presence.AbsolutePosition.Y).LandData.OwnerID)
  4815. World.TeleportClientHome(agentId, presence.ControllingClient);
  4816. }
  4817. }
  4818. ScriptSleep(5000);
  4819. }
  4820. public LSL_Integer llOverMyLand(string id)
  4821. {
  4822. m_host.AddScriptLPS(1);
  4823. UUID key = new UUID();
  4824. if (UUID.TryParse(id, out key))
  4825. {
  4826. ScenePresence presence = World.GetScenePresence(key);
  4827. if (presence != null) // object is an avatar
  4828. {
  4829. if (m_host.OwnerID
  4830. == World.LandChannel.GetLandObject(
  4831. presence.AbsolutePosition.X, presence.AbsolutePosition.Y).LandData.OwnerID)
  4832. return 1;
  4833. }
  4834. else // object is not an avatar
  4835. {
  4836. SceneObjectPart obj = World.GetSceneObjectPart(key);
  4837. if (obj != null)
  4838. if (m_host.OwnerID
  4839. == World.LandChannel.GetLandObject(
  4840. obj.AbsolutePosition.X, obj.AbsolutePosition.Y).LandData.OwnerID)
  4841. return 1;
  4842. }
  4843. }
  4844. return 0;
  4845. }
  4846. public LSL_String llGetLandOwnerAt(LSL_Vector pos)
  4847. {
  4848. m_host.AddScriptLPS(1);
  4849. ILandObject land = World.LandChannel.GetLandObject((float)pos.x, (float)pos.y);
  4850. if (land == null)
  4851. return UUID.Zero.ToString();
  4852. return land.LandData.OwnerID.ToString();
  4853. }
  4854. /// <summary>
  4855. /// According to http://lslwiki.net/lslwiki/wakka.php?wakka=llGetAgentSize
  4856. /// only the height of avatars vary and that says:
  4857. /// Width (x) and depth (y) are constant. (0.45m and 0.6m respectively).
  4858. /// </summary>
  4859. public LSL_Vector llGetAgentSize(string id)
  4860. {
  4861. m_host.AddScriptLPS(1);
  4862. ScenePresence avatar = World.GetScenePresence((UUID)id);
  4863. LSL_Vector agentSize;
  4864. if (avatar == null || avatar.IsChildAgent) // Fail if not in the same region
  4865. {
  4866. agentSize = ScriptBaseClass.ZERO_VECTOR;
  4867. }
  4868. else
  4869. {
  4870. agentSize = new LSL_Vector(0.45, 0.6, avatar.Appearance.AvatarHeight);
  4871. }
  4872. return agentSize;
  4873. }
  4874. public LSL_Integer llSameGroup(string agent)
  4875. {
  4876. m_host.AddScriptLPS(1);
  4877. UUID agentId = new UUID();
  4878. if (!UUID.TryParse(agent, out agentId))
  4879. return new LSL_Integer(0);
  4880. ScenePresence presence = World.GetScenePresence(agentId);
  4881. if (presence == null || presence.IsChildAgent) // Return flase for child agents
  4882. return new LSL_Integer(0);
  4883. IClientAPI client = presence.ControllingClient;
  4884. if (m_host.GroupID == client.ActiveGroupId)
  4885. return new LSL_Integer(1);
  4886. else
  4887. return new LSL_Integer(0);
  4888. }
  4889. public void llUnSit(string id)
  4890. {
  4891. m_host.AddScriptLPS(1);
  4892. UUID key = new UUID();
  4893. if (UUID.TryParse(id, out key))
  4894. {
  4895. ScenePresence av = World.GetScenePresence(key);
  4896. if (av != null)
  4897. {
  4898. if (llAvatarOnSitTarget() == id)
  4899. {
  4900. // if the avatar is sitting on this object, then
  4901. // we can unsit them. We don't want random scripts unsitting random people
  4902. // Lets avoid the popcorn avatar scenario.
  4903. av.StandUp();
  4904. }
  4905. else
  4906. {
  4907. // If the object owner also owns the parcel
  4908. // or
  4909. // if the land is group owned and the object is group owned by the same group
  4910. // or
  4911. // if the object is owned by a person with estate access.
  4912. ILandObject parcel = World.LandChannel.GetLandObject(av.AbsolutePosition.X, av.AbsolutePosition.Y);
  4913. if (parcel != null)
  4914. {
  4915. if (m_host.OwnerID == parcel.LandData.OwnerID ||
  4916. (m_host.OwnerID == m_host.GroupID && m_host.GroupID == parcel.LandData.GroupID
  4917. && parcel.LandData.IsGroupOwned) || World.Permissions.IsGod(m_host.OwnerID))
  4918. {
  4919. av.StandUp();
  4920. }
  4921. }
  4922. }
  4923. }
  4924. }
  4925. }
  4926. public LSL_Vector llGroundSlope(LSL_Vector offset)
  4927. {
  4928. m_host.AddScriptLPS(1);
  4929. //Get the slope normal. This gives us the equation of the plane tangent to the slope.
  4930. LSL_Vector vsn = llGroundNormal(offset);
  4931. //Plug the x,y coordinates of the slope normal into the equation of the plane to get
  4932. //the height of that point on the plane. The resulting vector gives the slope.
  4933. Vector3 vsl = new Vector3();
  4934. vsl.X = (float)vsn.x;
  4935. vsl.Y = (float)vsn.y;
  4936. vsl.Z = (float)(((vsn.x * vsn.x) + (vsn.y * vsn.y)) / (-1 * vsn.z));
  4937. vsl.Normalize();
  4938. //Normalization might be overkill here
  4939. return new LSL_Vector(vsl.X, vsl.Y, vsl.Z);
  4940. }
  4941. public LSL_Vector llGroundNormal(LSL_Vector offset)
  4942. {
  4943. m_host.AddScriptLPS(1);
  4944. Vector3 pos = m_host.GetWorldPosition() + new Vector3((float)offset.x,
  4945. (float)offset.y,
  4946. (float)offset.z);
  4947. // Clamp to valid position
  4948. if (pos.X < 0)
  4949. pos.X = 0;
  4950. else if (pos.X >= World.Heightmap.Width)
  4951. pos.X = World.Heightmap.Width - 1;
  4952. if (pos.Y < 0)
  4953. pos.Y = 0;
  4954. else if (pos.Y >= World.Heightmap.Height)
  4955. pos.Y = World.Heightmap.Height - 1;
  4956. //Find two points in addition to the position to define a plane
  4957. Vector3 p0 = new Vector3(pos.X, pos.Y,
  4958. (float)World.Heightmap[(int)pos.X, (int)pos.Y]);
  4959. Vector3 p1 = new Vector3();
  4960. Vector3 p2 = new Vector3();
  4961. if ((pos.X + 1.0f) >= World.Heightmap.Width)
  4962. p1 = new Vector3(pos.X + 1.0f, pos.Y,
  4963. (float)World.Heightmap[(int)pos.X, (int)pos.Y]);
  4964. else
  4965. p1 = new Vector3(pos.X + 1.0f, pos.Y,
  4966. (float)World.Heightmap[(int)(pos.X + 1.0f), (int)pos.Y]);
  4967. if ((pos.Y + 1.0f) >= World.Heightmap.Height)
  4968. p2 = new Vector3(pos.X, pos.Y + 1.0f,
  4969. (float)World.Heightmap[(int)pos.X, (int)pos.Y]);
  4970. else
  4971. p2 = new Vector3(pos.X, pos.Y + 1.0f,
  4972. (float)World.Heightmap[(int)pos.X, (int)(pos.Y + 1.0f)]);
  4973. //Find normalized vectors from p0 to p1 and p0 to p2
  4974. Vector3 v0 = new Vector3(p1.X - p0.X, p1.Y - p0.Y, p1.Z - p0.Z);
  4975. Vector3 v1 = new Vector3(p2.X - p0.X, p2.Y - p0.Y, p2.Z - p0.Z);
  4976. v0.Normalize();
  4977. v1.Normalize();
  4978. //Find the cross product of the vectors (the slope normal).
  4979. Vector3 vsn = new Vector3();
  4980. vsn.X = (v0.Y * v1.Z) - (v0.Z * v1.Y);
  4981. vsn.Y = (v0.Z * v1.X) - (v0.X * v1.Z);
  4982. vsn.Z = (v0.X * v1.Y) - (v0.Y * v1.X);
  4983. vsn.Normalize();
  4984. //I believe the crossproduct of two normalized vectors is a normalized vector so
  4985. //this normalization may be overkill
  4986. return new LSL_Vector(vsn.X, vsn.Y, vsn.Z);
  4987. }
  4988. public LSL_Vector llGroundContour(LSL_Vector offset)
  4989. {
  4990. m_host.AddScriptLPS(1);
  4991. LSL_Vector x = llGroundSlope(offset);
  4992. return new LSL_Vector(-x.y, x.x, 0.0);
  4993. }
  4994. public LSL_Integer llGetAttached()
  4995. {
  4996. m_host.AddScriptLPS(1);
  4997. return m_host.ParentGroup.RootPart.AttachmentPoint;
  4998. }
  4999. public LSL_Integer llGetFreeMemory()
  5000. {
  5001. m_host.AddScriptLPS(1);
  5002. // Make scripts designed for LSO happy
  5003. return 16384;
  5004. }
  5005. public LSL_Integer llGetFreeURLs()
  5006. {
  5007. m_host.AddScriptLPS(1);
  5008. if (m_UrlModule != null)
  5009. return new LSL_Integer(m_UrlModule.GetFreeUrls());
  5010. return new LSL_Integer(0);
  5011. }
  5012. public LSL_String llGetRegionName()
  5013. {
  5014. m_host.AddScriptLPS(1);
  5015. return World.RegionInfo.RegionName;
  5016. }
  5017. public LSL_Float llGetRegionTimeDilation()
  5018. {
  5019. m_host.AddScriptLPS(1);
  5020. return (double)World.TimeDilation;
  5021. }
  5022. /// <summary>
  5023. /// Returns the value reported in the client Statistics window
  5024. /// </summary>
  5025. public LSL_Float llGetRegionFPS()
  5026. {
  5027. m_host.AddScriptLPS(1);
  5028. return World.SimulatorFPS;
  5029. }
  5030. /* particle system rules should be coming into this routine as doubles, that is
  5031. rule[0] should be an integer from this list and rule[1] should be the arg
  5032. for the same integer. wiki.secondlife.com has most of this mapping, but some
  5033. came from http://www.caligari-designs.com/p4u2
  5034. We iterate through the list for 'Count' elements, incrementing by two for each
  5035. iteration and set the members of Primitive.ParticleSystem, one at a time.
  5036. */
  5037. public enum PrimitiveRule : int
  5038. {
  5039. PSYS_PART_FLAGS = 0,
  5040. PSYS_PART_START_COLOR = 1,
  5041. PSYS_PART_START_ALPHA = 2,
  5042. PSYS_PART_END_COLOR = 3,
  5043. PSYS_PART_END_ALPHA = 4,
  5044. PSYS_PART_START_SCALE = 5,
  5045. PSYS_PART_END_SCALE = 6,
  5046. PSYS_PART_MAX_AGE = 7,
  5047. PSYS_SRC_ACCEL = 8,
  5048. PSYS_SRC_PATTERN = 9,
  5049. PSYS_SRC_INNERANGLE = 10,
  5050. PSYS_SRC_OUTERANGLE = 11,
  5051. PSYS_SRC_TEXTURE = 12,
  5052. PSYS_SRC_BURST_RATE = 13,
  5053. PSYS_SRC_BURST_PART_COUNT = 15,
  5054. PSYS_SRC_BURST_RADIUS = 16,
  5055. PSYS_SRC_BURST_SPEED_MIN = 17,
  5056. PSYS_SRC_BURST_SPEED_MAX = 18,
  5057. PSYS_SRC_MAX_AGE = 19,
  5058. PSYS_SRC_TARGET_KEY = 20,
  5059. PSYS_SRC_OMEGA = 21,
  5060. PSYS_SRC_ANGLE_BEGIN = 22,
  5061. PSYS_SRC_ANGLE_END = 23
  5062. }
  5063. internal Primitive.ParticleSystem.ParticleDataFlags ConvertUINTtoFlags(uint flags)
  5064. {
  5065. Primitive.ParticleSystem.ParticleDataFlags returnval = Primitive.ParticleSystem.ParticleDataFlags.None;
  5066. return returnval;
  5067. }
  5068. protected Primitive.ParticleSystem getNewParticleSystemWithSLDefaultValues()
  5069. {
  5070. Primitive.ParticleSystem ps = new Primitive.ParticleSystem();
  5071. // TODO find out about the other defaults and add them here
  5072. ps.PartStartColor = new Color4(1.0f, 1.0f, 1.0f, 1.0f);
  5073. ps.PartEndColor = new Color4(1.0f, 1.0f, 1.0f, 1.0f);
  5074. ps.PartStartScaleX = 1.0f;
  5075. ps.PartStartScaleY = 1.0f;
  5076. ps.PartEndScaleX = 1.0f;
  5077. ps.PartEndScaleY = 1.0f;
  5078. ps.BurstSpeedMin = 1.0f;
  5079. ps.BurstSpeedMax = 1.0f;
  5080. ps.BurstRate = 0.1f;
  5081. ps.PartMaxAge = 10.0f;
  5082. return ps;
  5083. }
  5084. public void llLinkParticleSystem(int linknumber, LSL_List rules)
  5085. {
  5086. m_host.AddScriptLPS(1);
  5087. List<SceneObjectPart> parts = GetLinkParts(linknumber);
  5088. foreach (var part in parts)
  5089. {
  5090. SetParticleSystem(part, rules);
  5091. }
  5092. }
  5093. public void llParticleSystem(LSL_List rules)
  5094. {
  5095. m_host.AddScriptLPS(1);
  5096. SetParticleSystem(m_host, rules);
  5097. }
  5098. private void SetParticleSystem(SceneObjectPart part, LSL_List rules) {
  5099. if (rules.Length == 0)
  5100. {
  5101. part.RemoveParticleSystem();
  5102. part.ParentGroup.HasGroupChanged = true;
  5103. }
  5104. else
  5105. {
  5106. Primitive.ParticleSystem prules = getNewParticleSystemWithSLDefaultValues();
  5107. LSL_Vector tempv = new LSL_Vector();
  5108. float tempf = 0;
  5109. for (int i = 0; i < rules.Length; i += 2)
  5110. {
  5111. switch (rules.GetLSLIntegerItem(i))
  5112. {
  5113. case (int)ScriptBaseClass.PSYS_PART_FLAGS:
  5114. prules.PartDataFlags = (Primitive.ParticleSystem.ParticleDataFlags)(uint)rules.GetLSLIntegerItem(i + 1);
  5115. break;
  5116. case (int)ScriptBaseClass.PSYS_PART_START_COLOR:
  5117. tempv = rules.GetVector3Item(i + 1);
  5118. prules.PartStartColor.R = (float)tempv.x;
  5119. prules.PartStartColor.G = (float)tempv.y;
  5120. prules.PartStartColor.B = (float)tempv.z;
  5121. break;
  5122. case (int)ScriptBaseClass.PSYS_PART_START_ALPHA:
  5123. tempf = (float)rules.GetLSLFloatItem(i + 1);
  5124. prules.PartStartColor.A = tempf;
  5125. break;
  5126. case (int)ScriptBaseClass.PSYS_PART_END_COLOR:
  5127. tempv = rules.GetVector3Item(i + 1);
  5128. prules.PartEndColor.R = (float)tempv.x;
  5129. prules.PartEndColor.G = (float)tempv.y;
  5130. prules.PartEndColor.B = (float)tempv.z;
  5131. break;
  5132. case (int)ScriptBaseClass.PSYS_PART_END_ALPHA:
  5133. tempf = (float)rules.GetLSLFloatItem(i + 1);
  5134. prules.PartEndColor.A = tempf;
  5135. break;
  5136. case (int)ScriptBaseClass.PSYS_PART_START_SCALE:
  5137. tempv = rules.GetVector3Item(i + 1);
  5138. prules.PartStartScaleX = (float)tempv.x;
  5139. prules.PartStartScaleY = (float)tempv.y;
  5140. break;
  5141. case (int)ScriptBaseClass.PSYS_PART_END_SCALE:
  5142. tempv = rules.GetVector3Item(i + 1);
  5143. prules.PartEndScaleX = (float)tempv.x;
  5144. prules.PartEndScaleY = (float)tempv.y;
  5145. break;
  5146. case (int)ScriptBaseClass.PSYS_PART_MAX_AGE:
  5147. tempf = (float)rules.GetLSLFloatItem(i + 1);
  5148. prules.PartMaxAge = tempf;
  5149. break;
  5150. case (int)ScriptBaseClass.PSYS_SRC_ACCEL:
  5151. tempv = rules.GetVector3Item(i + 1);
  5152. prules.PartAcceleration.X = (float)tempv.x;
  5153. prules.PartAcceleration.Y = (float)tempv.y;
  5154. prules.PartAcceleration.Z = (float)tempv.z;
  5155. break;
  5156. case (int)ScriptBaseClass.PSYS_SRC_PATTERN:
  5157. int tmpi = (int)rules.GetLSLIntegerItem(i + 1);
  5158. prules.Pattern = (Primitive.ParticleSystem.SourcePattern)tmpi;
  5159. break;
  5160. // PSYS_SRC_INNERANGLE and PSYS_SRC_ANGLE_BEGIN use the same variables. The
  5161. // PSYS_SRC_OUTERANGLE and PSYS_SRC_ANGLE_END also use the same variable. The
  5162. // client tells the difference between the two by looking at the 0x02 bit in
  5163. // the PartFlags variable.
  5164. case (int)ScriptBaseClass.PSYS_SRC_INNERANGLE:
  5165. tempf = (float)rules.GetLSLFloatItem(i + 1);
  5166. prules.InnerAngle = (float)tempf;
  5167. prules.PartFlags &= 0xFFFFFFFD; // Make sure new angle format is off.
  5168. break;
  5169. case (int)ScriptBaseClass.PSYS_SRC_OUTERANGLE:
  5170. tempf = (float)rules.GetLSLFloatItem(i + 1);
  5171. prules.OuterAngle = (float)tempf;
  5172. prules.PartFlags &= 0xFFFFFFFD; // Make sure new angle format is off.
  5173. break;
  5174. case (int)ScriptBaseClass.PSYS_SRC_TEXTURE:
  5175. prules.Texture = KeyOrName(rules.GetLSLStringItem(i + 1));
  5176. break;
  5177. case (int)ScriptBaseClass.PSYS_SRC_BURST_RATE:
  5178. tempf = (float)rules.GetLSLFloatItem(i + 1);
  5179. prules.BurstRate = (float)tempf;
  5180. break;
  5181. case (int)ScriptBaseClass.PSYS_SRC_BURST_PART_COUNT:
  5182. prules.BurstPartCount = (byte)(int)rules.GetLSLIntegerItem(i + 1);
  5183. break;
  5184. case (int)ScriptBaseClass.PSYS_SRC_BURST_RADIUS:
  5185. tempf = (float)rules.GetLSLFloatItem(i + 1);
  5186. prules.BurstRadius = (float)tempf;
  5187. break;
  5188. case (int)ScriptBaseClass.PSYS_SRC_BURST_SPEED_MIN:
  5189. tempf = (float)rules.GetLSLFloatItem(i + 1);
  5190. prules.BurstSpeedMin = (float)tempf;
  5191. break;
  5192. case (int)ScriptBaseClass.PSYS_SRC_BURST_SPEED_MAX:
  5193. tempf = (float)rules.GetLSLFloatItem(i + 1);
  5194. prules.BurstSpeedMax = (float)tempf;
  5195. break;
  5196. case (int)ScriptBaseClass.PSYS_SRC_MAX_AGE:
  5197. tempf = (float)rules.GetLSLFloatItem(i + 1);
  5198. prules.MaxAge = (float)tempf;
  5199. break;
  5200. case (int)ScriptBaseClass.PSYS_SRC_TARGET_KEY:
  5201. UUID key = UUID.Zero;
  5202. if (UUID.TryParse(rules.Data[i + 1].ToString(), out key))
  5203. {
  5204. prules.Target = key;
  5205. }
  5206. else
  5207. {
  5208. prules.Target = part.UUID;
  5209. }
  5210. break;
  5211. case (int)ScriptBaseClass.PSYS_SRC_OMEGA:
  5212. // AL: This is an assumption, since it is the only thing that would match.
  5213. tempv = rules.GetVector3Item(i + 1);
  5214. prules.AngularVelocity.X = (float)tempv.x;
  5215. prules.AngularVelocity.Y = (float)tempv.y;
  5216. prules.AngularVelocity.Z = (float)tempv.z;
  5217. break;
  5218. case (int)ScriptBaseClass.PSYS_SRC_ANGLE_BEGIN:
  5219. tempf = (float)rules.GetLSLFloatItem(i + 1);
  5220. prules.InnerAngle = (float)tempf;
  5221. prules.PartFlags |= 0x02; // Set new angle format.
  5222. break;
  5223. case (int)ScriptBaseClass.PSYS_SRC_ANGLE_END:
  5224. tempf = (float)rules.GetLSLFloatItem(i + 1);
  5225. prules.OuterAngle = (float)tempf;
  5226. prules.PartFlags |= 0x02; // Set new angle format.
  5227. break;
  5228. }
  5229. }
  5230. prules.CRC = 1;
  5231. part.AddNewParticleSystem(prules);
  5232. part.ParentGroup.HasGroupChanged = true;
  5233. }
  5234. part.SendFullUpdateToAllClients();
  5235. }
  5236. public void llGroundRepel(double height, int water, double tau)
  5237. {
  5238. m_host.AddScriptLPS(1);
  5239. if (m_host.PhysActor != null)
  5240. {
  5241. float ground = (float)llGround(new LSL_Types.Vector3(0, 0, 0));
  5242. float waterLevel = (float)llWater(new LSL_Types.Vector3(0, 0, 0));
  5243. PIDHoverType hoverType = PIDHoverType.Ground;
  5244. if (water != 0)
  5245. {
  5246. hoverType = PIDHoverType.GroundAndWater;
  5247. if (ground < waterLevel)
  5248. height += waterLevel;
  5249. else
  5250. height += ground;
  5251. }
  5252. else
  5253. {
  5254. height += ground;
  5255. }
  5256. m_host.SetHoverHeight((float)height, hoverType, (float)tau);
  5257. }
  5258. }
  5259. protected UUID GetTaskInventoryItem(string name)
  5260. {
  5261. lock (m_host.TaskInventory)
  5262. {
  5263. foreach (KeyValuePair<UUID, TaskInventoryItem> inv in m_host.TaskInventory)
  5264. {
  5265. if (inv.Value.Name == name)
  5266. return inv.Key;
  5267. }
  5268. }
  5269. return UUID.Zero;
  5270. }
  5271. public void llGiveInventoryList(string destination, string category, LSL_List inventory)
  5272. {
  5273. m_host.AddScriptLPS(1);
  5274. UUID destID;
  5275. if (!UUID.TryParse(destination, out destID))
  5276. return;
  5277. List<UUID> itemList = new List<UUID>();
  5278. foreach (Object item in inventory.Data)
  5279. {
  5280. UUID itemID;
  5281. if (UUID.TryParse(item.ToString(), out itemID))
  5282. {
  5283. itemList.Add(itemID);
  5284. }
  5285. else
  5286. {
  5287. itemID = GetTaskInventoryItem(item.ToString());
  5288. if (itemID != UUID.Zero)
  5289. itemList.Add(itemID);
  5290. }
  5291. }
  5292. if (itemList.Count == 0)
  5293. return;
  5294. UUID folderID = m_ScriptEngine.World.MoveTaskInventoryItems(destID, category, m_host, itemList);
  5295. if (folderID == UUID.Zero)
  5296. return;
  5297. byte[] bucket = new byte[17];
  5298. bucket[0] = (byte)AssetType.Folder;
  5299. byte[] objBytes = folderID.GetBytes();
  5300. Array.Copy(objBytes, 0, bucket, 1, 16);
  5301. GridInstantMessage msg = new GridInstantMessage(World,
  5302. m_host.UUID, m_host.Name+", an object owned by "+
  5303. resolveName(m_host.OwnerID)+",", destID,
  5304. (byte)InstantMessageDialog.InventoryOffered,
  5305. false, category+"\n"+m_host.Name+" is located at "+
  5306. World.RegionInfo.RegionName+" "+
  5307. m_host.AbsolutePosition.ToString(),
  5308. folderID, true, m_host.AbsolutePosition,
  5309. bucket);
  5310. if (m_TransferModule != null)
  5311. m_TransferModule.SendInstantMessage(msg, delegate(bool success) {});
  5312. }
  5313. public void llSetVehicleType(int type)
  5314. {
  5315. m_host.AddScriptLPS(1);
  5316. if (m_host.ParentGroup != null)
  5317. {
  5318. if (!m_host.ParentGroup.IsDeleted)
  5319. {
  5320. m_host.ParentGroup.RootPart.SetVehicleType(type);
  5321. }
  5322. }
  5323. }
  5324. //CFK 9/28: Most, but not all of the underlying plumbing between here and the physics modules is in
  5325. //CFK 9/28: so these are not complete yet.
  5326. public void llSetVehicleFloatParam(int param, LSL_Float value)
  5327. {
  5328. m_host.AddScriptLPS(1);
  5329. if (m_host.ParentGroup != null)
  5330. {
  5331. if (!m_host.ParentGroup.IsDeleted)
  5332. {
  5333. m_host.ParentGroup.RootPart.SetVehicleFloatParam(param, (float)value);
  5334. }
  5335. }
  5336. }
  5337. //CFK 9/28: Most, but not all of the underlying plumbing between here and the physics modules is in
  5338. //CFK 9/28: so these are not complete yet.
  5339. public void llSetVehicleVectorParam(int param, LSL_Vector vec)
  5340. {
  5341. m_host.AddScriptLPS(1);
  5342. if (m_host.ParentGroup != null)
  5343. {
  5344. if (!m_host.ParentGroup.IsDeleted)
  5345. {
  5346. m_host.ParentGroup.RootPart.SetVehicleVectorParam(param,
  5347. new Vector3((float)vec.x, (float)vec.y, (float)vec.z));
  5348. }
  5349. }
  5350. }
  5351. //CFK 9/28: Most, but not all of the underlying plumbing between here and the physics modules is in
  5352. //CFK 9/28: so these are not complete yet.
  5353. public void llSetVehicleRotationParam(int param, LSL_Rotation rot)
  5354. {
  5355. m_host.AddScriptLPS(1);
  5356. if (m_host.ParentGroup != null)
  5357. {
  5358. if (!m_host.ParentGroup.IsDeleted)
  5359. {
  5360. m_host.ParentGroup.RootPart.SetVehicleRotationParam(param,
  5361. Rot2Quaternion(rot));
  5362. }
  5363. }
  5364. }
  5365. public void llSetVehicleFlags(int flags)
  5366. {
  5367. m_host.AddScriptLPS(1);
  5368. if (m_host.ParentGroup != null)
  5369. {
  5370. if (!m_host.ParentGroup.IsDeleted)
  5371. {
  5372. m_host.ParentGroup.RootPart.SetVehicleFlags(flags, false);
  5373. }
  5374. }
  5375. }
  5376. public void llRemoveVehicleFlags(int flags)
  5377. {
  5378. m_host.AddScriptLPS(1);
  5379. if (m_host.ParentGroup != null)
  5380. {
  5381. if (!m_host.ParentGroup.IsDeleted)
  5382. {
  5383. m_host.ParentGroup.RootPart.SetVehicleFlags(flags, true);
  5384. }
  5385. }
  5386. }
  5387. public void llSitTarget(LSL_Vector offset, LSL_Rotation rot)
  5388. {
  5389. m_host.AddScriptLPS(1);
  5390. // LSL quaternions can normalize to 0, normal Quaternions can't.
  5391. if (rot.s == 0 && rot.x == 0 && rot.y == 0 && rot.z == 0)
  5392. rot.z = 1; // ZERO_ROTATION = 0,0,0,1
  5393. m_host.SitTargetPosition = new Vector3((float)offset.x, (float)offset.y, (float)offset.z);
  5394. m_host.SitTargetOrientation = Rot2Quaternion(rot);
  5395. m_host.ParentGroup.HasGroupChanged = true;
  5396. }
  5397. public LSL_String llAvatarOnSitTarget()
  5398. {
  5399. m_host.AddScriptLPS(1);
  5400. return m_host.GetAvatarOnSitTarget().ToString();
  5401. }
  5402. public void llAddToLandPassList(string avatar, double hours)
  5403. {
  5404. m_host.AddScriptLPS(1);
  5405. UUID key;
  5406. ILandObject land = World.LandChannel.GetLandObject(m_host.AbsolutePosition.X, m_host.AbsolutePosition.Y);
  5407. if (World.Permissions.CanEditParcelProperties(m_host.OwnerID, land, GroupPowers.LandManageAllowed))
  5408. {
  5409. ParcelManager.ParcelAccessEntry entry = new ParcelManager.ParcelAccessEntry();
  5410. if (UUID.TryParse(avatar, out key))
  5411. {
  5412. if (land.LandData.ParcelAccessList.FindIndex(
  5413. delegate(ParcelManager.ParcelAccessEntry e)
  5414. {
  5415. if (e.AgentID == key && e.Flags == AccessList.Access)
  5416. return true;
  5417. return false;
  5418. }) == -1)
  5419. {
  5420. entry.AgentID = key;
  5421. entry.Flags = AccessList.Access;
  5422. entry.Time = DateTime.Now.AddHours(hours);
  5423. land.LandData.ParcelAccessList.Add(entry);
  5424. }
  5425. }
  5426. }
  5427. ScriptSleep(100);
  5428. }
  5429. public void llSetTouchText(string text)
  5430. {
  5431. m_host.AddScriptLPS(1);
  5432. m_host.TouchName = text;
  5433. }
  5434. public void llSetSitText(string text)
  5435. {
  5436. m_host.AddScriptLPS(1);
  5437. m_host.SitName = text;
  5438. }
  5439. public void llSetCameraEyeOffset(LSL_Vector offset)
  5440. {
  5441. m_host.AddScriptLPS(1);
  5442. m_host.SetCameraEyeOffset(new Vector3((float)offset.x, (float)offset.y, (float)offset.z));
  5443. }
  5444. public void llSetCameraAtOffset(LSL_Vector offset)
  5445. {
  5446. m_host.AddScriptLPS(1);
  5447. m_host.SetCameraAtOffset(new Vector3((float)offset.x, (float)offset.y, (float)offset.z));
  5448. }
  5449. public LSL_String llDumpList2String(LSL_List src, string seperator)
  5450. {
  5451. m_host.AddScriptLPS(1);
  5452. if (src.Length == 0)
  5453. {
  5454. return String.Empty;
  5455. }
  5456. string ret = String.Empty;
  5457. foreach (object o in src.Data)
  5458. {
  5459. ret = ret + o.ToString() + seperator;
  5460. }
  5461. ret = ret.Substring(0, ret.Length - seperator.Length);
  5462. return ret;
  5463. }
  5464. public LSL_Integer llScriptDanger(LSL_Vector pos)
  5465. {
  5466. m_host.AddScriptLPS(1);
  5467. bool result = World.ScriptDanger(m_host.LocalId, new Vector3((float)pos.x, (float)pos.y, (float)pos.z));
  5468. if (result)
  5469. {
  5470. return 1;
  5471. }
  5472. else
  5473. {
  5474. return 0;
  5475. }
  5476. }
  5477. public void llDialog(string avatar, string message, LSL_List buttons, int chat_channel)
  5478. {
  5479. IDialogModule dm = World.RequestModuleInterface<IDialogModule>();
  5480. if (dm == null)
  5481. return;
  5482. m_host.AddScriptLPS(1);
  5483. UUID av = new UUID();
  5484. if (!UUID.TryParse(avatar,out av))
  5485. {
  5486. LSLError("First parameter to llDialog needs to be a key");
  5487. return;
  5488. }
  5489. if (buttons.Length < 1)
  5490. {
  5491. LSLError("No less than 1 button can be shown");
  5492. return;
  5493. }
  5494. if (buttons.Length > 12)
  5495. {
  5496. LSLError("No more than 12 buttons can be shown");
  5497. return;
  5498. }
  5499. string[] buts = new string[buttons.Length];
  5500. for (int i = 0; i < buttons.Length; i++)
  5501. {
  5502. if (buttons.Data[i].ToString() == String.Empty)
  5503. {
  5504. LSLError("button label cannot be blank");
  5505. return;
  5506. }
  5507. if (buttons.Data[i].ToString().Length > 24)
  5508. {
  5509. LSLError("button label cannot be longer than 24 characters");
  5510. return;
  5511. }
  5512. buts[i] = buttons.Data[i].ToString();
  5513. }
  5514. dm.SendDialogToUser(
  5515. av, m_host.Name, m_host.UUID, m_host.OwnerID,
  5516. message, new UUID("00000000-0000-2222-3333-100000001000"), chat_channel, buts);
  5517. ScriptSleep(1000);
  5518. }
  5519. public void llVolumeDetect(int detect)
  5520. {
  5521. m_host.AddScriptLPS(1);
  5522. if (m_host.ParentGroup != null)
  5523. {
  5524. if (!m_host.ParentGroup.IsDeleted)
  5525. {
  5526. m_host.ParentGroup.RootPart.ScriptSetVolumeDetect(detect!=0);
  5527. }
  5528. }
  5529. }
  5530. /// <summary>
  5531. /// This is a depecated function so this just replicates the result of
  5532. /// invoking it in SL
  5533. /// </summary>
  5534. public void llRemoteLoadScript(string target, string name, int running, int start_param)
  5535. {
  5536. m_host.AddScriptLPS(1);
  5537. // Report an error as it does in SL
  5538. ShoutError("Deprecated. Please use llRemoteLoadScriptPin instead.");
  5539. ScriptSleep(3000);
  5540. }
  5541. public void llSetRemoteScriptAccessPin(int pin)
  5542. {
  5543. m_host.AddScriptLPS(1);
  5544. m_host.ScriptAccessPin = pin;
  5545. }
  5546. public void llRemoteLoadScriptPin(string target, string name, int pin, int running, int start_param)
  5547. {
  5548. m_host.AddScriptLPS(1);
  5549. bool found = false;
  5550. UUID destId = UUID.Zero;
  5551. UUID srcId = UUID.Zero;
  5552. if (!UUID.TryParse(target, out destId))
  5553. {
  5554. llSay(0, "Could not parse key " + target);
  5555. return;
  5556. }
  5557. // target must be a different prim than the one containing the script
  5558. if (m_host.UUID == destId)
  5559. {
  5560. return;
  5561. }
  5562. // copy the first script found with this inventory name
  5563. lock (m_host.TaskInventory)
  5564. {
  5565. foreach (KeyValuePair<UUID, TaskInventoryItem> inv in m_host.TaskInventory)
  5566. {
  5567. if (inv.Value.Name == name)
  5568. {
  5569. // make sure the object is a script
  5570. if (10 == inv.Value.Type)
  5571. {
  5572. found = true;
  5573. srcId = inv.Key;
  5574. break;
  5575. }
  5576. }
  5577. }
  5578. }
  5579. if (!found)
  5580. {
  5581. llSay(0, "Could not find script " + name);
  5582. return;
  5583. }
  5584. // the rest of the permission checks are done in RezScript, so check the pin there as well
  5585. World.RezScript(srcId, m_host, destId, pin, running, start_param);
  5586. // this will cause the delay even if the script pin or permissions were wrong - seems ok
  5587. ScriptSleep(3000);
  5588. }
  5589. public void llOpenRemoteDataChannel()
  5590. {
  5591. m_host.AddScriptLPS(1);
  5592. IXMLRPC xmlrpcMod = m_ScriptEngine.World.RequestModuleInterface<IXMLRPC>();
  5593. if (xmlrpcMod.IsEnabled())
  5594. {
  5595. UUID channelID = xmlrpcMod.OpenXMLRPCChannel(m_localID, m_itemID, UUID.Zero);
  5596. IXmlRpcRouter xmlRpcRouter = m_ScriptEngine.World.RequestModuleInterface<IXmlRpcRouter>();
  5597. if (xmlRpcRouter != null)
  5598. {
  5599. string ExternalHostName = m_ScriptEngine.World.RegionInfo.ExternalHostName;
  5600. xmlRpcRouter.RegisterNewReceiver(m_ScriptEngine.ScriptModule, channelID, m_host.UUID,
  5601. m_itemID, String.Format("http://{0}:{1}/", ExternalHostName,
  5602. xmlrpcMod.Port.ToString()));
  5603. }
  5604. object[] resobj = new object[]
  5605. {
  5606. new LSL_Integer(1),
  5607. new LSL_String(channelID.ToString()),
  5608. new LSL_String(UUID.Zero.ToString()),
  5609. new LSL_String(String.Empty),
  5610. new LSL_Integer(0),
  5611. new LSL_String(String.Empty)
  5612. };
  5613. m_ScriptEngine.PostScriptEvent(m_itemID, new EventParams("remote_data", resobj,
  5614. new DetectParams[0]));
  5615. }
  5616. ScriptSleep(1000);
  5617. }
  5618. public LSL_String llSendRemoteData(string channel, string dest, int idata, string sdata)
  5619. {
  5620. m_host.AddScriptLPS(1);
  5621. IXMLRPC xmlrpcMod = m_ScriptEngine.World.RequestModuleInterface<IXMLRPC>();
  5622. ScriptSleep(3000);
  5623. return (xmlrpcMod.SendRemoteData(m_localID, m_itemID, channel, dest, idata, sdata)).ToString();
  5624. }
  5625. public void llRemoteDataReply(string channel, string message_id, string sdata, int idata)
  5626. {
  5627. m_host.AddScriptLPS(1);
  5628. IXMLRPC xmlrpcMod = m_ScriptEngine.World.RequestModuleInterface<IXMLRPC>();
  5629. xmlrpcMod.RemoteDataReply(channel, message_id, sdata, idata);
  5630. ScriptSleep(3000);
  5631. }
  5632. public void llCloseRemoteDataChannel(string channel)
  5633. {
  5634. m_host.AddScriptLPS(1);
  5635. IXMLRPC xmlrpcMod = m_ScriptEngine.World.RequestModuleInterface<IXMLRPC>();
  5636. xmlrpcMod.CloseXMLRPCChannel((UUID)channel);
  5637. ScriptSleep(1000);
  5638. }
  5639. public LSL_String llMD5String(string src, int nonce)
  5640. {
  5641. m_host.AddScriptLPS(1);
  5642. return Util.Md5Hash(String.Format("{0}:{1}", src, nonce.ToString()));
  5643. }
  5644. public LSL_String llSHA1String(string src)
  5645. {
  5646. m_host.AddScriptLPS(1);
  5647. return Util.SHA1Hash(src).ToLower();
  5648. }
  5649. protected ObjectShapePacket.ObjectDataBlock SetPrimitiveBlockShapeParams(SceneObjectPart part, int holeshape, LSL_Vector cut, float hollow, LSL_Vector twist)
  5650. {
  5651. ObjectShapePacket.ObjectDataBlock shapeBlock = new ObjectShapePacket.ObjectDataBlock();
  5652. if (holeshape != (int)ScriptBaseClass.PRIM_HOLE_DEFAULT &&
  5653. holeshape != (int)ScriptBaseClass.PRIM_HOLE_CIRCLE &&
  5654. holeshape != (int)ScriptBaseClass.PRIM_HOLE_SQUARE &&
  5655. holeshape != (int)ScriptBaseClass.PRIM_HOLE_TRIANGLE)
  5656. {
  5657. holeshape = (int)ScriptBaseClass.PRIM_HOLE_DEFAULT;
  5658. }
  5659. shapeBlock.ProfileCurve = (byte)holeshape;
  5660. if (cut.x < 0f)
  5661. {
  5662. cut.x = 0f;
  5663. }
  5664. if (cut.x > 1f)
  5665. {
  5666. cut.x = 1f;
  5667. }
  5668. if (cut.y < 0f)
  5669. {
  5670. cut.y = 0f;
  5671. }
  5672. if (cut.y > 1f)
  5673. {
  5674. cut.y = 1f;
  5675. }
  5676. if (cut.y - cut.x < 0.05f)
  5677. {
  5678. cut.x = cut.y - 0.05f;
  5679. if (cut.x < 0.0f)
  5680. {
  5681. cut.x = 0.0f;
  5682. cut.y = 0.05f;
  5683. }
  5684. }
  5685. shapeBlock.ProfileBegin = (ushort)(50000 * cut.x);
  5686. shapeBlock.ProfileEnd = (ushort)(50000 * (1 - cut.y));
  5687. if (hollow < 0f)
  5688. {
  5689. hollow = 0f;
  5690. }
  5691. if (hollow > 0.95)
  5692. {
  5693. hollow = 0.95f;
  5694. }
  5695. shapeBlock.ProfileHollow = (ushort)(50000 * hollow);
  5696. if (twist.x < -1.0f)
  5697. {
  5698. twist.x = -1.0f;
  5699. }
  5700. if (twist.x > 1.0f)
  5701. {
  5702. twist.x = 1.0f;
  5703. }
  5704. if (twist.y < -1.0f)
  5705. {
  5706. twist.y = -1.0f;
  5707. }
  5708. if (twist.y > 1.0f)
  5709. {
  5710. twist.y = 1.0f;
  5711. }
  5712. shapeBlock.PathTwistBegin = (sbyte)(100 * twist.x);
  5713. shapeBlock.PathTwist = (sbyte)(100 * twist.y);
  5714. shapeBlock.ObjectLocalID = part.LocalId;
  5715. // retain pathcurve
  5716. shapeBlock.PathCurve = part.Shape.PathCurve;
  5717. part.Shape.SculptEntry = false;
  5718. return shapeBlock;
  5719. }
  5720. protected void SetPrimitiveShapeParams(SceneObjectPart part, int holeshape, LSL_Vector cut, float hollow, LSL_Vector twist, LSL_Vector taper_b, LSL_Vector topshear, byte fudge)
  5721. {
  5722. ObjectShapePacket.ObjectDataBlock shapeBlock;
  5723. shapeBlock = SetPrimitiveBlockShapeParams(part, holeshape, cut, hollow, twist);
  5724. shapeBlock.ProfileCurve += fudge;
  5725. if (taper_b.x < 0f)
  5726. {
  5727. taper_b.x = 0f;
  5728. }
  5729. if (taper_b.x > 2f)
  5730. {
  5731. taper_b.x = 2f;
  5732. }
  5733. if (taper_b.y < 0f)
  5734. {
  5735. taper_b.y = 0f;
  5736. }
  5737. if (taper_b.y > 2f)
  5738. {
  5739. taper_b.y = 2f;
  5740. }
  5741. shapeBlock.PathScaleX = (byte)(100 * (2.0 - taper_b.x));
  5742. shapeBlock.PathScaleY = (byte)(100 * (2.0 - taper_b.y));
  5743. if (topshear.x < -0.5f)
  5744. {
  5745. topshear.x = -0.5f;
  5746. }
  5747. if (topshear.x > 0.5f)
  5748. {
  5749. topshear.x = 0.5f;
  5750. }
  5751. if (topshear.y < -0.5f)
  5752. {
  5753. topshear.y = -0.5f;
  5754. }
  5755. if (topshear.y > 0.5f)
  5756. {
  5757. topshear.y = 0.5f;
  5758. }
  5759. shapeBlock.PathShearX = (byte)(100 * topshear.x);
  5760. shapeBlock.PathShearY = (byte)(100 * topshear.y);
  5761. part.Shape.SculptEntry = false;
  5762. part.UpdateShape(shapeBlock);
  5763. }
  5764. protected void SetPrimitiveShapeParams(SceneObjectPart part, int holeshape, LSL_Vector cut, float hollow, LSL_Vector twist, LSL_Vector dimple, byte fudge)
  5765. {
  5766. ObjectShapePacket.ObjectDataBlock shapeBlock;
  5767. shapeBlock = SetPrimitiveBlockShapeParams(part, holeshape, cut, hollow, twist);
  5768. // profile/path swapped for a sphere
  5769. shapeBlock.PathBegin = shapeBlock.ProfileBegin;
  5770. shapeBlock.PathEnd = shapeBlock.ProfileEnd;
  5771. shapeBlock.ProfileCurve += fudge;
  5772. shapeBlock.PathScaleX = 100;
  5773. shapeBlock.PathScaleY = 100;
  5774. if (dimple.x < 0f)
  5775. {
  5776. dimple.x = 0f;
  5777. }
  5778. if (dimple.x > 1f)
  5779. {
  5780. dimple.x = 1f;
  5781. }
  5782. if (dimple.y < 0f)
  5783. {
  5784. dimple.y = 0f;
  5785. }
  5786. if (dimple.y > 1f)
  5787. {
  5788. dimple.y = 1f;
  5789. }
  5790. if (dimple.y - cut.x < 0.05f)
  5791. {
  5792. dimple.x = cut.y - 0.05f;
  5793. }
  5794. shapeBlock.ProfileBegin = (ushort)(50000 * dimple.x);
  5795. shapeBlock.ProfileEnd = (ushort)(50000 * (1 - dimple.y));
  5796. part.Shape.SculptEntry = false;
  5797. part.UpdateShape(shapeBlock);
  5798. }
  5799. 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 fudge)
  5800. {
  5801. ObjectShapePacket.ObjectDataBlock shapeBlock;
  5802. shapeBlock = SetPrimitiveBlockShapeParams(part, holeshape, cut, hollow, twist);
  5803. shapeBlock.ProfileCurve += fudge;
  5804. // profile/path swapped for a torrus, tube, ring
  5805. shapeBlock.PathBegin = shapeBlock.ProfileBegin;
  5806. shapeBlock.PathEnd = shapeBlock.ProfileEnd;
  5807. if (holesize.x < 0.05f)
  5808. {
  5809. holesize.x = 0.05f;
  5810. }
  5811. if (holesize.x > 1f)
  5812. {
  5813. holesize.x = 1f;
  5814. }
  5815. if (holesize.y < 0.05f)
  5816. {
  5817. holesize.y = 0.05f;
  5818. }
  5819. if (holesize.y > 0.5f)
  5820. {
  5821. holesize.y = 0.5f;
  5822. }
  5823. shapeBlock.PathScaleX = (byte)(100 * (2 - holesize.x));
  5824. shapeBlock.PathScaleY = (byte)(100 * (2 - holesize.y));
  5825. if (topshear.x < -0.5f)
  5826. {
  5827. topshear.x = -0.5f;
  5828. }
  5829. if (topshear.x > 0.5f)
  5830. {
  5831. topshear.x = 0.5f;
  5832. }
  5833. if (topshear.y < -0.5f)
  5834. {
  5835. topshear.y = -0.5f;
  5836. }
  5837. if (topshear.y > 0.5f)
  5838. {
  5839. topshear.y = 0.5f;
  5840. }
  5841. shapeBlock.PathShearX = (byte)(100 * topshear.x);
  5842. shapeBlock.PathShearY = (byte)(100 * topshear.y);
  5843. if (profilecut.x < 0f)
  5844. {
  5845. profilecut.x = 0f;
  5846. }
  5847. if (profilecut.x > 1f)
  5848. {
  5849. profilecut.x = 1f;
  5850. }
  5851. if (profilecut.y < 0f)
  5852. {
  5853. profilecut.y = 0f;
  5854. }
  5855. if (profilecut.y > 1f)
  5856. {
  5857. profilecut.y = 1f;
  5858. }
  5859. if (profilecut.y - profilecut.x < 0.05f)
  5860. {
  5861. profilecut.x = profilecut.y - 0.05f;
  5862. if (profilecut.x < 0.0f)
  5863. {
  5864. profilecut.x = 0.0f;
  5865. profilecut.y = 0.05f;
  5866. }
  5867. }
  5868. shapeBlock.ProfileBegin = (ushort)(50000 * profilecut.x);
  5869. shapeBlock.ProfileEnd = (ushort)(50000 * (1 - profilecut.y));
  5870. if (taper_a.x < -1f)
  5871. {
  5872. taper_a.x = -1f;
  5873. }
  5874. if (taper_a.x > 1f)
  5875. {
  5876. taper_a.x = 1f;
  5877. }
  5878. if (taper_a.y < -1f)
  5879. {
  5880. taper_a.y = -1f;
  5881. }
  5882. if (taper_a.y > 1f)
  5883. {
  5884. taper_a.y = 1f;
  5885. }
  5886. shapeBlock.PathTaperX = (sbyte)(100 * taper_a.x);
  5887. shapeBlock.PathTaperY = (sbyte)(100 * taper_a.y);
  5888. if (revolutions < 1f)
  5889. {
  5890. revolutions = 1f;
  5891. }
  5892. if (revolutions > 4f)
  5893. {
  5894. revolutions = 4f;
  5895. }
  5896. shapeBlock.PathRevolutions = (byte)(66.666667 * (revolutions - 1.0));
  5897. // limits on radiusoffset depend on revolutions and hole size (how?) seems like the maximum range is 0 to 1
  5898. if (radiusoffset < 0f)
  5899. {
  5900. radiusoffset = 0f;
  5901. }
  5902. if (radiusoffset > 1f)
  5903. {
  5904. radiusoffset = 1f;
  5905. }
  5906. shapeBlock.PathRadiusOffset = (sbyte)(100 * radiusoffset);
  5907. if (skew < -0.95f)
  5908. {
  5909. skew = -0.95f;
  5910. }
  5911. if (skew > 0.95f)
  5912. {
  5913. skew = 0.95f;
  5914. }
  5915. shapeBlock.PathSkew = (sbyte)(100 * skew);
  5916. part.Shape.SculptEntry = false;
  5917. part.UpdateShape(shapeBlock);
  5918. }
  5919. protected void SetPrimitiveShapeParams(SceneObjectPart part, string map, int type)
  5920. {
  5921. ObjectShapePacket.ObjectDataBlock shapeBlock = new ObjectShapePacket.ObjectDataBlock();
  5922. UUID sculptId;
  5923. if (!UUID.TryParse(map, out sculptId))
  5924. {
  5925. sculptId = InventoryKey(map, (int)AssetType.Texture);
  5926. }
  5927. if (sculptId == UUID.Zero)
  5928. return;
  5929. shapeBlock.ObjectLocalID = part.LocalId;
  5930. shapeBlock.PathScaleX = 100;
  5931. shapeBlock.PathScaleY = 150;
  5932. if (type != (int)ScriptBaseClass.PRIM_SCULPT_TYPE_CYLINDER &&
  5933. type != (int)ScriptBaseClass.PRIM_SCULPT_TYPE_PLANE &&
  5934. type != (int)ScriptBaseClass.PRIM_SCULPT_TYPE_SPHERE &&
  5935. type != (int)ScriptBaseClass.PRIM_SCULPT_TYPE_TORUS)
  5936. {
  5937. // default
  5938. type = (int)ScriptBaseClass.PRIM_SCULPT_TYPE_SPHERE;
  5939. }
  5940. // retain pathcurve
  5941. shapeBlock.PathCurve = part.Shape.PathCurve;
  5942. part.Shape.SetSculptData((byte)type, sculptId);
  5943. part.Shape.SculptEntry = true;
  5944. part.UpdateShape(shapeBlock);
  5945. }
  5946. public void llSetPrimitiveParams(LSL_List rules)
  5947. {
  5948. m_host.AddScriptLPS(1);
  5949. SetPrimParams(m_host, rules);
  5950. ScriptSleep(200);
  5951. }
  5952. public void llSetLinkPrimitiveParams(int linknumber, LSL_List rules)
  5953. {
  5954. m_host.AddScriptLPS(1);
  5955. List<SceneObjectPart> parts = GetLinkParts(linknumber);
  5956. foreach (SceneObjectPart part in parts)
  5957. SetPrimParams(part, rules);
  5958. ScriptSleep(200);
  5959. }
  5960. public void llSetLinkPrimitiveParamsFast(int linknumber, LSL_List rules)
  5961. {
  5962. m_host.AddScriptLPS(1);
  5963. List<SceneObjectPart> parts = GetLinkParts(linknumber);
  5964. foreach (SceneObjectPart part in parts)
  5965. SetPrimParams(part, rules);
  5966. }
  5967. protected void SetPrimParams(SceneObjectPart part, LSL_List rules)
  5968. {
  5969. int idx = 0;
  5970. while (idx < rules.Length)
  5971. {
  5972. int code = rules.GetLSLIntegerItem(idx++);
  5973. int remain = rules.Length - idx;
  5974. int face;
  5975. LSL_Vector v;
  5976. switch (code)
  5977. {
  5978. case (int)ScriptBaseClass.PRIM_POSITION:
  5979. if (remain < 1)
  5980. return;
  5981. v=rules.GetVector3Item(idx++);
  5982. SetPos(part, v);
  5983. break;
  5984. case (int)ScriptBaseClass.PRIM_SIZE:
  5985. if (remain < 1)
  5986. return;
  5987. v=rules.GetVector3Item(idx++);
  5988. SetScale(part, v);
  5989. break;
  5990. case (int)ScriptBaseClass.PRIM_ROTATION:
  5991. if (remain < 1)
  5992. return;
  5993. LSL_Rotation q = rules.GetQuaternionItem(idx++);
  5994. // try to let this work as in SL...
  5995. if (part.ParentID == 0)
  5996. {
  5997. // special case: If we are root, rotate complete SOG to new rotation
  5998. SetRot(part, Rot2Quaternion(q));
  5999. }
  6000. else
  6001. {
  6002. // we are a child. The rotation values will be set to the one of root modified by rot, as in SL. Don't ask.
  6003. SceneObjectGroup group = part.ParentGroup;
  6004. if (group != null) // a bit paranoid, maybe
  6005. {
  6006. SceneObjectPart rootPart = group.RootPart;
  6007. if (rootPart != null) // again, better safe than sorry
  6008. {
  6009. SetRot(part, rootPart.RotationOffset * Rot2Quaternion(q));
  6010. }
  6011. }
  6012. }
  6013. break;
  6014. case (int)ScriptBaseClass.PRIM_TYPE:
  6015. if (remain < 3)
  6016. return;
  6017. code = (int)rules.GetLSLIntegerItem(idx++);
  6018. remain = rules.Length - idx;
  6019. float hollow;
  6020. LSL_Vector twist;
  6021. LSL_Vector taper_b;
  6022. LSL_Vector topshear;
  6023. float revolutions;
  6024. float radiusoffset;
  6025. float skew;
  6026. LSL_Vector holesize;
  6027. LSL_Vector profilecut;
  6028. switch (code)
  6029. {
  6030. case (int)ScriptBaseClass.PRIM_TYPE_BOX:
  6031. if (remain < 6)
  6032. return;
  6033. face = (int)rules.GetLSLIntegerItem(idx++);
  6034. v = rules.GetVector3Item(idx++); // cut
  6035. hollow = (float)rules.GetLSLFloatItem(idx++);
  6036. twist = rules.GetVector3Item(idx++);
  6037. taper_b = rules.GetVector3Item(idx++);
  6038. topshear = rules.GetVector3Item(idx++);
  6039. part.Shape.PathCurve = (byte)Extrusion.Straight;
  6040. SetPrimitiveShapeParams(part, face, v, hollow, twist, taper_b, topshear, 1);
  6041. break;
  6042. case (int)ScriptBaseClass.PRIM_TYPE_CYLINDER:
  6043. if (remain < 6)
  6044. return;
  6045. face = (int)rules.GetLSLIntegerItem(idx++); // holeshape
  6046. v = rules.GetVector3Item(idx++); // cut
  6047. hollow = (float)rules.GetLSLFloatItem(idx++);
  6048. twist = rules.GetVector3Item(idx++);
  6049. taper_b = rules.GetVector3Item(idx++);
  6050. topshear = rules.GetVector3Item(idx++);
  6051. part.Shape.ProfileShape = ProfileShape.Circle;
  6052. part.Shape.PathCurve = (byte)Extrusion.Straight;
  6053. SetPrimitiveShapeParams(part, face, v, hollow, twist, taper_b, topshear, 0);
  6054. break;
  6055. case (int)ScriptBaseClass.PRIM_TYPE_PRISM:
  6056. if (remain < 6)
  6057. return;
  6058. face = (int)rules.GetLSLIntegerItem(idx++); // holeshape
  6059. v = rules.GetVector3Item(idx++); //cut
  6060. hollow = (float)rules.GetLSLFloatItem(idx++);
  6061. twist = rules.GetVector3Item(idx++);
  6062. taper_b = rules.GetVector3Item(idx++);
  6063. topshear = rules.GetVector3Item(idx++);
  6064. part.Shape.PathCurve = (byte)Extrusion.Straight;
  6065. SetPrimitiveShapeParams(part, face, v, hollow, twist, taper_b, topshear, 3);
  6066. break;
  6067. case (int)ScriptBaseClass.PRIM_TYPE_SPHERE:
  6068. if (remain < 5)
  6069. return;
  6070. face = (int)rules.GetLSLIntegerItem(idx++); // holeshape
  6071. v = rules.GetVector3Item(idx++); // cut
  6072. hollow = (float)rules.GetLSLFloatItem(idx++);
  6073. twist = rules.GetVector3Item(idx++);
  6074. taper_b = rules.GetVector3Item(idx++); // dimple
  6075. part.Shape.PathCurve = (byte)Extrusion.Curve1;
  6076. SetPrimitiveShapeParams(part, face, v, hollow, twist, taper_b, 5);
  6077. break;
  6078. case (int)ScriptBaseClass.PRIM_TYPE_TORUS:
  6079. if (remain < 11)
  6080. return;
  6081. face = (int)rules.GetLSLIntegerItem(idx++); // holeshape
  6082. v = rules.GetVector3Item(idx++); //cut
  6083. hollow = (float)rules.GetLSLFloatItem(idx++);
  6084. twist = rules.GetVector3Item(idx++);
  6085. holesize = rules.GetVector3Item(idx++);
  6086. topshear = rules.GetVector3Item(idx++);
  6087. profilecut = rules.GetVector3Item(idx++);
  6088. taper_b = rules.GetVector3Item(idx++); // taper_a
  6089. revolutions = (float)rules.GetLSLFloatItem(idx++);
  6090. radiusoffset = (float)rules.GetLSLFloatItem(idx++);
  6091. skew = (float)rules.GetLSLFloatItem(idx++);
  6092. part.Shape.PathCurve = (byte)Extrusion.Curve1;
  6093. SetPrimitiveShapeParams(part, face, v, hollow, twist, holesize, topshear, profilecut, taper_b,
  6094. revolutions, radiusoffset, skew, 0);
  6095. break;
  6096. case (int)ScriptBaseClass.PRIM_TYPE_TUBE:
  6097. if (remain < 11)
  6098. return;
  6099. face = (int)rules.GetLSLIntegerItem(idx++); // holeshape
  6100. v = rules.GetVector3Item(idx++); //cut
  6101. hollow = (float)rules.GetLSLFloatItem(idx++);
  6102. twist = rules.GetVector3Item(idx++);
  6103. holesize = rules.GetVector3Item(idx++);
  6104. topshear = rules.GetVector3Item(idx++);
  6105. profilecut = rules.GetVector3Item(idx++);
  6106. taper_b = rules.GetVector3Item(idx++); // taper_a
  6107. revolutions = (float)rules.GetLSLFloatItem(idx++);
  6108. radiusoffset = (float)rules.GetLSLFloatItem(idx++);
  6109. skew = (float)rules.GetLSLFloatItem(idx++);
  6110. part.Shape.PathCurve = (byte)Extrusion.Curve1;
  6111. SetPrimitiveShapeParams(part, face, v, hollow, twist, holesize, topshear, profilecut, taper_b,
  6112. revolutions, radiusoffset, skew, 1);
  6113. break;
  6114. case (int)ScriptBaseClass.PRIM_TYPE_RING:
  6115. if (remain < 11)
  6116. return;
  6117. face = (int)rules.GetLSLIntegerItem(idx++); // holeshape
  6118. v = rules.GetVector3Item(idx++); //cut
  6119. hollow = (float)rules.GetLSLFloatItem(idx++);
  6120. twist = rules.GetVector3Item(idx++);
  6121. holesize = rules.GetVector3Item(idx++);
  6122. topshear = rules.GetVector3Item(idx++);
  6123. profilecut = rules.GetVector3Item(idx++);
  6124. taper_b = rules.GetVector3Item(idx++); // taper_a
  6125. revolutions = (float)rules.GetLSLFloatItem(idx++);
  6126. radiusoffset = (float)rules.GetLSLFloatItem(idx++);
  6127. skew = (float)rules.GetLSLFloatItem(idx++);
  6128. part.Shape.PathCurve = (byte)Extrusion.Curve1;
  6129. SetPrimitiveShapeParams(part, face, v, hollow, twist, holesize, topshear, profilecut, taper_b,
  6130. revolutions, radiusoffset, skew, 3);
  6131. break;
  6132. case (int)ScriptBaseClass.PRIM_TYPE_SCULPT:
  6133. if (remain < 2)
  6134. return;
  6135. string map = rules.Data[idx++].ToString();
  6136. face = (int)rules.GetLSLIntegerItem(idx++); // type
  6137. part.Shape.PathCurve = (byte)Extrusion.Curve1;
  6138. SetPrimitiveShapeParams(part, map, face);
  6139. break;
  6140. }
  6141. break;
  6142. case (int)ScriptBaseClass.PRIM_TEXTURE:
  6143. if (remain < 5)
  6144. return;
  6145. face=(int)rules.GetLSLIntegerItem(idx++);
  6146. string tex=rules.Data[idx++].ToString();
  6147. LSL_Vector repeats=rules.GetVector3Item(idx++);
  6148. LSL_Vector offsets=rules.GetVector3Item(idx++);
  6149. double rotation=(double)rules.GetLSLFloatItem(idx++);
  6150. SetTexture(part, tex, face);
  6151. ScaleTexture(part, repeats.x, repeats.y, face);
  6152. OffsetTexture(part, offsets.x, offsets.y, face);
  6153. RotateTexture(part, rotation, face);
  6154. break;
  6155. case (int)ScriptBaseClass.PRIM_COLOR:
  6156. if (remain < 3)
  6157. return;
  6158. face=(int)rules.GetLSLIntegerItem(idx++);
  6159. LSL_Vector color=rules.GetVector3Item(idx++);
  6160. double alpha=(double)rules.GetLSLFloatItem(idx++);
  6161. part.SetFaceColor(new Vector3((float)color.x, (float)color.y, (float)color.z), face);
  6162. SetAlpha(part, alpha, face);
  6163. break;
  6164. case (int)ScriptBaseClass.PRIM_FLEXIBLE:
  6165. if (remain < 7)
  6166. return;
  6167. bool flexi = rules.GetLSLIntegerItem(idx++);
  6168. int softness = rules.GetLSLIntegerItem(idx++);
  6169. float gravity = (float)rules.GetLSLFloatItem(idx++);
  6170. float friction = (float)rules.GetLSLFloatItem(idx++);
  6171. float wind = (float)rules.GetLSLFloatItem(idx++);
  6172. float tension = (float)rules.GetLSLFloatItem(idx++);
  6173. LSL_Vector force = rules.GetVector3Item(idx++);
  6174. SetFlexi(part, flexi, softness, gravity, friction, wind, tension, force);
  6175. break;
  6176. case (int)ScriptBaseClass.PRIM_POINT_LIGHT:
  6177. if (remain < 5)
  6178. return;
  6179. bool light = rules.GetLSLIntegerItem(idx++);
  6180. LSL_Vector lightcolor = rules.GetVector3Item(idx++);
  6181. float intensity = (float)rules.GetLSLFloatItem(idx++);
  6182. float radius = (float)rules.GetLSLFloatItem(idx++);
  6183. float falloff = (float)rules.GetLSLFloatItem(idx++);
  6184. SetPointLight(part, light, lightcolor, intensity, radius, falloff);
  6185. break;
  6186. case (int)ScriptBaseClass.PRIM_GLOW:
  6187. if (remain < 2)
  6188. return;
  6189. face = rules.GetLSLIntegerItem(idx++);
  6190. float glow = (float)rules.GetLSLFloatItem(idx++);
  6191. SetGlow(part, face, glow);
  6192. break;
  6193. case (int)ScriptBaseClass.PRIM_BUMP_SHINY:
  6194. if (remain < 3)
  6195. return;
  6196. face = (int)rules.GetLSLIntegerItem(idx++);
  6197. int shiny = (int)rules.GetLSLIntegerItem(idx++);
  6198. Bumpiness bump = (Bumpiness)Convert.ToByte((int)rules.GetLSLIntegerItem(idx++));
  6199. SetShiny(part, face, shiny, bump);
  6200. break;
  6201. case (int)ScriptBaseClass.PRIM_FULLBRIGHT:
  6202. if (remain < 2)
  6203. return;
  6204. face = rules.GetLSLIntegerItem(idx++);
  6205. bool st = rules.GetLSLIntegerItem(idx++);
  6206. SetFullBright(part, face , st);
  6207. break;
  6208. case (int)ScriptBaseClass.PRIM_MATERIAL:
  6209. if (remain < 1)
  6210. return;
  6211. int mat = rules.GetLSLIntegerItem(idx++);
  6212. if (mat < 0 || mat > 7)
  6213. return;
  6214. part.Material = Convert.ToByte(mat);
  6215. break;
  6216. case (int)ScriptBaseClass.PRIM_PHANTOM:
  6217. if (remain < 1)
  6218. return;
  6219. string ph = rules.Data[idx++].ToString();
  6220. bool phantom;
  6221. if (ph.Equals("1"))
  6222. phantom = true;
  6223. else
  6224. phantom = false;
  6225. part.ScriptSetPhantomStatus(phantom);
  6226. break;
  6227. case (int)ScriptBaseClass.PRIM_PHYSICS:
  6228. if (remain < 1)
  6229. return;
  6230. string phy = rules.Data[idx++].ToString();
  6231. bool physics;
  6232. if (phy.Equals("1"))
  6233. physics = true;
  6234. else
  6235. physics = false;
  6236. part.ScriptSetPhysicsStatus(physics);
  6237. break;
  6238. case (int)ScriptBaseClass.PRIM_TEMP_ON_REZ:
  6239. if (remain < 1)
  6240. return;
  6241. string temp = rules.Data[idx++].ToString();
  6242. bool tempOnRez;
  6243. if (temp.Equals("1"))
  6244. tempOnRez = true;
  6245. else
  6246. tempOnRez = false;
  6247. part.ScriptSetTemporaryStatus(tempOnRez);
  6248. break;
  6249. case (int)ScriptBaseClass.PRIM_TEXGEN:
  6250. if (remain < 2)
  6251. return;
  6252. //face,type
  6253. face = rules.GetLSLIntegerItem(idx++);
  6254. int style = rules.GetLSLIntegerItem(idx++);
  6255. SetTexGen(part, face, style);
  6256. break;
  6257. case (int)ScriptBaseClass.PRIM_TEXT:
  6258. if (remain < 3)
  6259. return;
  6260. string primText = rules.GetLSLStringItem(idx++);
  6261. LSL_Vector primTextColor = rules.GetVector3Item(idx++);
  6262. LSL_Float primTextAlpha = rules.GetLSLFloatItem(idx++);
  6263. Vector3 av3 = new Vector3(Util.Clip((float)primTextColor.x, 0.0f, 1.0f),
  6264. Util.Clip((float)primTextColor.y, 0.0f, 1.0f),
  6265. Util.Clip((float)primTextColor.z, 0.0f, 1.0f));
  6266. part.SetText(primText, av3, Util.Clip((float)primTextAlpha, 0.0f, 1.0f));
  6267. break;
  6268. case (int)ScriptBaseClass.PRIM_NAME:
  6269. if (remain < 1)
  6270. return;
  6271. string primName = rules.GetLSLStringItem(idx++);
  6272. part.Name = primName;
  6273. break;
  6274. case (int)ScriptBaseClass.PRIM_DESC:
  6275. if (remain < 1)
  6276. return;
  6277. string primDesc = rules.GetLSLStringItem(idx++);
  6278. part.Description = primDesc;
  6279. break;
  6280. case (int)ScriptBaseClass.PRIM_ROT_LOCAL:
  6281. if (remain < 1)
  6282. return;
  6283. LSL_Rotation lr = rules.GetQuaternionItem(idx++);
  6284. SetRot(part, Rot2Quaternion(lr));
  6285. break;
  6286. }
  6287. }
  6288. }
  6289. public LSL_String llStringToBase64(string str)
  6290. {
  6291. m_host.AddScriptLPS(1);
  6292. try
  6293. {
  6294. byte[] encData_byte = new byte[str.Length];
  6295. encData_byte = Util.UTF8.GetBytes(str);
  6296. string encodedData = Convert.ToBase64String(encData_byte);
  6297. return encodedData;
  6298. }
  6299. catch (Exception e)
  6300. {
  6301. throw new Exception("Error in base64Encode" + e.Message);
  6302. }
  6303. }
  6304. public LSL_String llBase64ToString(string str)
  6305. {
  6306. m_host.AddScriptLPS(1);
  6307. try
  6308. {
  6309. return Util.Base64ToString(str);
  6310. }
  6311. catch (Exception e)
  6312. {
  6313. throw new Exception("Error in base64Decode" + e.Message);
  6314. }
  6315. }
  6316. public LSL_String llXorBase64Strings(string str1, string str2)
  6317. {
  6318. m_host.AddScriptLPS(1);
  6319. Deprecated("llXorBase64Strings");
  6320. ScriptSleep(300);
  6321. return String.Empty;
  6322. }
  6323. public void llRemoteDataSetRegion()
  6324. {
  6325. m_host.AddScriptLPS(1);
  6326. Deprecated("llRemoteDataSetRegion");
  6327. }
  6328. public LSL_Float llLog10(double val)
  6329. {
  6330. m_host.AddScriptLPS(1);
  6331. return (double)Math.Log10(val);
  6332. }
  6333. public LSL_Float llLog(double val)
  6334. {
  6335. m_host.AddScriptLPS(1);
  6336. return (double)Math.Log(val);
  6337. }
  6338. public LSL_List llGetAnimationList(string id)
  6339. {
  6340. m_host.AddScriptLPS(1);
  6341. LSL_List l = new LSL_List();
  6342. ScenePresence av = World.GetScenePresence((UUID)id);
  6343. if (av == null || av.IsChildAgent) // only if in the region
  6344. return l;
  6345. UUID[] anims;
  6346. anims = av.Animator.GetAnimationArray();
  6347. foreach (UUID foo in anims)
  6348. l.Add(foo.ToString());
  6349. return l;
  6350. }
  6351. public void llSetParcelMusicURL(string url)
  6352. {
  6353. m_host.AddScriptLPS(1);
  6354. ILandObject land = World.LandChannel.GetLandObject(m_host.AbsolutePosition.X, m_host.AbsolutePosition.Y);
  6355. if (land.LandData.OwnerID != m_host.OwnerID)
  6356. return;
  6357. land.SetMusicUrl(url);
  6358. ScriptSleep(2000);
  6359. }
  6360. public LSL_Vector llGetRootPosition()
  6361. {
  6362. m_host.AddScriptLPS(1);
  6363. return new LSL_Vector(m_host.ParentGroup.AbsolutePosition.X, m_host.ParentGroup.AbsolutePosition.Y,
  6364. m_host.ParentGroup.AbsolutePosition.Z);
  6365. }
  6366. /// <summary>
  6367. /// http://lslwiki.net/lslwiki/wakka.php?wakka=llGetRot
  6368. /// http://lslwiki.net/lslwiki/wakka.php?wakka=ChildRotation
  6369. /// Also tested in sl in regards to the behaviour in attachments/mouselook
  6370. /// In the root prim:-
  6371. /// Returns the object rotation if not attached
  6372. /// Returns the avatars rotation if attached
  6373. /// Returns the camera rotation if attached and the avatar is in mouselook
  6374. /// </summary>
  6375. public LSL_Rotation llGetRootRotation()
  6376. {
  6377. m_host.AddScriptLPS(1);
  6378. Quaternion q;
  6379. if (m_host.ParentGroup.RootPart.AttachmentPoint != 0)
  6380. {
  6381. ScenePresence avatar = World.GetScenePresence(m_host.AttachedAvatar);
  6382. if (avatar != null)
  6383. if ((avatar.AgentControlFlags & (uint)AgentManager.ControlFlags.AGENT_CONTROL_MOUSELOOK) != 0)
  6384. q = avatar.CameraRotation; // Mouselook
  6385. else
  6386. q = avatar.Rotation; // Currently infrequently updated so may be inaccurate
  6387. else
  6388. q = m_host.ParentGroup.GroupRotation; // Likely never get here but just in case
  6389. }
  6390. else
  6391. q = m_host.ParentGroup.GroupRotation; // just the group rotation
  6392. return new LSL_Rotation(q.X, q.Y, q.Z, q.W);
  6393. }
  6394. public LSL_String llGetObjectDesc()
  6395. {
  6396. return m_host.Description!=null?m_host.Description:String.Empty;
  6397. }
  6398. public void llSetObjectDesc(string desc)
  6399. {
  6400. m_host.AddScriptLPS(1);
  6401. m_host.Description = desc!=null?desc:String.Empty;
  6402. }
  6403. public LSL_String llGetCreator()
  6404. {
  6405. m_host.AddScriptLPS(1);
  6406. return m_host.CreatorID.ToString();
  6407. }
  6408. public LSL_String llGetTimestamp()
  6409. {
  6410. m_host.AddScriptLPS(1);
  6411. return DateTime.Now.ToUniversalTime().ToString("yyyy-MM-ddTHH:mm:ss.fffffffZ");
  6412. }
  6413. public LSL_Integer llGetNumberOfPrims()
  6414. {
  6415. m_host.AddScriptLPS(1);
  6416. int avatarCount = 0;
  6417. World.ForEachScenePresence(delegate(ScenePresence presence)
  6418. {
  6419. if (!presence.IsChildAgent && presence.ParentID != 0 && m_host.ParentGroup.HasChildPrim(presence.ParentID))
  6420. avatarCount++;
  6421. });
  6422. return m_host.ParentGroup.PrimCount + avatarCount;
  6423. }
  6424. /// <summary>
  6425. /// A partial implementation.
  6426. /// http://lslwiki.net/lslwiki/wakka.php?wakka=llGetBoundingBox
  6427. /// So far only valid for standing/flying/ground sitting avatars and single prim objects.
  6428. /// If the object has multiple prims and/or a sitting avatar then the bounding
  6429. /// box is for the root prim only.
  6430. /// </summary>
  6431. public LSL_List llGetBoundingBox(string obj)
  6432. {
  6433. m_host.AddScriptLPS(1);
  6434. UUID objID = UUID.Zero;
  6435. LSL_List result = new LSL_List();
  6436. if (!UUID.TryParse(obj, out objID))
  6437. {
  6438. result.Add(new LSL_Vector());
  6439. result.Add(new LSL_Vector());
  6440. return result;
  6441. }
  6442. ScenePresence presence = World.GetScenePresence(objID);
  6443. if (presence != null)
  6444. {
  6445. if (presence.ParentID == 0) // not sat on an object
  6446. {
  6447. LSL_Vector lower;
  6448. LSL_Vector upper;
  6449. if (presence.Animator.Animations.DefaultAnimation.AnimID
  6450. == AnimationSet.Animations.AnimsUUID["SIT_GROUND_CONSTRAINED"])
  6451. {
  6452. // This is for ground sitting avatars
  6453. float height = presence.Appearance.AvatarHeight / 2.66666667f;
  6454. lower = new LSL_Vector(-0.3375f, -0.45f, height * -1.0f);
  6455. upper = new LSL_Vector(0.3375f, 0.45f, 0.0f);
  6456. }
  6457. else
  6458. {
  6459. // This is for standing/flying avatars
  6460. float height = presence.Appearance.AvatarHeight / 2.0f;
  6461. lower = new LSL_Vector(-0.225f, -0.3f, height * -1.0f);
  6462. upper = new LSL_Vector(0.225f, 0.3f, height + 0.05f);
  6463. }
  6464. result.Add(lower);
  6465. result.Add(upper);
  6466. return result;
  6467. }
  6468. else
  6469. {
  6470. // sitting on an object so we need the bounding box of that
  6471. // which should include the avatar so set the UUID to the
  6472. // UUID of the object the avatar is sat on and allow it to fall through
  6473. // to processing an object
  6474. SceneObjectPart p = World.GetSceneObjectPart(presence.ParentID);
  6475. objID = p.UUID;
  6476. }
  6477. }
  6478. SceneObjectPart part = World.GetSceneObjectPart(objID);
  6479. // Currently only works for single prims without a sitting avatar
  6480. if (part != null)
  6481. {
  6482. Vector3 halfSize = part.Scale / 2.0f;
  6483. LSL_Vector lower = new LSL_Vector(halfSize.X * -1.0f, halfSize.Y * -1.0f, halfSize.Z * -1.0f);
  6484. LSL_Vector upper = new LSL_Vector(halfSize.X, halfSize.Y, halfSize.Z);
  6485. result.Add(lower);
  6486. result.Add(upper);
  6487. return result;
  6488. }
  6489. // Not found so return empty values
  6490. result.Add(new LSL_Vector());
  6491. result.Add(new LSL_Vector());
  6492. return result;
  6493. }
  6494. public LSL_Vector llGetGeometricCenter()
  6495. {
  6496. return new LSL_Vector(m_host.GetGeometricCenter().X, m_host.GetGeometricCenter().Y, m_host.GetGeometricCenter().Z);
  6497. }
  6498. public LSL_List llGetPrimitiveParams(LSL_List rules)
  6499. {
  6500. m_host.AddScriptLPS(1);
  6501. return GetLinkPrimitiveParams(m_host, rules);
  6502. }
  6503. public LSL_List llGetLinkPrimitiveParams(int linknumber, LSL_List rules)
  6504. {
  6505. m_host.AddScriptLPS(1);
  6506. List<SceneObjectPart> parts = GetLinkParts(linknumber);
  6507. LSL_List res = new LSL_List();
  6508. foreach (var part in parts)
  6509. {
  6510. LSL_List partRes = GetLinkPrimitiveParams(part, rules);
  6511. res += partRes;
  6512. }
  6513. return res;
  6514. }
  6515. public LSL_List GetLinkPrimitiveParams(SceneObjectPart part, LSL_List rules)
  6516. {
  6517. LSL_List res = new LSL_List();
  6518. int idx=0;
  6519. while (idx < rules.Length)
  6520. {
  6521. int code=(int)rules.GetLSLIntegerItem(idx++);
  6522. int remain=rules.Length-idx;
  6523. switch (code)
  6524. {
  6525. case (int)ScriptBaseClass.PRIM_MATERIAL:
  6526. res.Add(new LSL_Integer(part.Material));
  6527. break;
  6528. case (int)ScriptBaseClass.PRIM_PHYSICS:
  6529. if ((part.GetEffectiveObjectFlags() & (uint)PrimFlags.Physics) != 0)
  6530. res.Add(new LSL_Integer(1));
  6531. else
  6532. res.Add(new LSL_Integer(0));
  6533. break;
  6534. case (int)ScriptBaseClass.PRIM_TEMP_ON_REZ:
  6535. if ((part.GetEffectiveObjectFlags() & (uint)PrimFlags.TemporaryOnRez) != 0)
  6536. res.Add(new LSL_Integer(1));
  6537. else
  6538. res.Add(new LSL_Integer(0));
  6539. break;
  6540. case (int)ScriptBaseClass.PRIM_PHANTOM:
  6541. if ((part.GetEffectiveObjectFlags() & (uint)PrimFlags.Phantom) != 0)
  6542. res.Add(new LSL_Integer(1));
  6543. else
  6544. res.Add(new LSL_Integer(0));
  6545. break;
  6546. case (int)ScriptBaseClass.PRIM_POSITION:
  6547. LSL_Vector v = new LSL_Vector(part.AbsolutePosition.X,
  6548. part.AbsolutePosition.Y,
  6549. part.AbsolutePosition.Z);
  6550. // For some reason, the part.AbsolutePosition.* values do not change if the
  6551. // linkset is rotated; they always reflect the child prim's world position
  6552. // as though the linkset is unrotated. This is incompatible behavior with SL's
  6553. // implementation, so will break scripts imported from there (not to mention it
  6554. // makes it more difficult to determine a child prim's actual inworld position).
  6555. if (part.ParentID != 0)
  6556. v = ((v - llGetRootPosition()) * llGetRootRotation()) + llGetRootPosition();
  6557. res.Add(v);
  6558. break;
  6559. case (int)ScriptBaseClass.PRIM_SIZE:
  6560. res.Add(new LSL_Vector(part.Scale.X,
  6561. part.Scale.Y,
  6562. part.Scale.Z));
  6563. break;
  6564. case (int)ScriptBaseClass.PRIM_ROTATION:
  6565. res.Add(GetPartRot(part));
  6566. break;
  6567. case (int)ScriptBaseClass.PRIM_TYPE:
  6568. // implementing box
  6569. PrimitiveBaseShape Shape = part.Shape;
  6570. int primType = (int)part.GetPrimType();
  6571. res.Add(new LSL_Integer(primType));
  6572. double topshearx = (double)(sbyte)Shape.PathShearX / 100.0; // Fix negative values for PathShearX
  6573. double topsheary = (double)(sbyte)Shape.PathShearY / 100.0; // and PathShearY.
  6574. switch (primType)
  6575. {
  6576. case ScriptBaseClass.PRIM_TYPE_BOX:
  6577. case ScriptBaseClass.PRIM_TYPE_CYLINDER:
  6578. case ScriptBaseClass.PRIM_TYPE_PRISM:
  6579. res.Add(new LSL_Integer(Shape.ProfileCurve));
  6580. res.Add(new LSL_Vector(Shape.ProfileBegin / 50000.0, 1 - Shape.ProfileEnd / 50000.0, 0));
  6581. res.Add(new LSL_Float(Shape.ProfileHollow / 50000.0));
  6582. res.Add(new LSL_Vector(Shape.PathTwistBegin / 100.0, Shape.PathTwist / 100.0, 0));
  6583. res.Add(new LSL_Vector(1 - (Shape.PathScaleX / 100.0 - 1), 1 - (Shape.PathScaleY / 100.0 - 1), 0));
  6584. res.Add(new LSL_Vector(topshearx, topsheary, 0));
  6585. break;
  6586. case ScriptBaseClass.PRIM_TYPE_SPHERE:
  6587. res.Add(new LSL_Integer(Shape.ProfileCurve));
  6588. res.Add(new LSL_Vector(Shape.PathBegin / 50000.0, 1 - Shape.PathEnd / 50000.0, 0));
  6589. res.Add(new LSL_Float(Shape.ProfileHollow / 50000.0));
  6590. res.Add(new LSL_Vector(Shape.PathTwistBegin / 100.0, Shape.PathTwist / 100.0, 0));
  6591. res.Add(new LSL_Vector(Shape.ProfileBegin / 50000.0, 1 - Shape.ProfileEnd / 50000.0, 0));
  6592. break;
  6593. case ScriptBaseClass.PRIM_TYPE_SCULPT:
  6594. res.Add(Shape.SculptTexture.ToString());
  6595. res.Add(new LSL_Integer(Shape.SculptType));
  6596. break;
  6597. case ScriptBaseClass.PRIM_TYPE_RING:
  6598. case ScriptBaseClass.PRIM_TYPE_TUBE:
  6599. case ScriptBaseClass.PRIM_TYPE_TORUS:
  6600. // holeshape
  6601. res.Add(new LSL_Integer(Shape.ProfileCurve));
  6602. // cut
  6603. res.Add(new LSL_Vector(Shape.PathBegin / 50000.0, 1 - Shape.PathEnd / 50000.0, 0));
  6604. // hollow
  6605. res.Add(new LSL_Float(Shape.ProfileHollow / 50000.0));
  6606. // twist
  6607. res.Add(new LSL_Vector(Shape.PathTwistBegin / 100.0, Shape.PathTwist / 100.0, 0));
  6608. // vector holesize
  6609. res.Add(new LSL_Vector(1 - (Shape.PathScaleX / 100.0 - 1), 1 - (Shape.PathScaleY / 100.0 - 1), 0));
  6610. // vector topshear
  6611. res.Add(new LSL_Vector(topshearx, topsheary, 0));
  6612. // vector profilecut
  6613. res.Add(new LSL_Vector(Shape.ProfileBegin / 50000.0, 1 - Shape.ProfileEnd / 50000.0, 0));
  6614. // vector tapera
  6615. res.Add(new LSL_Vector(Shape.PathTaperX / 100.0, Shape.PathTaperY / 100.0, 0));
  6616. // float revolutions
  6617. res.Add(new LSL_Float((Shape.PathRevolutions * 0.015) + 1.0)); // Slightly inaccurate, because an unsigned
  6618. // byte is being used to represent the entire
  6619. // range of floating-point values from 1.0
  6620. // through 4.0 (which is how SL does it).
  6621. // float radiusoffset
  6622. res.Add(new LSL_Float(Shape.PathRadiusOffset / 100.0));
  6623. // float skew
  6624. res.Add(new LSL_Float(Shape.PathSkew / 100.0));
  6625. break;
  6626. }
  6627. break;
  6628. case (int)ScriptBaseClass.PRIM_TEXTURE:
  6629. if (remain < 1)
  6630. return res;
  6631. int face = (int)rules.GetLSLIntegerItem(idx++);
  6632. Primitive.TextureEntry tex = part.Shape.Textures;
  6633. if (face == ScriptBaseClass.ALL_SIDES)
  6634. {
  6635. for (face = 0 ; face < GetNumberOfSides(part); face++)
  6636. {
  6637. Primitive.TextureEntryFace texface = tex.GetFace((uint)face);
  6638. res.Add(new LSL_String(texface.TextureID.ToString()));
  6639. res.Add(new LSL_Vector(texface.RepeatU,
  6640. texface.RepeatV,
  6641. 0));
  6642. res.Add(new LSL_Vector(texface.OffsetU,
  6643. texface.OffsetV,
  6644. 0));
  6645. res.Add(new LSL_Float(texface.Rotation));
  6646. }
  6647. }
  6648. else
  6649. {
  6650. if (face >= 0 && face < GetNumberOfSides(part))
  6651. {
  6652. Primitive.TextureEntryFace texface = tex.GetFace((uint)face);
  6653. res.Add(new LSL_String(texface.TextureID.ToString()));
  6654. res.Add(new LSL_Vector(texface.RepeatU,
  6655. texface.RepeatV,
  6656. 0));
  6657. res.Add(new LSL_Vector(texface.OffsetU,
  6658. texface.OffsetV,
  6659. 0));
  6660. res.Add(new LSL_Float(texface.Rotation));
  6661. }
  6662. }
  6663. break;
  6664. case (int)ScriptBaseClass.PRIM_COLOR:
  6665. if (remain < 1)
  6666. return res;
  6667. face=(int)rules.GetLSLIntegerItem(idx++);
  6668. tex = part.Shape.Textures;
  6669. Color4 texcolor;
  6670. if (face == ScriptBaseClass.ALL_SIDES)
  6671. {
  6672. for (face = 0 ; face < GetNumberOfSides(part); face++)
  6673. {
  6674. texcolor = tex.GetFace((uint)face).RGBA;
  6675. res.Add(new LSL_Vector(texcolor.R,
  6676. texcolor.G,
  6677. texcolor.B));
  6678. res.Add(new LSL_Float(texcolor.A));
  6679. }
  6680. }
  6681. else
  6682. {
  6683. texcolor = tex.GetFace((uint)face).RGBA;
  6684. res.Add(new LSL_Vector(texcolor.R,
  6685. texcolor.G,
  6686. texcolor.B));
  6687. res.Add(new LSL_Float(texcolor.A));
  6688. }
  6689. break;
  6690. case (int)ScriptBaseClass.PRIM_BUMP_SHINY:
  6691. if (remain < 1)
  6692. return res;
  6693. face=(int)rules.GetLSLIntegerItem(idx++);
  6694. tex = part.Shape.Textures;
  6695. if (face == ScriptBaseClass.ALL_SIDES)
  6696. {
  6697. for (face = 0; face < GetNumberOfSides(part); face++)
  6698. {
  6699. Primitive.TextureEntryFace texface = tex.GetFace((uint)face);
  6700. // Convert Shininess to PRIM_SHINY_*
  6701. res.Add(new LSL_Integer((uint)texface.Shiny >> 6));
  6702. // PRIM_BUMP_*
  6703. res.Add(new LSL_Integer((int)texface.Bump));
  6704. }
  6705. }
  6706. else
  6707. {
  6708. if (face >= 0 && face < GetNumberOfSides(part))
  6709. {
  6710. Primitive.TextureEntryFace texface = tex.GetFace((uint)face);
  6711. // Convert Shininess to PRIM_SHINY_*
  6712. res.Add(new LSL_Integer((uint)texface.Shiny >> 6));
  6713. // PRIM_BUMP_*
  6714. res.Add(new LSL_Integer((int)texface.Bump));
  6715. }
  6716. }
  6717. break;
  6718. case (int)ScriptBaseClass.PRIM_FULLBRIGHT:
  6719. if (remain < 1)
  6720. return res;
  6721. face=(int)rules.GetLSLIntegerItem(idx++);
  6722. tex = part.Shape.Textures;
  6723. if (face == ScriptBaseClass.ALL_SIDES)
  6724. {
  6725. for (face = 0; face < GetNumberOfSides(part); face++)
  6726. {
  6727. Primitive.TextureEntryFace texface = tex.GetFace((uint)face);
  6728. res.Add(new LSL_Integer(texface.Fullbright ? 1 : 0));
  6729. }
  6730. }
  6731. else
  6732. {
  6733. if (face >= 0 && face < GetNumberOfSides(part))
  6734. {
  6735. Primitive.TextureEntryFace texface = tex.GetFace((uint)face);
  6736. res.Add(new LSL_Integer(texface.Fullbright ? 1 : 0));
  6737. }
  6738. }
  6739. break;
  6740. case (int)ScriptBaseClass.PRIM_FLEXIBLE:
  6741. PrimitiveBaseShape shape = part.Shape;
  6742. if (shape.FlexiEntry)
  6743. res.Add(new LSL_Integer(1)); // active
  6744. else
  6745. res.Add(new LSL_Integer(0));
  6746. res.Add(new LSL_Integer(shape.FlexiSoftness));// softness
  6747. res.Add(new LSL_Float(shape.FlexiGravity)); // gravity
  6748. res.Add(new LSL_Float(shape.FlexiDrag)); // friction
  6749. res.Add(new LSL_Float(shape.FlexiWind)); // wind
  6750. res.Add(new LSL_Float(shape.FlexiTension)); // tension
  6751. res.Add(new LSL_Vector(shape.FlexiForceX, // force
  6752. shape.FlexiForceY,
  6753. shape.FlexiForceZ));
  6754. break;
  6755. case (int)ScriptBaseClass.PRIM_TEXGEN:
  6756. if (remain < 1)
  6757. return res;
  6758. face=(int)rules.GetLSLIntegerItem(idx++);
  6759. tex = part.Shape.Textures;
  6760. if (face == ScriptBaseClass.ALL_SIDES)
  6761. {
  6762. for (face = 0; face < GetNumberOfSides(part); face++)
  6763. {
  6764. MappingType texgen = tex.GetFace((uint)face).TexMapType;
  6765. // Convert MappingType to PRIM_TEXGEN_DEFAULT, PRIM_TEXGEN_PLANAR etc.
  6766. res.Add(new LSL_Integer((uint)texgen >> 1));
  6767. }
  6768. }
  6769. else
  6770. {
  6771. if (face >= 0 && face < GetNumberOfSides(part))
  6772. {
  6773. MappingType texgen = tex.GetFace((uint)face).TexMapType;
  6774. res.Add(new LSL_Integer((uint)texgen >> 1));
  6775. }
  6776. }
  6777. break;
  6778. case (int)ScriptBaseClass.PRIM_POINT_LIGHT:
  6779. shape = part.Shape;
  6780. if (shape.LightEntry)
  6781. res.Add(new LSL_Integer(1)); // active
  6782. else
  6783. res.Add(new LSL_Integer(0));
  6784. res.Add(new LSL_Vector(shape.LightColorR, // color
  6785. shape.LightColorG,
  6786. shape.LightColorB));
  6787. res.Add(new LSL_Float(shape.LightIntensity)); // intensity
  6788. res.Add(new LSL_Float(shape.LightRadius)); // radius
  6789. res.Add(new LSL_Float(shape.LightFalloff)); // falloff
  6790. break;
  6791. case (int)ScriptBaseClass.PRIM_GLOW:
  6792. if (remain < 1)
  6793. return res;
  6794. face=(int)rules.GetLSLIntegerItem(idx++);
  6795. tex = part.Shape.Textures;
  6796. if (face == ScriptBaseClass.ALL_SIDES)
  6797. {
  6798. for (face = 0; face < GetNumberOfSides(part); face++)
  6799. {
  6800. Primitive.TextureEntryFace texface = tex.GetFace((uint)face);
  6801. res.Add(new LSL_Float(texface.Glow));
  6802. }
  6803. }
  6804. else
  6805. {
  6806. if (face >= 0 && face < GetNumberOfSides(part))
  6807. {
  6808. Primitive.TextureEntryFace texface = tex.GetFace((uint)face);
  6809. res.Add(new LSL_Float(texface.Glow));
  6810. }
  6811. }
  6812. break;
  6813. case (int)ScriptBaseClass.PRIM_TEXT:
  6814. Color4 textColor = part.GetTextColor();
  6815. res.Add(part.Text);
  6816. res.Add(new LSL_Vector(textColor.R,
  6817. textColor.G,
  6818. textColor.B));
  6819. res.Add(new LSL_Float(textColor.A));
  6820. break;
  6821. case (int)ScriptBaseClass.PRIM_NAME:
  6822. res.Add(part.Name);
  6823. break;
  6824. case (int)ScriptBaseClass.PRIM_DESC:
  6825. res.Add(part.Description);
  6826. break;
  6827. case (int)ScriptBaseClass.PRIM_ROT_LOCAL:
  6828. res.Add(new LSL_Rotation(part.RotationOffset.X, part.RotationOffset.Y, part.RotationOffset.Z, part.RotationOffset.W));
  6829. break;
  6830. }
  6831. }
  6832. return res;
  6833. }
  6834. public LSL_List llGetPrimMediaParams(int face, LSL_List rules)
  6835. {
  6836. m_host.AddScriptLPS(1);
  6837. ScriptSleep(1000);
  6838. // LSL Spec http://wiki.secondlife.com/wiki/LlGetPrimMediaParams says to fail silently if face is invalid
  6839. // TODO: Need to correctly handle case where a face has no media (which gives back an empty list).
  6840. // Assuming silently fail means give back an empty list. Ideally, need to check this.
  6841. if (face < 0 || face > m_host.GetNumberOfSides() - 1)
  6842. return new LSL_List();
  6843. return GetPrimMediaParams(face, rules);
  6844. }
  6845. private LSL_List GetPrimMediaParams(int face, LSL_List rules)
  6846. {
  6847. IMoapModule module = m_ScriptEngine.World.RequestModuleInterface<IMoapModule>();
  6848. if (null == module)
  6849. throw new Exception("Media on a prim functions not available");
  6850. MediaEntry me = module.GetMediaEntry(m_host, face);
  6851. // As per http://wiki.secondlife.com/wiki/LlGetPrimMediaParams
  6852. if (null == me)
  6853. return new LSL_List();
  6854. LSL_List res = new LSL_List();
  6855. for (int i = 0; i < rules.Length; i++)
  6856. {
  6857. int code = (int)rules.GetLSLIntegerItem(i);
  6858. switch (code)
  6859. {
  6860. case ScriptBaseClass.PRIM_MEDIA_ALT_IMAGE_ENABLE:
  6861. // Not implemented
  6862. res.Add(new LSL_Integer(0));
  6863. break;
  6864. case ScriptBaseClass.PRIM_MEDIA_CONTROLS:
  6865. if (me.Controls == MediaControls.Standard)
  6866. res.Add(new LSL_Integer(ScriptBaseClass.PRIM_MEDIA_CONTROLS_STANDARD));
  6867. else
  6868. res.Add(new LSL_Integer(ScriptBaseClass.PRIM_MEDIA_CONTROLS_MINI));
  6869. break;
  6870. case ScriptBaseClass.PRIM_MEDIA_CURRENT_URL:
  6871. res.Add(new LSL_String(me.CurrentURL));
  6872. break;
  6873. case ScriptBaseClass.PRIM_MEDIA_HOME_URL:
  6874. res.Add(new LSL_String(me.HomeURL));
  6875. break;
  6876. case ScriptBaseClass.PRIM_MEDIA_AUTO_LOOP:
  6877. res.Add(me.AutoLoop ? ScriptBaseClass.TRUE : ScriptBaseClass.FALSE);
  6878. break;
  6879. case ScriptBaseClass.PRIM_MEDIA_AUTO_PLAY:
  6880. res.Add(me.AutoPlay ? ScriptBaseClass.TRUE : ScriptBaseClass.FALSE);
  6881. break;
  6882. case ScriptBaseClass.PRIM_MEDIA_AUTO_SCALE:
  6883. res.Add(me.AutoScale ? ScriptBaseClass.TRUE : ScriptBaseClass.FALSE);
  6884. break;
  6885. case ScriptBaseClass.PRIM_MEDIA_AUTO_ZOOM:
  6886. res.Add(me.AutoZoom ? ScriptBaseClass.TRUE : ScriptBaseClass.FALSE);
  6887. break;
  6888. case ScriptBaseClass.PRIM_MEDIA_FIRST_CLICK_INTERACT:
  6889. res.Add(me.InteractOnFirstClick ? ScriptBaseClass.TRUE : ScriptBaseClass.FALSE);
  6890. break;
  6891. case ScriptBaseClass.PRIM_MEDIA_WIDTH_PIXELS:
  6892. res.Add(new LSL_Integer(me.Width));
  6893. break;
  6894. case ScriptBaseClass.PRIM_MEDIA_HEIGHT_PIXELS:
  6895. res.Add(new LSL_Integer(me.Height));
  6896. break;
  6897. case ScriptBaseClass.PRIM_MEDIA_WHITELIST_ENABLE:
  6898. res.Add(me.EnableWhiteList ? ScriptBaseClass.TRUE : ScriptBaseClass.FALSE);
  6899. break;
  6900. case ScriptBaseClass.PRIM_MEDIA_WHITELIST:
  6901. string[] urls = (string[])me.WhiteList.Clone();
  6902. for (int j = 0; j < urls.Length; j++)
  6903. urls[j] = Uri.EscapeDataString(urls[j]);
  6904. res.Add(new LSL_String(string.Join(", ", urls)));
  6905. break;
  6906. case ScriptBaseClass.PRIM_MEDIA_PERMS_INTERACT:
  6907. res.Add(new LSL_Integer((int)me.InteractPermissions));
  6908. break;
  6909. case ScriptBaseClass.PRIM_MEDIA_PERMS_CONTROL:
  6910. res.Add(new LSL_Integer((int)me.ControlPermissions));
  6911. break;
  6912. }
  6913. }
  6914. return res;
  6915. }
  6916. public LSL_Integer llSetPrimMediaParams(int face, LSL_List rules)
  6917. {
  6918. m_host.AddScriptLPS(1);
  6919. ScriptSleep(1000);
  6920. // LSL Spec http://wiki.secondlife.com/wiki/LlSetPrimMediaParams says to fail silently if face is invalid
  6921. // Assuming silently fail means sending back LSL_STATUS_OK. Ideally, need to check this.
  6922. // Don't perform the media check directly
  6923. if (face < 0 || face > m_host.GetNumberOfSides() - 1)
  6924. return ScriptBaseClass.LSL_STATUS_OK;
  6925. return SetPrimMediaParams(face, rules);
  6926. }
  6927. private LSL_Integer SetPrimMediaParams(int face, LSL_List rules)
  6928. {
  6929. IMoapModule module = m_ScriptEngine.World.RequestModuleInterface<IMoapModule>();
  6930. if (null == module)
  6931. throw new Exception("Media on a prim functions not available");
  6932. MediaEntry me = module.GetMediaEntry(m_host, face);
  6933. if (null == me)
  6934. me = new MediaEntry();
  6935. int i = 0;
  6936. while (i < rules.Length - 1)
  6937. {
  6938. int code = rules.GetLSLIntegerItem(i++);
  6939. switch (code)
  6940. {
  6941. case ScriptBaseClass.PRIM_MEDIA_ALT_IMAGE_ENABLE:
  6942. me.EnableAlterntiveImage = (rules.GetLSLIntegerItem(i++) != 0 ? true : false);
  6943. break;
  6944. case ScriptBaseClass.PRIM_MEDIA_CONTROLS:
  6945. int v = rules.GetLSLIntegerItem(i++);
  6946. if (ScriptBaseClass.PRIM_MEDIA_CONTROLS_STANDARD == v)
  6947. me.Controls = MediaControls.Standard;
  6948. else
  6949. me.Controls = MediaControls.Mini;
  6950. break;
  6951. case ScriptBaseClass.PRIM_MEDIA_CURRENT_URL:
  6952. me.CurrentURL = rules.GetLSLStringItem(i++);
  6953. break;
  6954. case ScriptBaseClass.PRIM_MEDIA_HOME_URL:
  6955. me.HomeURL = rules.GetLSLStringItem(i++);
  6956. break;
  6957. case ScriptBaseClass.PRIM_MEDIA_AUTO_LOOP:
  6958. me.AutoLoop = (ScriptBaseClass.TRUE == rules.GetLSLIntegerItem(i++) ? true : false);
  6959. break;
  6960. case ScriptBaseClass.PRIM_MEDIA_AUTO_PLAY:
  6961. me.AutoPlay = (ScriptBaseClass.TRUE == rules.GetLSLIntegerItem(i++) ? true : false);
  6962. break;
  6963. case ScriptBaseClass.PRIM_MEDIA_AUTO_SCALE:
  6964. me.AutoScale = (ScriptBaseClass.TRUE == rules.GetLSLIntegerItem(i++) ? true : false);
  6965. break;
  6966. case ScriptBaseClass.PRIM_MEDIA_AUTO_ZOOM:
  6967. me.AutoZoom = (ScriptBaseClass.TRUE == rules.GetLSLIntegerItem(i++) ? true : false);
  6968. break;
  6969. case ScriptBaseClass.PRIM_MEDIA_FIRST_CLICK_INTERACT:
  6970. me.InteractOnFirstClick = (ScriptBaseClass.TRUE == rules.GetLSLIntegerItem(i++) ? true : false);
  6971. break;
  6972. case ScriptBaseClass.PRIM_MEDIA_WIDTH_PIXELS:
  6973. me.Width = (int)rules.GetLSLIntegerItem(i++);
  6974. break;
  6975. case ScriptBaseClass.PRIM_MEDIA_HEIGHT_PIXELS:
  6976. me.Height = (int)rules.GetLSLIntegerItem(i++);
  6977. break;
  6978. case ScriptBaseClass.PRIM_MEDIA_WHITELIST_ENABLE:
  6979. me.EnableWhiteList = (ScriptBaseClass.TRUE == rules.GetLSLIntegerItem(i++) ? true : false);
  6980. break;
  6981. case ScriptBaseClass.PRIM_MEDIA_WHITELIST:
  6982. string[] rawWhiteListUrls = rules.GetLSLStringItem(i++).ToString().Split(new char[] { ',' });
  6983. List<string> whiteListUrls = new List<string>();
  6984. Array.ForEach(
  6985. rawWhiteListUrls, delegate(string rawUrl) { whiteListUrls.Add(rawUrl.Trim()); });
  6986. me.WhiteList = whiteListUrls.ToArray();
  6987. break;
  6988. case ScriptBaseClass.PRIM_MEDIA_PERMS_INTERACT:
  6989. me.InteractPermissions = (MediaPermission)(byte)(int)rules.GetLSLIntegerItem(i++);
  6990. break;
  6991. case ScriptBaseClass.PRIM_MEDIA_PERMS_CONTROL:
  6992. me.ControlPermissions = (MediaPermission)(byte)(int)rules.GetLSLIntegerItem(i++);
  6993. break;
  6994. }
  6995. }
  6996. module.SetMediaEntry(m_host, face, me);
  6997. return ScriptBaseClass.LSL_STATUS_OK;
  6998. }
  6999. public LSL_Integer llClearPrimMedia(LSL_Integer face)
  7000. {
  7001. m_host.AddScriptLPS(1);
  7002. ScriptSleep(1000);
  7003. // LSL Spec http://wiki.secondlife.com/wiki/LlClearPrimMedia says to fail silently if face is invalid
  7004. // Assuming silently fail means sending back LSL_STATUS_OK. Ideally, need to check this.
  7005. // FIXME: Don't perform the media check directly
  7006. if (face < 0 || face > m_host.GetNumberOfSides() - 1)
  7007. return ScriptBaseClass.LSL_STATUS_OK;
  7008. IMoapModule module = m_ScriptEngine.World.RequestModuleInterface<IMoapModule>();
  7009. if (null == module)
  7010. throw new Exception("Media on a prim functions not available");
  7011. module.ClearMediaEntry(m_host, face);
  7012. return ScriptBaseClass.LSL_STATUS_OK;
  7013. }
  7014. // <remarks>
  7015. // <para>
  7016. // The .NET definition of base 64 is:
  7017. // <list>
  7018. // <item>
  7019. // Significant: A-Z a-z 0-9 + -
  7020. // </item>
  7021. // <item>
  7022. // Whitespace: \t \n \r ' '
  7023. // </item>
  7024. // <item>
  7025. // Valueless: =
  7026. // </item>
  7027. // <item>
  7028. // End-of-string: \0 or '=='
  7029. // </item>
  7030. // </list>
  7031. // </para>
  7032. // <para>
  7033. // Each point in a base-64 string represents
  7034. // a 6 bit value. A 32-bit integer can be
  7035. // represented using 6 characters (with some
  7036. // redundancy).
  7037. // </para>
  7038. // <para>
  7039. // LSL requires a base64 string to be 8
  7040. // characters in length. LSL also uses '/'
  7041. // rather than '-' (MIME compliant).
  7042. // </para>
  7043. // <para>
  7044. // RFC 1341 used as a reference (as specified
  7045. // by the SecondLife Wiki).
  7046. // </para>
  7047. // <para>
  7048. // SL do not record any kind of exception for
  7049. // these functions, so the string to integer
  7050. // conversion returns '0' if an invalid
  7051. // character is encountered during conversion.
  7052. // </para>
  7053. // <para>
  7054. // References
  7055. // <list>
  7056. // <item>
  7057. // http://lslwiki.net/lslwiki/wakka.php?wakka=Base64
  7058. // </item>
  7059. // <item>
  7060. // </item>
  7061. // </list>
  7062. // </para>
  7063. // </remarks>
  7064. // <summary>
  7065. // Table for converting 6-bit integers into
  7066. // base-64 characters
  7067. // </summary>
  7068. protected static readonly char[] i2ctable =
  7069. {
  7070. 'A','B','C','D','E','F','G','H',
  7071. 'I','J','K','L','M','N','O','P',
  7072. 'Q','R','S','T','U','V','W','X',
  7073. 'Y','Z',
  7074. 'a','b','c','d','e','f','g','h',
  7075. 'i','j','k','l','m','n','o','p',
  7076. 'q','r','s','t','u','v','w','x',
  7077. 'y','z',
  7078. '0','1','2','3','4','5','6','7',
  7079. '8','9',
  7080. '+','/'
  7081. };
  7082. // <summary>
  7083. // Table for converting base-64 characters
  7084. // into 6-bit integers.
  7085. // </summary>
  7086. protected static readonly int[] c2itable =
  7087. {
  7088. -1,-1,-1,-1,-1,-1,-1,-1, // 0x
  7089. -1,-1,-1,-1,-1,-1,-1,-1,
  7090. -1,-1,-1,-1,-1,-1,-1,-1, // 1x
  7091. -1,-1,-1,-1,-1,-1,-1,-1,
  7092. -1,-1,-1,-1,-1,-1,-1,-1, // 2x
  7093. -1,-1,-1,63,-1,-1,-1,64,
  7094. 53,54,55,56,57,58,59,60, // 3x
  7095. 61,62,-1,-1,-1,0,-1,-1,
  7096. -1,1,2,3,4,5,6,7, // 4x
  7097. 8,9,10,11,12,13,14,15,
  7098. 16,17,18,19,20,21,22,23, // 5x
  7099. 24,25,26,-1,-1,-1,-1,-1,
  7100. -1,27,28,29,30,31,32,33, // 6x
  7101. 34,35,36,37,38,39,40,41,
  7102. 42,43,44,45,46,47,48,49, // 7x
  7103. 50,51,52,-1,-1,-1,-1,-1,
  7104. -1,-1,-1,-1,-1,-1,-1,-1, // 8x
  7105. -1,-1,-1,-1,-1,-1,-1,-1,
  7106. -1,-1,-1,-1,-1,-1,-1,-1, // 9x
  7107. -1,-1,-1,-1,-1,-1,-1,-1,
  7108. -1,-1,-1,-1,-1,-1,-1,-1, // Ax
  7109. -1,-1,-1,-1,-1,-1,-1,-1,
  7110. -1,-1,-1,-1,-1,-1,-1,-1, // Bx
  7111. -1,-1,-1,-1,-1,-1,-1,-1,
  7112. -1,-1,-1,-1,-1,-1,-1,-1, // Cx
  7113. -1,-1,-1,-1,-1,-1,-1,-1,
  7114. -1,-1,-1,-1,-1,-1,-1,-1, // Dx
  7115. -1,-1,-1,-1,-1,-1,-1,-1,
  7116. -1,-1,-1,-1,-1,-1,-1,-1, // Ex
  7117. -1,-1,-1,-1,-1,-1,-1,-1,
  7118. -1,-1,-1,-1,-1,-1,-1,-1, // Fx
  7119. -1,-1,-1,-1,-1,-1,-1,-1
  7120. };
  7121. // <summary>
  7122. // Converts a 32-bit integer into a Base64
  7123. // character string. Base64 character strings
  7124. // are always 8 characters long. All iinteger
  7125. // values are acceptable.
  7126. // </summary>
  7127. // <param name="number">
  7128. // 32-bit integer to be converted.
  7129. // </param>
  7130. // <returns>
  7131. // 8 character string. The 1st six characters
  7132. // contain the encoded number, the last two
  7133. // characters are padded with "=".
  7134. // </returns>
  7135. public LSL_String llIntegerToBase64(int number)
  7136. {
  7137. // uninitialized string
  7138. char[] imdt = new char[8];
  7139. m_host.AddScriptLPS(1);
  7140. // Manually unroll the loop
  7141. imdt[7] = '=';
  7142. imdt[6] = '=';
  7143. imdt[5] = i2ctable[number<<4 & 0x3F];
  7144. imdt[4] = i2ctable[number>>2 & 0x3F];
  7145. imdt[3] = i2ctable[number>>8 & 0x3F];
  7146. imdt[2] = i2ctable[number>>14 & 0x3F];
  7147. imdt[1] = i2ctable[number>>20 & 0x3F];
  7148. imdt[0] = i2ctable[number>>26 & 0x3F];
  7149. return new string(imdt);
  7150. }
  7151. // <summary>
  7152. // Converts an eight character base-64 string
  7153. // into a 32-bit integer.
  7154. // </summary>
  7155. // <param name="str">
  7156. // 8 characters string to be converted. Other
  7157. // length strings return zero.
  7158. // </param>
  7159. // <returns>
  7160. // Returns an integer representing the
  7161. // encoded value providedint he 1st 6
  7162. // characters of the string.
  7163. // </returns>
  7164. // <remarks>
  7165. // This is coded to behave like LSL's
  7166. // implementation (I think), based upon the
  7167. // information available at the Wiki.
  7168. // If more than 8 characters are supplied,
  7169. // zero is returned.
  7170. // If a NULL string is supplied, zero will
  7171. // be returned.
  7172. // If fewer than 6 characters are supplied, then
  7173. // the answer will reflect a partial
  7174. // accumulation.
  7175. // <para>
  7176. // The 6-bit segments are
  7177. // extracted left-to-right in big-endian mode,
  7178. // which means that segment 6 only contains the
  7179. // two low-order bits of the 32 bit integer as
  7180. // its high order 2 bits. A short string therefore
  7181. // means loss of low-order information. E.g.
  7182. //
  7183. // |<---------------------- 32-bit integer ----------------------->|<-Pad->|
  7184. // |<--Byte 0----->|<--Byte 1----->|<--Byte 2----->|<--Byte 3----->|<-Pad->|
  7185. // |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|
  7186. // |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|
  7187. // | str[0] | str[1] | str[2] | str[3] | str[4] | str[6] |
  7188. //
  7189. // </para>
  7190. // </remarks>
  7191. public LSL_Integer llBase64ToInteger(string str)
  7192. {
  7193. int number = 0;
  7194. int digit;
  7195. m_host.AddScriptLPS(1);
  7196. // Require a well-fromed base64 string
  7197. if (str.Length > 8)
  7198. return 0;
  7199. // The loop is unrolled in the interests
  7200. // of performance and simple necessity.
  7201. //
  7202. // MUST find 6 digits to be well formed
  7203. // -1 == invalid
  7204. // 0 == padding
  7205. if ((digit = c2itable[str[0]]) <= 0)
  7206. {
  7207. return digit < 0 ? (int)0 : number;
  7208. }
  7209. number += --digit<<26;
  7210. if ((digit = c2itable[str[1]]) <= 0)
  7211. {
  7212. return digit < 0 ? (int)0 : number;
  7213. }
  7214. number += --digit<<20;
  7215. if ((digit = c2itable[str[2]]) <= 0)
  7216. {
  7217. return digit < 0 ? (int)0 : number;
  7218. }
  7219. number += --digit<<14;
  7220. if ((digit = c2itable[str[3]]) <= 0)
  7221. {
  7222. return digit < 0 ? (int)0 : number;
  7223. }
  7224. number += --digit<<8;
  7225. if ((digit = c2itable[str[4]]) <= 0)
  7226. {
  7227. return digit < 0 ? (int)0 : number;
  7228. }
  7229. number += --digit<<2;
  7230. if ((digit = c2itable[str[5]]) <= 0)
  7231. {
  7232. return digit < 0 ? (int)0 : number;
  7233. }
  7234. number += --digit>>4;
  7235. // ignore trailing padding
  7236. return number;
  7237. }
  7238. public LSL_Float llGetGMTclock()
  7239. {
  7240. m_host.AddScriptLPS(1);
  7241. return DateTime.UtcNow.TimeOfDay.TotalSeconds;
  7242. }
  7243. public LSL_String llGetHTTPHeader(LSL_Key request_id, string header)
  7244. {
  7245. m_host.AddScriptLPS(1);
  7246. if (m_UrlModule != null)
  7247. return m_UrlModule.GetHttpHeader(new UUID(request_id), header);
  7248. return String.Empty;
  7249. }
  7250. public LSL_String llGetSimulatorHostname()
  7251. {
  7252. m_host.AddScriptLPS(1);
  7253. return System.Environment.MachineName;
  7254. }
  7255. // <summary>
  7256. // Scan the string supplied in 'src' and
  7257. // tokenize it based upon two sets of
  7258. // tokenizers provided in two lists,
  7259. // separators and spacers.
  7260. // </summary>
  7261. //
  7262. // <remarks>
  7263. // Separators demarcate tokens and are
  7264. // elided as they are encountered. Spacers
  7265. // also demarcate tokens, but are themselves
  7266. // retained as tokens.
  7267. //
  7268. // Both separators and spacers may be arbitrarily
  7269. // long strings. i.e. ":::".
  7270. //
  7271. // The function returns an ordered list
  7272. // representing the tokens found in the supplied
  7273. // sources string. If two successive tokenizers
  7274. // are encountered, then a NULL entry is added
  7275. // to the list.
  7276. //
  7277. // It is a precondition that the source and
  7278. // toekizer lisst are non-null. If they are null,
  7279. // then a null pointer exception will be thrown
  7280. // while their lengths are being determined.
  7281. //
  7282. // A small amount of working memoryis required
  7283. // of approximately 8*#tokenizers.
  7284. //
  7285. // There are many ways in which this function
  7286. // can be implemented, this implementation is
  7287. // fairly naive and assumes that when the
  7288. // function is invooked with a short source
  7289. // string and/or short lists of tokenizers, then
  7290. // performance will not be an issue.
  7291. //
  7292. // In order to minimize the perofrmance
  7293. // effects of long strings, or large numbers
  7294. // of tokeizers, the function skips as far as
  7295. // possible whenever a toekenizer is found,
  7296. // and eliminates redundant tokenizers as soon
  7297. // as is possible.
  7298. //
  7299. // The implementation tries to avoid any copying
  7300. // of arrays or other objects.
  7301. // </remarks>
  7302. private LSL_List ParseString(string src, LSL_List separators, LSL_List spacers, bool keepNulls)
  7303. {
  7304. int beginning = 0;
  7305. int srclen = src.Length;
  7306. int seplen = separators.Length;
  7307. object[] separray = separators.Data;
  7308. int spclen = spacers.Length;
  7309. object[] spcarray = spacers.Data;
  7310. int mlen = seplen+spclen;
  7311. int[] offset = new int[mlen+1];
  7312. bool[] active = new bool[mlen];
  7313. int best;
  7314. int j;
  7315. // Initial capacity reduces resize cost
  7316. LSL_List tokens = new LSL_List();
  7317. // All entries are initially valid
  7318. for (int i = 0; i < mlen; i++)
  7319. active[i] = true;
  7320. offset[mlen] = srclen;
  7321. while (beginning < srclen)
  7322. {
  7323. best = mlen; // as bad as it gets
  7324. // Scan for separators
  7325. for (j = 0; j < seplen; j++)
  7326. {
  7327. if (separray[j].ToString() == String.Empty)
  7328. active[j] = false;
  7329. if (active[j])
  7330. {
  7331. // scan all of the markers
  7332. if ((offset[j] = src.IndexOf(separray[j].ToString(), beginning)) == -1)
  7333. {
  7334. // not present at all
  7335. active[j] = false;
  7336. }
  7337. else
  7338. {
  7339. // present and correct
  7340. if (offset[j] < offset[best])
  7341. {
  7342. // closest so far
  7343. best = j;
  7344. if (offset[best] == beginning)
  7345. break;
  7346. }
  7347. }
  7348. }
  7349. }
  7350. // Scan for spacers
  7351. if (offset[best] != beginning)
  7352. {
  7353. for (j = seplen; (j < mlen) && (offset[best] > beginning); j++)
  7354. {
  7355. if (spcarray[j-seplen].ToString() == String.Empty)
  7356. active[j] = false;
  7357. if (active[j])
  7358. {
  7359. // scan all of the markers
  7360. if ((offset[j] = src.IndexOf(spcarray[j-seplen].ToString(), beginning)) == -1)
  7361. {
  7362. // not present at all
  7363. active[j] = false;
  7364. }
  7365. else
  7366. {
  7367. // present and correct
  7368. if (offset[j] < offset[best])
  7369. {
  7370. // closest so far
  7371. best = j;
  7372. }
  7373. }
  7374. }
  7375. }
  7376. }
  7377. // This is the normal exit from the scanning loop
  7378. if (best == mlen)
  7379. {
  7380. // no markers were found on this pass
  7381. // so we're pretty much done
  7382. if ((keepNulls) || ((!keepNulls) && (srclen - beginning) > 0))
  7383. tokens.Add(new LSL_String(src.Substring(beginning, srclen - beginning)));
  7384. break;
  7385. }
  7386. // Otherwise we just add the newly delimited token
  7387. // and recalculate where the search should continue.
  7388. if ((keepNulls) || ((!keepNulls) && (offset[best] - beginning) > 0))
  7389. tokens.Add(new LSL_String(src.Substring(beginning,offset[best]-beginning)));
  7390. if (best < seplen)
  7391. {
  7392. beginning = offset[best] + (separray[best].ToString()).Length;
  7393. }
  7394. else
  7395. {
  7396. beginning = offset[best] + (spcarray[best - seplen].ToString()).Length;
  7397. string str = spcarray[best - seplen].ToString();
  7398. if ((keepNulls) || ((!keepNulls) && (str.Length > 0)))
  7399. tokens.Add(new LSL_String(str));
  7400. }
  7401. }
  7402. // This an awkward an not very intuitive boundary case. If the
  7403. // last substring is a tokenizer, then there is an implied trailing
  7404. // null list entry. Hopefully the single comparison will not be too
  7405. // arduous. Alternatively the 'break' could be replced with a return
  7406. // but that's shabby programming.
  7407. if ((beginning == srclen) && (keepNulls))
  7408. {
  7409. if (srclen != 0)
  7410. tokens.Add(new LSL_String(""));
  7411. }
  7412. return tokens;
  7413. }
  7414. public LSL_List llParseString2List(string src, LSL_List separators, LSL_List spacers)
  7415. {
  7416. m_host.AddScriptLPS(1);
  7417. return this.ParseString(src, separators, spacers, false);
  7418. }
  7419. public LSL_List llParseStringKeepNulls(string src, LSL_List separators, LSL_List spacers)
  7420. {
  7421. m_host.AddScriptLPS(1);
  7422. return this.ParseString(src, separators, spacers, true);
  7423. }
  7424. public LSL_Integer llGetObjectPermMask(int mask)
  7425. {
  7426. m_host.AddScriptLPS(1);
  7427. int permmask = 0;
  7428. if (mask == ScriptBaseClass.MASK_BASE)//0
  7429. {
  7430. permmask = (int)m_host.BaseMask;
  7431. }
  7432. else if (mask == ScriptBaseClass.MASK_OWNER)//1
  7433. {
  7434. permmask = (int)m_host.OwnerMask;
  7435. }
  7436. else if (mask == ScriptBaseClass.MASK_GROUP)//2
  7437. {
  7438. permmask = (int)m_host.GroupMask;
  7439. }
  7440. else if (mask == ScriptBaseClass.MASK_EVERYONE)//3
  7441. {
  7442. permmask = (int)m_host.EveryoneMask;
  7443. }
  7444. else if (mask == ScriptBaseClass.MASK_NEXT)//4
  7445. {
  7446. permmask = (int)m_host.NextOwnerMask;
  7447. }
  7448. return permmask;
  7449. }
  7450. public void llSetObjectPermMask(int mask, int value)
  7451. {
  7452. m_host.AddScriptLPS(1);
  7453. if (m_ScriptEngine.Config.GetBoolean("AllowGodFunctions", false))
  7454. {
  7455. if (World.Permissions.CanRunConsoleCommand(m_host.OwnerID))
  7456. {
  7457. if (mask == ScriptBaseClass.MASK_BASE)//0
  7458. {
  7459. m_host.BaseMask = (uint)value;
  7460. }
  7461. else if (mask == ScriptBaseClass.MASK_OWNER)//1
  7462. {
  7463. m_host.OwnerMask = (uint)value;
  7464. }
  7465. else if (mask == ScriptBaseClass.MASK_GROUP)//2
  7466. {
  7467. m_host.GroupMask = (uint)value;
  7468. }
  7469. else if (mask == ScriptBaseClass.MASK_EVERYONE)//3
  7470. {
  7471. m_host.EveryoneMask = (uint)value;
  7472. }
  7473. else if (mask == ScriptBaseClass.MASK_NEXT)//4
  7474. {
  7475. m_host.NextOwnerMask = (uint)value;
  7476. }
  7477. }
  7478. }
  7479. }
  7480. public LSL_Integer llGetInventoryPermMask(string item, int mask)
  7481. {
  7482. m_host.AddScriptLPS(1);
  7483. lock (m_host.TaskInventory)
  7484. {
  7485. foreach (KeyValuePair<UUID, TaskInventoryItem> inv in m_host.TaskInventory)
  7486. {
  7487. if (inv.Value.Name == item)
  7488. {
  7489. switch (mask)
  7490. {
  7491. case 0:
  7492. return (int)inv.Value.BasePermissions;
  7493. case 1:
  7494. return (int)inv.Value.CurrentPermissions;
  7495. case 2:
  7496. return (int)inv.Value.GroupPermissions;
  7497. case 3:
  7498. return (int)inv.Value.EveryonePermissions;
  7499. case 4:
  7500. return (int)inv.Value.NextPermissions;
  7501. }
  7502. }
  7503. }
  7504. }
  7505. return -1;
  7506. }
  7507. public void llSetInventoryPermMask(string item, int mask, int value)
  7508. {
  7509. m_host.AddScriptLPS(1);
  7510. if (m_ScriptEngine.Config.GetBoolean("AllowGodFunctions", false))
  7511. {
  7512. if (World.Permissions.CanRunConsoleCommand(m_host.OwnerID))
  7513. {
  7514. lock (m_host.TaskInventory)
  7515. {
  7516. foreach (KeyValuePair<UUID, TaskInventoryItem> inv in m_host.TaskInventory)
  7517. {
  7518. if (inv.Value.Name == item)
  7519. {
  7520. switch (mask)
  7521. {
  7522. case 0:
  7523. inv.Value.BasePermissions = (uint)value;
  7524. break;
  7525. case 1:
  7526. inv.Value.CurrentPermissions = (uint)value;
  7527. break;
  7528. case 2:
  7529. inv.Value.GroupPermissions = (uint)value;
  7530. break;
  7531. case 3:
  7532. inv.Value.EveryonePermissions = (uint)value;
  7533. break;
  7534. case 4:
  7535. inv.Value.NextPermissions = (uint)value;
  7536. break;
  7537. }
  7538. }
  7539. }
  7540. }
  7541. }
  7542. }
  7543. }
  7544. public LSL_String llGetInventoryCreator(string item)
  7545. {
  7546. m_host.AddScriptLPS(1);
  7547. lock (m_host.TaskInventory)
  7548. {
  7549. foreach (KeyValuePair<UUID, TaskInventoryItem> inv in m_host.TaskInventory)
  7550. {
  7551. if (inv.Value.Name == item)
  7552. {
  7553. return inv.Value.CreatorID.ToString();
  7554. }
  7555. }
  7556. }
  7557. llSay(0, "No item name '" + item + "'");
  7558. return String.Empty;
  7559. }
  7560. public void llOwnerSay(string msg)
  7561. {
  7562. m_host.AddScriptLPS(1);
  7563. World.SimChatBroadcast(Utils.StringToBytes(msg), ChatTypeEnum.Owner, 0,
  7564. m_host.AbsolutePosition, m_host.Name, m_host.UUID, false);
  7565. // IWorldComm wComm = m_ScriptEngine.World.RequestModuleInterface<IWorldComm>();
  7566. // wComm.DeliverMessage(ChatTypeEnum.Owner, 0, m_host.Name, m_host.UUID, msg);
  7567. }
  7568. public LSL_String llRequestSecureURL()
  7569. {
  7570. m_host.AddScriptLPS(1);
  7571. if (m_UrlModule != null)
  7572. return m_UrlModule.RequestSecureURL(m_ScriptEngine.ScriptModule, m_host, m_itemID).ToString();
  7573. return UUID.Zero.ToString();
  7574. }
  7575. public LSL_String llRequestSimulatorData(string simulator, int data)
  7576. {
  7577. IOSSL_Api ossl = (IOSSL_Api)m_ScriptEngine.GetApi(m_itemID, "OSSL");
  7578. try
  7579. {
  7580. m_host.AddScriptLPS(1);
  7581. string reply = String.Empty;
  7582. GridRegion info;
  7583. if (m_ScriptEngine.World.RegionInfo.RegionName == simulator)
  7584. info = new GridRegion(m_ScriptEngine.World.RegionInfo);
  7585. else
  7586. info = m_ScriptEngine.World.GridService.GetRegionByName(m_ScriptEngine.World.RegionInfo.ScopeID, simulator);
  7587. switch (data)
  7588. {
  7589. case ScriptBaseClass.DATA_SIM_POS:
  7590. if (info == null)
  7591. {
  7592. ScriptSleep(1000);
  7593. return UUID.Zero.ToString();
  7594. }
  7595. reply = new LSL_Vector(
  7596. info.RegionLocX,
  7597. info.RegionLocY,
  7598. 0).ToString();
  7599. break;
  7600. case ScriptBaseClass.DATA_SIM_STATUS:
  7601. if (info != null)
  7602. reply = "up"; // Duh!
  7603. else
  7604. reply = "unknown";
  7605. break;
  7606. case ScriptBaseClass.DATA_SIM_RATING:
  7607. if (info == null)
  7608. {
  7609. ScriptSleep(1000);
  7610. return UUID.Zero.ToString();
  7611. }
  7612. int access = info.Maturity;
  7613. if (access == 0)
  7614. reply = "PG";
  7615. else if (access == 1)
  7616. reply = "MATURE";
  7617. else if (access == 2)
  7618. reply = "ADULT";
  7619. else
  7620. reply = "UNKNOWN";
  7621. break;
  7622. case ScriptBaseClass.DATA_SIM_RELEASE:
  7623. if (ossl != null)
  7624. ossl.CheckThreatLevel(ThreatLevel.High, "llRequestSimulatorData");
  7625. reply = "OpenSim";
  7626. break;
  7627. default:
  7628. ScriptSleep(1000);
  7629. return UUID.Zero.ToString(); // Raise no event
  7630. }
  7631. UUID rq = UUID.Random();
  7632. UUID tid = AsyncCommands.
  7633. DataserverPlugin.RegisterRequest(m_localID, m_itemID, rq.ToString());
  7634. AsyncCommands.
  7635. DataserverPlugin.DataserverReply(rq.ToString(), reply);
  7636. ScriptSleep(1000);
  7637. return tid.ToString();
  7638. }
  7639. catch(Exception)
  7640. {
  7641. //m_log.Error("[LSL_API]: llRequestSimulatorData" + e.ToString());
  7642. return UUID.Zero.ToString();
  7643. }
  7644. }
  7645. public LSL_String llRequestURL()
  7646. {
  7647. m_host.AddScriptLPS(1);
  7648. if (m_UrlModule != null)
  7649. return m_UrlModule.RequestURL(m_ScriptEngine.ScriptModule, m_host, m_itemID).ToString();
  7650. return UUID.Zero.ToString();
  7651. }
  7652. public void llForceMouselook(int mouselook)
  7653. {
  7654. m_host.AddScriptLPS(1);
  7655. m_host.SetForceMouselook(mouselook != 0);
  7656. }
  7657. public LSL_Float llGetObjectMass(string id)
  7658. {
  7659. m_host.AddScriptLPS(1);
  7660. UUID key = new UUID();
  7661. if (UUID.TryParse(id, out key))
  7662. {
  7663. try
  7664. {
  7665. SceneObjectPart obj = World.GetSceneObjectPart(World.Entities[key].LocalId);
  7666. if (obj != null)
  7667. return (double)obj.GetMass();
  7668. // the object is null so the key is for an avatar
  7669. ScenePresence avatar = World.GetScenePresence(key);
  7670. if (avatar != null)
  7671. if (avatar.IsChildAgent)
  7672. // reference http://www.lslwiki.net/lslwiki/wakka.php?wakka=llGetObjectMass
  7673. // child agents have a mass of 1.0
  7674. return 1;
  7675. else
  7676. return (double)avatar.PhysicsActor.Mass;
  7677. }
  7678. catch (KeyNotFoundException)
  7679. {
  7680. return 0; // The Object/Agent not in the region so just return zero
  7681. }
  7682. }
  7683. return 0;
  7684. }
  7685. /// <summary>
  7686. /// illListReplaceList removes the sub-list defined by the inclusive indices
  7687. /// start and end and inserts the src list in its place. The inclusive
  7688. /// nature of the indices means that at least one element must be deleted
  7689. /// if the indices are within the bounds of the existing list. I.e. 2,2
  7690. /// will remove the element at index 2 and replace it with the source
  7691. /// list. Both indices may be negative, with the usual interpretation. An
  7692. /// interesting case is where end is lower than start. As these indices
  7693. /// bound the list to be removed, then 0->end, and start->lim are removed
  7694. /// and the source list is added as a suffix.
  7695. /// </summary>
  7696. public LSL_List llListReplaceList(LSL_List dest, LSL_List src, int start, int end)
  7697. {
  7698. LSL_List pref = null;
  7699. m_host.AddScriptLPS(1);
  7700. // Note that although we have normalized, both
  7701. // indices could still be negative.
  7702. if (start < 0)
  7703. {
  7704. start = start+dest.Length;
  7705. }
  7706. if (end < 0)
  7707. {
  7708. end = end+dest.Length;
  7709. }
  7710. // The comventional case, remove a sequence starting with
  7711. // start and ending with end. And then insert the source
  7712. // list.
  7713. if (start <= end)
  7714. {
  7715. // If greater than zero, then there is going to be a
  7716. // surviving prefix. Otherwise the inclusive nature
  7717. // of the indices mean that we're going to add the
  7718. // source list as a prefix.
  7719. if (start > 0)
  7720. {
  7721. pref = dest.GetSublist(0,start-1);
  7722. // Only add a suffix if there is something
  7723. // beyond the end index (it's inclusive too).
  7724. if (end + 1 < dest.Length)
  7725. {
  7726. return pref + src + dest.GetSublist(end + 1, -1);
  7727. }
  7728. else
  7729. {
  7730. return pref + src;
  7731. }
  7732. }
  7733. // If start is less than or equal to zero, then
  7734. // the new list is simply a prefix. We still need to
  7735. // figure out any necessary surgery to the destination
  7736. // based upon end. Note that if end exceeds the upper
  7737. // bound in this case, the entire destination list
  7738. // is removed.
  7739. else
  7740. {
  7741. if (end + 1 < dest.Length)
  7742. {
  7743. return src + dest.GetSublist(end + 1, -1);
  7744. }
  7745. else
  7746. {
  7747. return src;
  7748. }
  7749. }
  7750. }
  7751. // Finally, if start > end, we strip away a prefix and
  7752. // a suffix, to leave the list that sits <between> ens
  7753. // and start, and then tag on the src list. AT least
  7754. // that's my interpretation. We can get sublist to do
  7755. // this for us. Note that one, or both of the indices
  7756. // might have been negative.
  7757. else
  7758. {
  7759. return dest.GetSublist(end + 1, start - 1) + src;
  7760. }
  7761. }
  7762. public void llLoadURL(string avatar_id, string message, string url)
  7763. {
  7764. m_host.AddScriptLPS(1);
  7765. IDialogModule dm = World.RequestModuleInterface<IDialogModule>();
  7766. if (null != dm)
  7767. dm.SendUrlToUser(
  7768. new UUID(avatar_id), m_host.Name, m_host.UUID, m_host.OwnerID, false, message, url);
  7769. ScriptSleep(10000);
  7770. }
  7771. public void llParcelMediaCommandList(LSL_List commandList)
  7772. {
  7773. // TODO: Not implemented yet (missing in libomv?):
  7774. // 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)
  7775. m_host.AddScriptLPS(1);
  7776. // according to the docs, this command only works if script owner and land owner are the same
  7777. // lets add estate owners and gods, too, and use the generic permission check.
  7778. ILandObject landObject = World.LandChannel.GetLandObject(m_host.AbsolutePosition.X, m_host.AbsolutePosition.Y);
  7779. if (!World.Permissions.CanEditParcelProperties(m_host.OwnerID, landObject, GroupPowers.ChangeMedia)) return;
  7780. bool update = false; // send a ParcelMediaUpdate (and possibly change the land's media URL)?
  7781. byte loop = 0;
  7782. LandData landData = landObject.LandData;
  7783. string url = landData.MediaURL;
  7784. string texture = landData.MediaID.ToString();
  7785. bool autoAlign = landData.MediaAutoScale != 0;
  7786. string mediaType = ""; // TODO these have to be added as soon as LandData supports it
  7787. string description = "";
  7788. int width = 0;
  7789. int height = 0;
  7790. ParcelMediaCommandEnum? commandToSend = null;
  7791. float time = 0.0f; // default is from start
  7792. ScenePresence presence = null;
  7793. for (int i = 0; i < commandList.Data.Length; i++)
  7794. {
  7795. ParcelMediaCommandEnum command = (ParcelMediaCommandEnum)commandList.Data[i];
  7796. switch (command)
  7797. {
  7798. case ParcelMediaCommandEnum.Agent:
  7799. // we send only to one agent
  7800. if ((i + 1) < commandList.Length)
  7801. {
  7802. if (commandList.Data[i + 1] is LSL_String)
  7803. {
  7804. UUID agentID;
  7805. if (UUID.TryParse((LSL_String)commandList.Data[i + 1], out agentID))
  7806. {
  7807. presence = World.GetScenePresence(agentID);
  7808. }
  7809. }
  7810. else ShoutError("The argument of PARCEL_MEDIA_COMMAND_AGENT must be a key");
  7811. ++i;
  7812. }
  7813. break;
  7814. case ParcelMediaCommandEnum.Loop:
  7815. loop = 1;
  7816. commandToSend = command;
  7817. update = true; //need to send the media update packet to set looping
  7818. break;
  7819. case ParcelMediaCommandEnum.Play:
  7820. loop = 0;
  7821. commandToSend = command;
  7822. update = true; //need to send the media update packet to make sure it doesn't loop
  7823. break;
  7824. case ParcelMediaCommandEnum.Pause:
  7825. case ParcelMediaCommandEnum.Stop:
  7826. case ParcelMediaCommandEnum.Unload:
  7827. commandToSend = command;
  7828. break;
  7829. case ParcelMediaCommandEnum.Url:
  7830. if ((i + 1) < commandList.Length)
  7831. {
  7832. if (commandList.Data[i + 1] is LSL_String)
  7833. {
  7834. url = (LSL_String)commandList.Data[i + 1];
  7835. update = true;
  7836. }
  7837. else ShoutError("The argument of PARCEL_MEDIA_COMMAND_URL must be a string.");
  7838. ++i;
  7839. }
  7840. break;
  7841. case ParcelMediaCommandEnum.Texture:
  7842. if ((i + 1) < commandList.Length)
  7843. {
  7844. if (commandList.Data[i + 1] is LSL_String)
  7845. {
  7846. texture = (LSL_String)commandList.Data[i + 1];
  7847. update = true;
  7848. }
  7849. else ShoutError("The argument of PARCEL_MEDIA_COMMAND_TEXTURE must be a string or key.");
  7850. ++i;
  7851. }
  7852. break;
  7853. case ParcelMediaCommandEnum.Time:
  7854. if ((i + 1) < commandList.Length)
  7855. {
  7856. if (commandList.Data[i + 1] is LSL_Float)
  7857. {
  7858. time = (float)(LSL_Float)commandList.Data[i + 1];
  7859. }
  7860. else ShoutError("The argument of PARCEL_MEDIA_COMMAND_TIME must be a float.");
  7861. ++i;
  7862. }
  7863. break;
  7864. case ParcelMediaCommandEnum.AutoAlign:
  7865. if ((i + 1) < commandList.Length)
  7866. {
  7867. if (commandList.Data[i + 1] is LSL_Integer)
  7868. {
  7869. autoAlign = (LSL_Integer)commandList.Data[i + 1];
  7870. update = true;
  7871. }
  7872. else ShoutError("The argument of PARCEL_MEDIA_COMMAND_AUTO_ALIGN must be an integer.");
  7873. ++i;
  7874. }
  7875. break;
  7876. case ParcelMediaCommandEnum.Type:
  7877. if ((i + 1) < commandList.Length)
  7878. {
  7879. if (commandList.Data[i + 1] is LSL_String)
  7880. {
  7881. mediaType = (LSL_String)commandList.Data[i + 1];
  7882. update = true;
  7883. }
  7884. else ShoutError("The argument of PARCEL_MEDIA_COMMAND_TYPE must be a string.");
  7885. ++i;
  7886. }
  7887. break;
  7888. case ParcelMediaCommandEnum.Desc:
  7889. if ((i + 1) < commandList.Length)
  7890. {
  7891. if (commandList.Data[i + 1] is LSL_String)
  7892. {
  7893. description = (LSL_String)commandList.Data[i + 1];
  7894. update = true;
  7895. }
  7896. else ShoutError("The argument of PARCEL_MEDIA_COMMAND_DESC must be a string.");
  7897. ++i;
  7898. }
  7899. break;
  7900. case ParcelMediaCommandEnum.Size:
  7901. if ((i + 2) < commandList.Length)
  7902. {
  7903. if (commandList.Data[i + 1] is LSL_Integer)
  7904. {
  7905. if (commandList.Data[i + 2] is LSL_Integer)
  7906. {
  7907. width = (LSL_Integer)commandList.Data[i + 1];
  7908. height = (LSL_Integer)commandList.Data[i + 2];
  7909. update = true;
  7910. }
  7911. else ShoutError("The second argument of PARCEL_MEDIA_COMMAND_SIZE must be an integer.");
  7912. }
  7913. else ShoutError("The first argument of PARCEL_MEDIA_COMMAND_SIZE must be an integer.");
  7914. i += 2;
  7915. }
  7916. break;
  7917. default:
  7918. NotImplemented("llParcelMediaCommandList parameter not supported yet: " + Enum.Parse(typeof(ParcelMediaCommandEnum), commandList.Data[i].ToString()).ToString());
  7919. break;
  7920. }//end switch
  7921. }//end for
  7922. // if we didn't get a presence, we send to all and change the url
  7923. // if we did get a presence, we only send to the agent specified, and *don't change the land settings*!
  7924. // did something important change or do we only start/stop/pause?
  7925. if (update)
  7926. {
  7927. if (presence == null)
  7928. {
  7929. // we send to all
  7930. landData.MediaID = new UUID(texture);
  7931. landData.MediaAutoScale = autoAlign ? (byte)1 : (byte)0;
  7932. landData.MediaWidth = width;
  7933. landData.MediaHeight = height;
  7934. landData.MediaType = mediaType;
  7935. // do that one last, it will cause a ParcelPropertiesUpdate
  7936. landObject.SetMediaUrl(url);
  7937. // now send to all (non-child) agents in the parcel
  7938. World.ForEachScenePresence(delegate(ScenePresence sp)
  7939. {
  7940. if (!sp.IsChildAgent && (sp.currentParcelUUID == landData.GlobalID))
  7941. {
  7942. sp.ControllingClient.SendParcelMediaUpdate(landData.MediaURL,
  7943. landData.MediaID,
  7944. landData.MediaAutoScale,
  7945. mediaType,
  7946. description,
  7947. width, height,
  7948. loop);
  7949. }
  7950. });
  7951. }
  7952. else if (!presence.IsChildAgent)
  7953. {
  7954. // we only send to one (root) agent
  7955. presence.ControllingClient.SendParcelMediaUpdate(url,
  7956. new UUID(texture),
  7957. autoAlign ? (byte)1 : (byte)0,
  7958. mediaType,
  7959. description,
  7960. width, height,
  7961. loop);
  7962. }
  7963. }
  7964. if (commandToSend != null)
  7965. {
  7966. // the commandList contained a start/stop/... command, too
  7967. if (presence == null)
  7968. {
  7969. // send to all (non-child) agents in the parcel
  7970. World.ForEachScenePresence(delegate(ScenePresence sp)
  7971. {
  7972. if (!sp.IsChildAgent && (sp.currentParcelUUID == landData.GlobalID))
  7973. {
  7974. sp.ControllingClient.SendParcelMediaCommand(0x4, // TODO what is this?
  7975. (ParcelMediaCommandEnum)commandToSend,
  7976. time);
  7977. }
  7978. });
  7979. }
  7980. else if (!presence.IsChildAgent)
  7981. {
  7982. presence.ControllingClient.SendParcelMediaCommand(0x4, // TODO what is this?
  7983. (ParcelMediaCommandEnum)commandToSend,
  7984. time);
  7985. }
  7986. }
  7987. ScriptSleep(2000);
  7988. }
  7989. public LSL_List llParcelMediaQuery(LSL_List aList)
  7990. {
  7991. m_host.AddScriptLPS(1);
  7992. LSL_List list = new LSL_List();
  7993. //TO DO: make the implementation for the missing commands
  7994. //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)
  7995. for (int i = 0; i < aList.Data.Length; i++)
  7996. {
  7997. if (aList.Data[i] != null)
  7998. {
  7999. switch ((ParcelMediaCommandEnum) aList.Data[i])
  8000. {
  8001. case ParcelMediaCommandEnum.Url:
  8002. list.Add(new LSL_String(World.GetLandData(m_host.AbsolutePosition.X, m_host.AbsolutePosition.Y).MediaURL));
  8003. break;
  8004. case ParcelMediaCommandEnum.Desc:
  8005. list.Add(new LSL_String(World.GetLandData(m_host.AbsolutePosition.X, m_host.AbsolutePosition.Y).Description));
  8006. break;
  8007. case ParcelMediaCommandEnum.Texture:
  8008. list.Add(new LSL_String(World.GetLandData(m_host.AbsolutePosition.X, m_host.AbsolutePosition.Y).MediaID.ToString()));
  8009. break;
  8010. case ParcelMediaCommandEnum.Type:
  8011. list.Add(new LSL_String(World.GetLandData(m_host.AbsolutePosition.X, m_host.AbsolutePosition.Y).MediaType));
  8012. break;
  8013. case ParcelMediaCommandEnum.Size:
  8014. list.Add(new LSL_String(World.GetLandData(m_host.AbsolutePosition.X, m_host.AbsolutePosition.Y).MediaWidth));
  8015. list.Add(new LSL_String(World.GetLandData(m_host.AbsolutePosition.X, m_host.AbsolutePosition.Y).MediaHeight));
  8016. break;
  8017. default:
  8018. ParcelMediaCommandEnum mediaCommandEnum = ParcelMediaCommandEnum.Url;
  8019. NotImplemented("llParcelMediaQuery parameter do not supported yet: " + Enum.Parse(mediaCommandEnum.GetType() , aList.Data[i].ToString()).ToString());
  8020. break;
  8021. }
  8022. }
  8023. }
  8024. ScriptSleep(2000);
  8025. return list;
  8026. }
  8027. public LSL_Integer llModPow(int a, int b, int c)
  8028. {
  8029. m_host.AddScriptLPS(1);
  8030. Int64 tmp = 0;
  8031. Math.DivRem(Convert.ToInt64(Math.Pow(a, b)), c, out tmp);
  8032. ScriptSleep(1000);
  8033. return Convert.ToInt32(tmp);
  8034. }
  8035. public LSL_Integer llGetInventoryType(string name)
  8036. {
  8037. m_host.AddScriptLPS(1);
  8038. lock (m_host.TaskInventory)
  8039. {
  8040. foreach (KeyValuePair<UUID, TaskInventoryItem> inv in m_host.TaskInventory)
  8041. {
  8042. if (inv.Value.Name == name)
  8043. {
  8044. return inv.Value.Type;
  8045. }
  8046. }
  8047. }
  8048. return -1;
  8049. }
  8050. public void llSetPayPrice(int price, LSL_List quick_pay_buttons)
  8051. {
  8052. m_host.AddScriptLPS(1);
  8053. if (quick_pay_buttons.Data.Length < 4)
  8054. {
  8055. LSLError("List must have at least 4 elements");
  8056. return;
  8057. }
  8058. m_host.ParentGroup.RootPart.PayPrice[0]=price;
  8059. m_host.ParentGroup.RootPart.PayPrice[1]=(LSL_Integer)quick_pay_buttons.Data[0];
  8060. m_host.ParentGroup.RootPart.PayPrice[2]=(LSL_Integer)quick_pay_buttons.Data[1];
  8061. m_host.ParentGroup.RootPart.PayPrice[3]=(LSL_Integer)quick_pay_buttons.Data[2];
  8062. m_host.ParentGroup.RootPart.PayPrice[4]=(LSL_Integer)quick_pay_buttons.Data[3];
  8063. m_host.ParentGroup.HasGroupChanged = true;
  8064. }
  8065. public LSL_Vector llGetCameraPos()
  8066. {
  8067. m_host.AddScriptLPS(1);
  8068. UUID invItemID = InventorySelf();
  8069. if (invItemID == UUID.Zero)
  8070. return new LSL_Vector();
  8071. lock (m_host.TaskInventory)
  8072. {
  8073. if (m_host.TaskInventory[invItemID].PermsGranter == UUID.Zero)
  8074. return new LSL_Vector();
  8075. if ((m_host.TaskInventory[invItemID].PermsMask & ScriptBaseClass.PERMISSION_TRACK_CAMERA) == 0)
  8076. {
  8077. ShoutError("No permissions to track the camera");
  8078. return new LSL_Vector();
  8079. }
  8080. }
  8081. ScenePresence presence = World.GetScenePresence(m_host.OwnerID);
  8082. if (presence != null)
  8083. {
  8084. LSL_Vector pos = new LSL_Vector(presence.CameraPosition.X, presence.CameraPosition.Y, presence.CameraPosition.Z);
  8085. return pos;
  8086. }
  8087. return new LSL_Vector();
  8088. }
  8089. public LSL_Rotation llGetCameraRot()
  8090. {
  8091. m_host.AddScriptLPS(1);
  8092. UUID invItemID = InventorySelf();
  8093. if (invItemID == UUID.Zero)
  8094. return new LSL_Rotation();
  8095. lock (m_host.TaskInventory)
  8096. {
  8097. if (m_host.TaskInventory[invItemID].PermsGranter == UUID.Zero)
  8098. return new LSL_Rotation();
  8099. if ((m_host.TaskInventory[invItemID].PermsMask & ScriptBaseClass.PERMISSION_TRACK_CAMERA) == 0)
  8100. {
  8101. ShoutError("No permissions to track the camera");
  8102. return new LSL_Rotation();
  8103. }
  8104. }
  8105. ScenePresence presence = World.GetScenePresence(m_host.OwnerID);
  8106. if (presence != null)
  8107. {
  8108. return new LSL_Rotation(presence.CameraRotation.X, presence.CameraRotation.Y, presence.CameraRotation.Z, presence.CameraRotation.W);
  8109. }
  8110. return new LSL_Rotation();
  8111. }
  8112. /// <summary>
  8113. /// The SL implementation does nothing, it is deprecated
  8114. /// This duplicates SL
  8115. /// </summary>
  8116. public void llSetPrimURL(string url)
  8117. {
  8118. m_host.AddScriptLPS(1);
  8119. ScriptSleep(2000);
  8120. }
  8121. /// <summary>
  8122. /// The SL implementation shouts an error, it is deprecated
  8123. /// This duplicates SL
  8124. /// </summary>
  8125. public void llRefreshPrimURL()
  8126. {
  8127. m_host.AddScriptLPS(1);
  8128. ShoutError("llRefreshPrimURL - not yet supported");
  8129. ScriptSleep(20000);
  8130. }
  8131. public LSL_String llEscapeURL(string url)
  8132. {
  8133. m_host.AddScriptLPS(1);
  8134. try
  8135. {
  8136. return Uri.EscapeDataString(url);
  8137. }
  8138. catch (Exception ex)
  8139. {
  8140. return "llEscapeURL: " + ex.ToString();
  8141. }
  8142. }
  8143. public LSL_String llUnescapeURL(string url)
  8144. {
  8145. m_host.AddScriptLPS(1);
  8146. try
  8147. {
  8148. return Uri.UnescapeDataString(url);
  8149. }
  8150. catch (Exception ex)
  8151. {
  8152. return "llUnescapeURL: " + ex.ToString();
  8153. }
  8154. }
  8155. public void llMapDestination(string simname, LSL_Vector pos, LSL_Vector lookAt)
  8156. {
  8157. m_host.AddScriptLPS(1);
  8158. DetectParams detectedParams = m_ScriptEngine.GetDetectParams(m_itemID, 0);
  8159. if (detectedParams == null) return; // only works on the first detected avatar
  8160. ScenePresence avatar = World.GetScenePresence(detectedParams.Key);
  8161. if (avatar != null)
  8162. {
  8163. avatar.ControllingClient.SendScriptTeleportRequest(m_host.Name, simname,
  8164. new Vector3((float)pos.x, (float)pos.y, (float)pos.z),
  8165. new Vector3((float)lookAt.x, (float)lookAt.y, (float)lookAt.z));
  8166. }
  8167. ScriptSleep(1000);
  8168. }
  8169. public void llAddToLandBanList(string avatar, double hours)
  8170. {
  8171. m_host.AddScriptLPS(1);
  8172. UUID key;
  8173. ILandObject land = World.LandChannel.GetLandObject(m_host.AbsolutePosition.X, m_host.AbsolutePosition.Y);
  8174. if (World.Permissions.CanEditParcelProperties(m_host.OwnerID, land, GroupPowers.LandManageBanned))
  8175. {
  8176. ParcelManager.ParcelAccessEntry entry = new ParcelManager.ParcelAccessEntry();
  8177. if (UUID.TryParse(avatar, out key))
  8178. {
  8179. if (land.LandData.ParcelAccessList.FindIndex(
  8180. delegate(ParcelManager.ParcelAccessEntry e)
  8181. {
  8182. if (e.AgentID == key && e.Flags == AccessList.Ban)
  8183. return true;
  8184. return false;
  8185. }) == -1)
  8186. {
  8187. entry.AgentID = key;
  8188. entry.Flags = AccessList.Ban;
  8189. entry.Time = DateTime.Now.AddHours(hours);
  8190. land.LandData.ParcelAccessList.Add(entry);
  8191. }
  8192. }
  8193. }
  8194. ScriptSleep(100);
  8195. }
  8196. public void llRemoveFromLandPassList(string avatar)
  8197. {
  8198. m_host.AddScriptLPS(1);
  8199. UUID key;
  8200. ILandObject land = World.LandChannel.GetLandObject(m_host.AbsolutePosition.X, m_host.AbsolutePosition.Y);
  8201. if (World.Permissions.CanEditParcelProperties(m_host.OwnerID, land, GroupPowers.LandManageAllowed))
  8202. {
  8203. if (UUID.TryParse(avatar, out key))
  8204. {
  8205. int idx = land.LandData.ParcelAccessList.FindIndex(
  8206. delegate(ParcelManager.ParcelAccessEntry e)
  8207. {
  8208. if (e.AgentID == key && e.Flags == AccessList.Access)
  8209. return true;
  8210. return false;
  8211. });
  8212. if (idx != -1)
  8213. land.LandData.ParcelAccessList.RemoveAt(idx);
  8214. }
  8215. }
  8216. ScriptSleep(100);
  8217. }
  8218. public void llRemoveFromLandBanList(string avatar)
  8219. {
  8220. m_host.AddScriptLPS(1);
  8221. UUID key;
  8222. ILandObject land = World.LandChannel.GetLandObject(m_host.AbsolutePosition.X, m_host.AbsolutePosition.Y);
  8223. if (World.Permissions.CanEditParcelProperties(m_host.OwnerID, land, GroupPowers.LandManageBanned))
  8224. {
  8225. if (UUID.TryParse(avatar, out key))
  8226. {
  8227. int idx = land.LandData.ParcelAccessList.FindIndex(
  8228. delegate(ParcelManager.ParcelAccessEntry e)
  8229. {
  8230. if (e.AgentID == key && e.Flags == AccessList.Ban)
  8231. return true;
  8232. return false;
  8233. });
  8234. if (idx != -1)
  8235. land.LandData.ParcelAccessList.RemoveAt(idx);
  8236. }
  8237. }
  8238. ScriptSleep(100);
  8239. }
  8240. public void llSetCameraParams(LSL_List rules)
  8241. {
  8242. m_host.AddScriptLPS(1);
  8243. // our key in the object we are in
  8244. UUID invItemID = InventorySelf();
  8245. if (invItemID == UUID.Zero) return;
  8246. // the object we are in
  8247. UUID objectID = m_host.ParentUUID;
  8248. if (objectID == UUID.Zero) return;
  8249. UUID agentID;
  8250. lock (m_host.TaskInventory)
  8251. {
  8252. // we need the permission first, to know which avatar we want to set the camera for
  8253. agentID = m_host.TaskInventory[invItemID].PermsGranter;
  8254. if (agentID == UUID.Zero) return;
  8255. if ((m_host.TaskInventory[invItemID].PermsMask & ScriptBaseClass.PERMISSION_CONTROL_CAMERA) == 0) return;
  8256. }
  8257. ScenePresence presence = World.GetScenePresence(agentID);
  8258. // we are not interested in child-agents
  8259. if (presence.IsChildAgent) return;
  8260. SortedDictionary<int, float> parameters = new SortedDictionary<int, float>();
  8261. object[] data = rules.Data;
  8262. for (int i = 0; i < data.Length; ++i) {
  8263. int type = Convert.ToInt32(data[i++].ToString());
  8264. if (i >= data.Length) break; // odd number of entries => ignore the last
  8265. // some special cases: Vector parameters are split into 3 float parameters (with type+1, type+2, type+3)
  8266. switch (type) {
  8267. case ScriptBaseClass.CAMERA_FOCUS:
  8268. case ScriptBaseClass.CAMERA_FOCUS_OFFSET:
  8269. case ScriptBaseClass.CAMERA_POSITION:
  8270. LSL_Vector v = (LSL_Vector)data[i];
  8271. parameters.Add(type + 1, (float)v.x);
  8272. parameters.Add(type + 2, (float)v.y);
  8273. parameters.Add(type + 3, (float)v.z);
  8274. break;
  8275. default:
  8276. // TODO: clean that up as soon as the implicit casts are in
  8277. if (data[i] is LSL_Float)
  8278. parameters.Add(type, (float)((LSL_Float)data[i]).value);
  8279. else if (data[i] is LSL_Integer)
  8280. parameters.Add(type, (float)((LSL_Integer)data[i]).value);
  8281. else parameters.Add(type, Convert.ToSingle(data[i]));
  8282. break;
  8283. }
  8284. }
  8285. if (parameters.Count > 0) presence.ControllingClient.SendSetFollowCamProperties(objectID, parameters);
  8286. }
  8287. public void llClearCameraParams()
  8288. {
  8289. m_host.AddScriptLPS(1);
  8290. // our key in the object we are in
  8291. UUID invItemID=InventorySelf();
  8292. if (invItemID == UUID.Zero) return;
  8293. // the object we are in
  8294. UUID objectID = m_host.ParentUUID;
  8295. if (objectID == UUID.Zero) return;
  8296. // we need the permission first, to know which avatar we want to clear the camera for
  8297. UUID agentID;
  8298. lock (m_host.TaskInventory)
  8299. {
  8300. agentID = m_host.TaskInventory[invItemID].PermsGranter;
  8301. if (agentID == UUID.Zero) return;
  8302. if ((m_host.TaskInventory[invItemID].PermsMask & ScriptBaseClass.PERMISSION_CONTROL_CAMERA) == 0) return;
  8303. }
  8304. ScenePresence presence = World.GetScenePresence(agentID);
  8305. // we are not interested in child-agents
  8306. if (presence.IsChildAgent) return;
  8307. presence.ControllingClient.SendClearFollowCamProperties(objectID);
  8308. }
  8309. public LSL_Float llListStatistics(int operation, LSL_List src)
  8310. {
  8311. m_host.AddScriptLPS(1);
  8312. LSL_List nums = LSL_List.ToDoubleList(src);
  8313. switch (operation)
  8314. {
  8315. case ScriptBaseClass.LIST_STAT_RANGE:
  8316. return nums.Range();
  8317. case ScriptBaseClass.LIST_STAT_MIN:
  8318. return nums.Min();
  8319. case ScriptBaseClass.LIST_STAT_MAX:
  8320. return nums.Max();
  8321. case ScriptBaseClass.LIST_STAT_MEAN:
  8322. return nums.Mean();
  8323. case ScriptBaseClass.LIST_STAT_MEDIAN:
  8324. return nums.Median();
  8325. case ScriptBaseClass.LIST_STAT_NUM_COUNT:
  8326. return nums.NumericLength();
  8327. case ScriptBaseClass.LIST_STAT_STD_DEV:
  8328. return nums.StdDev();
  8329. case ScriptBaseClass.LIST_STAT_SUM:
  8330. return nums.Sum();
  8331. case ScriptBaseClass.LIST_STAT_SUM_SQUARES:
  8332. return nums.SumSqrs();
  8333. case ScriptBaseClass.LIST_STAT_GEOMETRIC_MEAN:
  8334. return nums.GeometricMean();
  8335. case ScriptBaseClass.LIST_STAT_HARMONIC_MEAN:
  8336. return nums.HarmonicMean();
  8337. default:
  8338. return 0.0;
  8339. }
  8340. }
  8341. public LSL_Integer llGetUnixTime()
  8342. {
  8343. m_host.AddScriptLPS(1);
  8344. return Util.UnixTimeSinceEpoch();
  8345. }
  8346. public LSL_Integer llGetParcelFlags(LSL_Vector pos)
  8347. {
  8348. m_host.AddScriptLPS(1);
  8349. return (int)World.LandChannel.GetLandObject((float)pos.x, (float)pos.y).LandData.Flags;
  8350. }
  8351. public LSL_Integer llGetRegionFlags()
  8352. {
  8353. m_host.AddScriptLPS(1);
  8354. IEstateModule estate = World.RequestModuleInterface<IEstateModule>();
  8355. if (estate == null)
  8356. return 67108864;
  8357. return (int)estate.GetRegionFlags();
  8358. }
  8359. public LSL_String llXorBase64StringsCorrect(string str1, string str2)
  8360. {
  8361. m_host.AddScriptLPS(1);
  8362. string ret = String.Empty;
  8363. string src1 = llBase64ToString(str1);
  8364. string src2 = llBase64ToString(str2);
  8365. int c = 0;
  8366. for (int i = 0; i < src1.Length; i++)
  8367. {
  8368. ret += (char) (src1[i] ^ src2[c]);
  8369. c++;
  8370. if (c >= src2.Length)
  8371. c = 0;
  8372. }
  8373. return llStringToBase64(ret);
  8374. }
  8375. public LSL_String llHTTPRequest(string url, LSL_List parameters, string body)
  8376. {
  8377. // Partial implementation: support for parameter flags needed
  8378. // see http://wiki.secondlife.com/wiki/LlHTTPRequest
  8379. // parameter flags support are implemented in ScriptsHttpRequests.cs
  8380. // in StartHttpRequest
  8381. m_host.AddScriptLPS(1);
  8382. IHttpRequestModule httpScriptMod =
  8383. m_ScriptEngine.World.RequestModuleInterface<IHttpRequestModule>();
  8384. List<string> param = new List<string>();
  8385. foreach (object o in parameters.Data)
  8386. {
  8387. param.Add(o.ToString());
  8388. }
  8389. Vector3 position = m_host.AbsolutePosition;
  8390. Vector3 velocity = m_host.Velocity;
  8391. Quaternion rotation = m_host.RotationOffset;
  8392. string ownerName = String.Empty;
  8393. ScenePresence scenePresence = World.GetScenePresence(m_host.OwnerID);
  8394. if (scenePresence == null)
  8395. ownerName = resolveName(m_host.OwnerID);
  8396. else
  8397. ownerName = scenePresence.Name;
  8398. RegionInfo regionInfo = World.RegionInfo;
  8399. Dictionary<string, string> httpHeaders = new Dictionary<string, string>();
  8400. string shard = "OpenSim";
  8401. IConfigSource config = m_ScriptEngine.ConfigSource;
  8402. if (config.Configs["Network"] != null)
  8403. {
  8404. shard = config.Configs["Network"].GetString(
  8405. "user_server_url", "http://127.0.0.1:" + ConfigSettings.DefaultUserServerHttpPort.ToString());
  8406. shard = config.Configs["Network"].GetString("shard", shard);
  8407. }
  8408. httpHeaders["X-SecondLife-Shard"] = shard;
  8409. httpHeaders["X-SecondLife-Object-Name"] = m_host.Name;
  8410. httpHeaders["X-SecondLife-Object-Key"] = m_host.UUID.ToString();
  8411. httpHeaders["X-SecondLife-Region"] = string.Format("{0} ({1}, {2})", regionInfo.RegionName, regionInfo.RegionLocX, regionInfo.RegionLocY);
  8412. httpHeaders["X-SecondLife-Local-Position"] = string.Format("({0:0.000000}, {1:0.000000}, {2:0.000000})", position.X, position.Y, position.Z);
  8413. httpHeaders["X-SecondLife-Local-Velocity"] = string.Format("({0:0.000000}, {1:0.000000}, {2:0.000000})", velocity.X, velocity.Y, velocity.Z);
  8414. 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);
  8415. httpHeaders["X-SecondLife-Owner-Name"] = ownerName;
  8416. httpHeaders["X-SecondLife-Owner-Key"] = m_host.OwnerID.ToString();
  8417. string userAgent = config.Configs["Network"].GetString("user_agent", null);
  8418. if (userAgent != null)
  8419. httpHeaders["User-Agent"] = userAgent;
  8420. string authregex = @"^(https?:\/\/)(\w+):(\w+)@(.*)$";
  8421. Regex r = new Regex(authregex);
  8422. int[] gnums = r.GetGroupNumbers();
  8423. Match m = r.Match(url);
  8424. if (m.Success) {
  8425. for (int i = 1; i < gnums.Length; i++) {
  8426. //System.Text.RegularExpressions.Group g = m.Groups[gnums[i]];
  8427. //CaptureCollection cc = g.Captures;
  8428. }
  8429. if (m.Groups.Count == 5) {
  8430. httpHeaders["Authorization"] = String.Format("Basic {0}", Convert.ToBase64String(System.Text.ASCIIEncoding.ASCII.GetBytes(m.Groups[2].ToString() + ":" + m.Groups[3].ToString())));
  8431. url = m.Groups[1].ToString() + m.Groups[4].ToString();
  8432. }
  8433. }
  8434. UUID reqID = httpScriptMod.
  8435. StartHttpRequest(m_localID, m_itemID, url, param, httpHeaders, body);
  8436. if (reqID != UUID.Zero)
  8437. return reqID.ToString();
  8438. else
  8439. return null;
  8440. }
  8441. public void llHTTPResponse(LSL_Key id, int status, string body)
  8442. {
  8443. // Partial implementation: support for parameter flags needed
  8444. // see http://wiki.secondlife.com/wiki/llHTTPResponse
  8445. m_host.AddScriptLPS(1);
  8446. if (m_UrlModule != null)
  8447. m_UrlModule.HttpResponse(new UUID(id), status,body);
  8448. }
  8449. public void llResetLandBanList()
  8450. {
  8451. m_host.AddScriptLPS(1);
  8452. LandData land = World.LandChannel.GetLandObject(m_host.AbsolutePosition.X, m_host.AbsolutePosition.Y).LandData;
  8453. if (land.OwnerID == m_host.OwnerID)
  8454. {
  8455. foreach (ParcelManager.ParcelAccessEntry entry in land.ParcelAccessList)
  8456. {
  8457. if (entry.Flags == AccessList.Ban)
  8458. {
  8459. land.ParcelAccessList.Remove(entry);
  8460. }
  8461. }
  8462. }
  8463. ScriptSleep(100);
  8464. }
  8465. public void llResetLandPassList()
  8466. {
  8467. m_host.AddScriptLPS(1);
  8468. LandData land = World.LandChannel.GetLandObject(m_host.AbsolutePosition.X, m_host.AbsolutePosition.Y).LandData;
  8469. if (land.OwnerID == m_host.OwnerID)
  8470. {
  8471. foreach (ParcelManager.ParcelAccessEntry entry in land.ParcelAccessList)
  8472. {
  8473. if (entry.Flags == AccessList.Access)
  8474. {
  8475. land.ParcelAccessList.Remove(entry);
  8476. }
  8477. }
  8478. }
  8479. ScriptSleep(100);
  8480. }
  8481. public LSL_Integer llGetParcelPrimCount(LSL_Vector pos, int category, int sim_wide)
  8482. {
  8483. m_host.AddScriptLPS(1);
  8484. LandData land = World.GetLandData((float)pos.x, (float)pos.y);
  8485. if (land == null)
  8486. {
  8487. return 0;
  8488. }
  8489. else
  8490. {
  8491. if (sim_wide != 0)
  8492. {
  8493. if (category == 0)
  8494. {
  8495. return land.SimwidePrims;
  8496. }
  8497. else
  8498. {
  8499. //public int simwideArea = 0;
  8500. return 0;
  8501. }
  8502. }
  8503. else
  8504. {
  8505. if (category == 0)//Total Prims
  8506. {
  8507. return 0;//land.
  8508. }
  8509. else if (category == 1)//Owner Prims
  8510. {
  8511. return land.OwnerPrims;
  8512. }
  8513. else if (category == 2)//Group Prims
  8514. {
  8515. return land.GroupPrims;
  8516. }
  8517. else if (category == 3)//Other Prims
  8518. {
  8519. return land.OtherPrims;
  8520. }
  8521. else if (category == 4)//Selected
  8522. {
  8523. return land.SelectedPrims;
  8524. }
  8525. else if (category == 5)//Temp
  8526. {
  8527. return 0;//land.
  8528. }
  8529. }
  8530. }
  8531. return 0;
  8532. }
  8533. public LSL_List llGetParcelPrimOwners(LSL_Vector pos)
  8534. {
  8535. m_host.AddScriptLPS(1);
  8536. LandObject land = (LandObject)World.LandChannel.GetLandObject((float)pos.x, (float)pos.y);
  8537. LSL_List ret = new LSL_List();
  8538. if (land != null)
  8539. {
  8540. foreach (KeyValuePair<UUID, int> detectedParams in land.GetLandObjectOwners())
  8541. {
  8542. ret.Add(detectedParams.Key.ToString());
  8543. ret.Add(detectedParams.Value);
  8544. }
  8545. }
  8546. ScriptSleep(2000);
  8547. return ret;
  8548. }
  8549. public LSL_Integer llGetObjectPrimCount(string object_id)
  8550. {
  8551. m_host.AddScriptLPS(1);
  8552. SceneObjectPart part = World.GetSceneObjectPart(new UUID(object_id));
  8553. if (part == null)
  8554. {
  8555. return 0;
  8556. }
  8557. else
  8558. {
  8559. return part.ParentGroup.PrimCount;
  8560. }
  8561. }
  8562. public LSL_Integer llGetParcelMaxPrims(LSL_Vector pos, int sim_wide)
  8563. {
  8564. m_host.AddScriptLPS(1);
  8565. // Alondria: This currently just is utilizing the normal grid's 0.22 prims/m2 calculation
  8566. // Which probably will be irrelevent in OpenSim....
  8567. LandData land = World.GetLandData((float)pos.x, (float)pos.y);
  8568. float bonusfactor = (float)World.RegionInfo.RegionSettings.ObjectBonus;
  8569. if (land == null)
  8570. {
  8571. return 0;
  8572. }
  8573. if (sim_wide != 0)
  8574. {
  8575. decimal v = land.SimwideArea * (decimal)(0.22) * (decimal)bonusfactor;
  8576. return (int)v;
  8577. }
  8578. else
  8579. {
  8580. decimal v = land.Area * (decimal)(0.22) * (decimal)bonusfactor;
  8581. return (int)v;
  8582. }
  8583. }
  8584. public LSL_List llGetParcelDetails(LSL_Vector pos, LSL_List param)
  8585. {
  8586. m_host.AddScriptLPS(1);
  8587. LandData land = World.GetLandData((float)pos.x, (float)pos.y);
  8588. if (land == null)
  8589. {
  8590. return new LSL_List(0);
  8591. }
  8592. LSL_List ret = new LSL_List();
  8593. foreach (object o in param.Data)
  8594. {
  8595. switch (o.ToString())
  8596. {
  8597. case "0":
  8598. ret = ret + new LSL_List(land.Name);
  8599. break;
  8600. case "1":
  8601. ret = ret + new LSL_List(land.Description);
  8602. break;
  8603. case "2":
  8604. ret = ret + new LSL_List(land.OwnerID.ToString());
  8605. break;
  8606. case "3":
  8607. ret = ret + new LSL_List(land.GroupID.ToString());
  8608. break;
  8609. case "4":
  8610. ret = ret + new LSL_List(land.Area);
  8611. break;
  8612. case "5":
  8613. ret = ret + new LSL_List(land.GlobalID);
  8614. break;
  8615. default:
  8616. ret = ret + new LSL_List(0);
  8617. break;
  8618. }
  8619. }
  8620. return ret;
  8621. }
  8622. public LSL_String llStringTrim(string src, int type)
  8623. {
  8624. m_host.AddScriptLPS(1);
  8625. if (type == (int)ScriptBaseClass.STRING_TRIM_HEAD) { return src.TrimStart(); }
  8626. if (type == (int)ScriptBaseClass.STRING_TRIM_TAIL) { return src.TrimEnd(); }
  8627. if (type == (int)ScriptBaseClass.STRING_TRIM) { return src.Trim(); }
  8628. return src;
  8629. }
  8630. public LSL_List llGetObjectDetails(string id, LSL_List args)
  8631. {
  8632. m_host.AddScriptLPS(1);
  8633. LSL_List ret = new LSL_List();
  8634. UUID key = new UUID();
  8635. if (UUID.TryParse(id, out key))
  8636. {
  8637. ScenePresence av = World.GetScenePresence(key);
  8638. if (av != null)
  8639. {
  8640. foreach (object o in args.Data)
  8641. {
  8642. switch (o.ToString())
  8643. {
  8644. case "1":
  8645. ret.Add(av.Firstname + " " + av.Lastname);
  8646. break;
  8647. case "2":
  8648. ret.Add("");
  8649. break;
  8650. case "3":
  8651. ret.Add(new LSL_Vector((double)av.AbsolutePosition.X, (double)av.AbsolutePosition.Y, (double)av.AbsolutePosition.Z));
  8652. break;
  8653. case "4":
  8654. ret.Add(new LSL_Rotation((double)av.Rotation.X, (double)av.Rotation.Y, (double)av.Rotation.Z, (double)av.Rotation.W));
  8655. break;
  8656. case "5":
  8657. ret.Add(new LSL_Vector(av.Velocity.X, av.Velocity.Y, av.Velocity.Z));
  8658. break;
  8659. case "6":
  8660. ret.Add(id);
  8661. break;
  8662. case "7":
  8663. ret.Add(UUID.Zero.ToString());
  8664. break;
  8665. case "8":
  8666. ret.Add(UUID.Zero.ToString());
  8667. break;
  8668. }
  8669. }
  8670. return ret;
  8671. }
  8672. SceneObjectPart obj = World.GetSceneObjectPart(key);
  8673. if (obj != null)
  8674. {
  8675. foreach (object o in args.Data)
  8676. {
  8677. switch (o.ToString())
  8678. {
  8679. case "1":
  8680. ret.Add(obj.Name);
  8681. break;
  8682. case "2":
  8683. ret.Add(obj.Description);
  8684. break;
  8685. case "3":
  8686. ret.Add(new LSL_Vector(obj.AbsolutePosition.X, obj.AbsolutePosition.Y, obj.AbsolutePosition.Z));
  8687. break;
  8688. case "4":
  8689. ret.Add(new LSL_Rotation(obj.RotationOffset.X, obj.RotationOffset.Y, obj.RotationOffset.Z, obj.RotationOffset.W));
  8690. break;
  8691. case "5":
  8692. ret.Add(new LSL_Vector(obj.Velocity.X, obj.Velocity.Y, obj.Velocity.Z));
  8693. break;
  8694. case "6":
  8695. ret.Add(obj.OwnerID.ToString());
  8696. break;
  8697. case "7":
  8698. ret.Add(obj.GroupID.ToString());
  8699. break;
  8700. case "8":
  8701. ret.Add(obj.CreatorID.ToString());
  8702. break;
  8703. }
  8704. }
  8705. return ret;
  8706. }
  8707. }
  8708. return new LSL_List();
  8709. }
  8710. internal UUID ScriptByName(string name)
  8711. {
  8712. lock (m_host.TaskInventory)
  8713. {
  8714. foreach (TaskInventoryItem item in m_host.TaskInventory.Values)
  8715. {
  8716. if (item.Type == 10 && item.Name == name)
  8717. return item.ItemID;
  8718. }
  8719. }
  8720. return UUID.Zero;
  8721. }
  8722. internal void ShoutError(string msg)
  8723. {
  8724. llShout(ScriptBaseClass.DEBUG_CHANNEL, msg);
  8725. }
  8726. internal void NotImplemented(string command)
  8727. {
  8728. if (throwErrorOnNotImplemented)
  8729. throw new NotImplementedException("Command not implemented: " + command);
  8730. }
  8731. internal void Deprecated(string command)
  8732. {
  8733. throw new Exception("Command deprecated: " + command);
  8734. }
  8735. internal void LSLError(string msg)
  8736. {
  8737. throw new Exception("LSL Runtime Error: " + msg);
  8738. }
  8739. public delegate void AssetRequestCallback(UUID assetID, AssetBase asset);
  8740. protected void WithNotecard(UUID assetID, AssetRequestCallback cb)
  8741. {
  8742. World.AssetService.Get(assetID.ToString(), this,
  8743. delegate(string i, object sender, AssetBase a)
  8744. {
  8745. UUID uuid = UUID.Zero;
  8746. UUID.TryParse(i, out uuid);
  8747. cb(uuid, a);
  8748. });
  8749. }
  8750. public LSL_String llGetNumberOfNotecardLines(string name)
  8751. {
  8752. m_host.AddScriptLPS(1);
  8753. TaskInventoryDictionary itemsDictionary = (TaskInventoryDictionary)m_host.TaskInventory.Clone();
  8754. UUID assetID = UUID.Zero;
  8755. if (!UUID.TryParse(name, out assetID))
  8756. {
  8757. foreach (TaskInventoryItem item in itemsDictionary.Values)
  8758. {
  8759. if (item.Type == 7 && item.Name == name)
  8760. {
  8761. assetID = item.AssetID;
  8762. break;
  8763. }
  8764. }
  8765. }
  8766. if (assetID == UUID.Zero)
  8767. {
  8768. // => complain loudly, as specified by the LSL docs
  8769. ShoutError("Notecard '" + name + "' could not be found.");
  8770. return UUID.Zero.ToString();
  8771. }
  8772. // was: UUID tid = tid = AsyncCommands.
  8773. UUID tid = AsyncCommands.DataserverPlugin.RegisterRequest(m_localID, m_itemID, assetID.ToString());
  8774. if (NotecardCache.IsCached(assetID))
  8775. {
  8776. AsyncCommands.
  8777. DataserverPlugin.DataserverReply(assetID.ToString(),
  8778. NotecardCache.GetLines(assetID).ToString());
  8779. ScriptSleep(100);
  8780. return tid.ToString();
  8781. }
  8782. WithNotecard(assetID, delegate (UUID id, AssetBase a)
  8783. {
  8784. if (a == null || a.Type != 7)
  8785. {
  8786. ShoutError("Notecard '" + name + "' could not be found.");
  8787. return;
  8788. }
  8789. System.Text.UTF8Encoding enc =
  8790. new System.Text.UTF8Encoding();
  8791. string data = enc.GetString(a.Data);
  8792. //m_log.Debug(data);
  8793. NotecardCache.Cache(id, data);
  8794. AsyncCommands.
  8795. DataserverPlugin.DataserverReply(id.ToString(),
  8796. NotecardCache.GetLines(id).ToString());
  8797. });
  8798. ScriptSleep(100);
  8799. return tid.ToString();
  8800. }
  8801. public LSL_String llGetNotecardLine(string name, int line)
  8802. {
  8803. m_host.AddScriptLPS(1);
  8804. TaskInventoryDictionary itemsDictionary = (TaskInventoryDictionary)m_host.TaskInventory.Clone();
  8805. UUID assetID = UUID.Zero;
  8806. if (!UUID.TryParse(name, out assetID))
  8807. {
  8808. foreach (TaskInventoryItem item in itemsDictionary.Values)
  8809. {
  8810. if (item.Type == 7 && item.Name == name)
  8811. {
  8812. assetID = item.AssetID;
  8813. break;
  8814. }
  8815. }
  8816. }
  8817. if (assetID == UUID.Zero)
  8818. {
  8819. // => complain loudly, as specified by the LSL docs
  8820. ShoutError("Notecard '" + name + "' could not be found.");
  8821. return UUID.Zero.ToString();
  8822. }
  8823. // was: UUID tid = tid = AsyncCommands.
  8824. UUID tid = AsyncCommands.DataserverPlugin.RegisterRequest(m_localID, m_itemID, assetID.ToString());
  8825. if (NotecardCache.IsCached(assetID))
  8826. {
  8827. AsyncCommands.DataserverPlugin.DataserverReply(assetID.ToString(),
  8828. NotecardCache.GetLine(assetID, line, m_notecardLineReadCharsMax));
  8829. ScriptSleep(100);
  8830. return tid.ToString();
  8831. }
  8832. WithNotecard(assetID, delegate (UUID id, AssetBase a)
  8833. {
  8834. if (a == null || a.Type != 7)
  8835. {
  8836. ShoutError("Notecard '" + name + "' could not be found.");
  8837. return;
  8838. }
  8839. System.Text.UTF8Encoding enc =
  8840. new System.Text.UTF8Encoding();
  8841. string data = enc.GetString(a.Data);
  8842. //m_log.Debug(data);
  8843. NotecardCache.Cache(id, data);
  8844. AsyncCommands.DataserverPlugin.DataserverReply(id.ToString(),
  8845. NotecardCache.GetLine(id, line, m_notecardLineReadCharsMax));
  8846. });
  8847. ScriptSleep(100);
  8848. return tid.ToString();
  8849. }
  8850. public void SetPrimitiveParamsEx(LSL_Key prim, LSL_List rules)
  8851. {
  8852. SceneObjectPart obj = World.GetSceneObjectPart(new UUID(prim));
  8853. if (obj == null)
  8854. return;
  8855. if (obj.OwnerID != m_host.OwnerID)
  8856. return;
  8857. SetPrimParams(obj, rules);
  8858. }
  8859. public LSL_List GetLinkPrimitiveParamsEx(LSL_Key prim, LSL_List rules)
  8860. {
  8861. SceneObjectPart obj = World.GetSceneObjectPart(new UUID(prim));
  8862. if (obj == null)
  8863. return new LSL_List();
  8864. if (obj.OwnerID != m_host.OwnerID)
  8865. return new LSL_List();
  8866. return GetLinkPrimitiveParams(obj, rules);
  8867. }
  8868. }
  8869. public class NotecardCache
  8870. {
  8871. protected class Notecard
  8872. {
  8873. public string[] text;
  8874. public DateTime lastRef;
  8875. }
  8876. protected static Dictionary<UUID, Notecard> m_Notecards =
  8877. new Dictionary<UUID, Notecard>();
  8878. public static void Cache(UUID assetID, string text)
  8879. {
  8880. CacheCheck();
  8881. lock (m_Notecards)
  8882. {
  8883. if (m_Notecards.ContainsKey(assetID))
  8884. return;
  8885. Notecard nc = new Notecard();
  8886. nc.lastRef = DateTime.Now;
  8887. nc.text = SLUtil.ParseNotecardToList(text).ToArray();
  8888. m_Notecards[assetID] = nc;
  8889. }
  8890. }
  8891. public static bool IsCached(UUID assetID)
  8892. {
  8893. lock (m_Notecards)
  8894. {
  8895. return m_Notecards.ContainsKey(assetID);
  8896. }
  8897. }
  8898. public static int GetLines(UUID assetID)
  8899. {
  8900. if (!IsCached(assetID))
  8901. return -1;
  8902. lock (m_Notecards)
  8903. {
  8904. m_Notecards[assetID].lastRef = DateTime.Now;
  8905. return m_Notecards[assetID].text.Length;
  8906. }
  8907. }
  8908. public static string GetLine(UUID assetID, int line, int maxLength)
  8909. {
  8910. if (line < 0)
  8911. return "";
  8912. string data;
  8913. if (!IsCached(assetID))
  8914. return "";
  8915. lock (m_Notecards)
  8916. {
  8917. m_Notecards[assetID].lastRef = DateTime.Now;
  8918. if (line >= m_Notecards[assetID].text.Length)
  8919. return "\n\n\n";
  8920. data = m_Notecards[assetID].text[line];
  8921. if (data.Length > maxLength)
  8922. data = data.Substring(0, maxLength);
  8923. return data;
  8924. }
  8925. }
  8926. public static void CacheCheck()
  8927. {
  8928. foreach (UUID key in new List<UUID>(m_Notecards.Keys))
  8929. {
  8930. Notecard nc = m_Notecards[key];
  8931. if (nc.lastRef.AddSeconds(30) < DateTime.Now)
  8932. m_Notecards.Remove(key);
  8933. }
  8934. }
  8935. }
  8936. }