LSL_Api.cs 248 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173
  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 OpenSim 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 Nini.Config;
  34. using Axiom.Math;
  35. using libsecondlife;
  36. using libsecondlife.Packets;
  37. using OpenSim;
  38. using OpenSim.Framework;
  39. using OpenSim.Framework.Communications.Cache;
  40. using OpenSim.Region.Environment;
  41. using OpenSim.Region.Environment.Interfaces;
  42. using OpenSim.Region.Environment.Modules.Avatar.Currency.SampleMoney;
  43. using OpenSim.Region.Environment.Modules.World.Land;
  44. using OpenSim.Region.Environment.Scenes;
  45. using OpenSim.Region.ScriptEngine.Shared;
  46. using OpenSim.Region.ScriptEngine.Shared.Api.Plugins;
  47. using OpenSim.Region.ScriptEngine.Shared.ScriptBase;
  48. using OpenSim.Region.ScriptEngine.Interfaces;
  49. using OpenSim.Region.ScriptEngine.Shared.Api.Interfaces;
  50. namespace OpenSim.Region.ScriptEngine.Shared.Api
  51. {
  52. /// <summary>
  53. /// Contains all LSL ll-functions. This class will be in Default AppDomain.
  54. /// </summary>
  55. public class LSL_Api : MarshalByRefObject, ILSL_Api, IScriptApi
  56. {
  57. // private static readonly log4net.ILog m_log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
  58. internal IScriptEngine m_ScriptEngine;
  59. internal SceneObjectPart m_host;
  60. internal uint m_localID;
  61. internal LLUUID m_itemID;
  62. internal bool throwErrorOnNotImplemented = true;
  63. internal static AsyncCommandManager AsyncCommands = null;
  64. public void Initialize(IScriptEngine ScriptEngine, SceneObjectPart host, uint localID, LLUUID itemID)
  65. {
  66. m_ScriptEngine = ScriptEngine;
  67. m_host = host;
  68. m_localID = localID;
  69. m_itemID = itemID;
  70. AsyncCommands = (AsyncCommandManager)ScriptEngine.AsyncCommands;
  71. }
  72. private DateTime m_timer = DateTime.Now;
  73. private bool m_waitingForScriptAnswer=false;
  74. // Object never expires
  75. public override Object InitializeLifetimeService()
  76. {
  77. ILease lease = (ILease)base.InitializeLifetimeService();
  78. if (lease.CurrentState == LeaseState.Initial)
  79. {
  80. lease.InitialLeaseTime = TimeSpan.Zero;
  81. }
  82. return lease;
  83. }
  84. public Scene World
  85. {
  86. get { return m_ScriptEngine.World; }
  87. }
  88. public void state(string newState)
  89. {
  90. m_ScriptEngine.SetState(m_itemID, newState);
  91. throw new EventAbortException();
  92. }
  93. public void llSay(int channelID, string text)
  94. {
  95. m_host.AddScriptLPS(1);
  96. if (text.Length > 1023)
  97. text = text.Substring(0, 1023);
  98. World.SimChat(Helpers.StringToField(text),
  99. ChatTypeEnum.Say, channelID, m_host.AbsolutePosition, m_host.Name, m_host.UUID, false);
  100. IWorldComm wComm = m_ScriptEngine.World.RequestModuleInterface<IWorldComm>();
  101. wComm.DeliverMessage(ChatTypeEnum.Say, channelID, m_host.Name, m_host.UUID, text);
  102. }
  103. // Extension commands use this:
  104. public ICommander GetCommander(string name)
  105. {
  106. return World.GetCommander(name);
  107. }
  108. private LLUUID InventorySelf()
  109. {
  110. LLUUID invItemID = new LLUUID();
  111. foreach (KeyValuePair<LLUUID, TaskInventoryItem> inv in m_host.TaskInventory)
  112. {
  113. if (inv.Value.Type == 10 && inv.Value.ItemID == m_itemID)
  114. {
  115. invItemID = inv.Key;
  116. break;
  117. }
  118. }
  119. return invItemID;
  120. }
  121. private LLUUID InventoryKey(string name, int type)
  122. {
  123. m_host.AddScriptLPS(1);
  124. foreach (KeyValuePair<LLUUID, TaskInventoryItem> inv in m_host.TaskInventory)
  125. {
  126. if (inv.Value.Name == name)
  127. {
  128. if (inv.Value.Type != type)
  129. return LLUUID.Zero;
  130. return inv.Value.AssetID.ToString();
  131. }
  132. }
  133. return LLUUID.Zero;
  134. }
  135. private LLUUID InventoryKey(string name)
  136. {
  137. m_host.AddScriptLPS(1);
  138. foreach (KeyValuePair<LLUUID, TaskInventoryItem> inv in m_host.TaskInventory)
  139. {
  140. if (inv.Value.Name == name)
  141. {
  142. return inv.Value.AssetID.ToString();
  143. }
  144. }
  145. return LLUUID.Zero;
  146. }
  147. /// <summary>
  148. /// accepts a valid LLUUID, -or- a name of an inventory item.
  149. /// Returns a valid LLUUID or LLUUID.Zero if key invalid and item not found
  150. /// in prim inventory.
  151. /// </summary>
  152. /// <param name="k"></param>
  153. /// <returns></returns>
  154. private LLUUID KeyOrName(string k)
  155. {
  156. LLUUID key = LLUUID.Zero;
  157. // if we can parse the string as a key, use it.
  158. if (LLUUID.TryParse(k, out key))
  159. {
  160. return key;
  161. }
  162. // else try to locate the name in inventory of object. found returns key,
  163. // not found returns LLUUID.Zero which will translate to the default particle texture
  164. else
  165. {
  166. return InventoryKey(k);
  167. }
  168. }
  169. public void osSetRegionWaterHeight(double height)
  170. {
  171. m_host.AddScriptLPS(1);
  172. //Check to make sure that the script's owner is the estate manager/master
  173. //World.Permissions.GenericEstatePermission(
  174. if (World.ExternalChecks.ExternalChecksCanBeGodLike(m_host.OwnerID))
  175. {
  176. World.EventManager.TriggerRequestChangeWaterHeight((float)height);
  177. }
  178. }
  179. //These are the implementations of the various ll-functions used by the LSL scripts.
  180. //starting out, we use the System.Math library for trig functions. - ckrinke 8-14-07
  181. public double llSin(double f)
  182. {
  183. m_host.AddScriptLPS(1);
  184. return (double)Math.Sin(f);
  185. }
  186. public double llCos(double f)
  187. {
  188. m_host.AddScriptLPS(1);
  189. return (double)Math.Cos(f);
  190. }
  191. public double llTan(double f)
  192. {
  193. m_host.AddScriptLPS(1);
  194. return (double)Math.Tan(f);
  195. }
  196. public double llAtan2(double x, double y)
  197. {
  198. m_host.AddScriptLPS(1);
  199. return (double)Math.Atan2(y, x);
  200. }
  201. public double llSqrt(double f)
  202. {
  203. m_host.AddScriptLPS(1);
  204. return (double)Math.Sqrt(f);
  205. }
  206. public double llPow(double fbase, double fexponent)
  207. {
  208. m_host.AddScriptLPS(1);
  209. return (double)Math.Pow(fbase, fexponent);
  210. }
  211. public LSL_Types.LSLInteger llAbs(int i)
  212. {
  213. m_host.AddScriptLPS(1);
  214. return (int)Math.Abs(i);
  215. }
  216. public double llFabs(double f)
  217. {
  218. m_host.AddScriptLPS(1);
  219. return (double)Math.Abs(f);
  220. }
  221. public double llFrand(double mag)
  222. {
  223. m_host.AddScriptLPS(1);
  224. lock (Util.RandomClass)
  225. {
  226. return Util.RandomClass.NextDouble() * mag;
  227. }
  228. }
  229. public LSL_Types.LSLInteger llFloor(double f)
  230. {
  231. m_host.AddScriptLPS(1);
  232. return (int)Math.Floor(f);
  233. }
  234. public LSL_Types.LSLInteger llCeil(double f)
  235. {
  236. m_host.AddScriptLPS(1);
  237. return (int)Math.Ceiling(f);
  238. }
  239. // Xantor 01/May/2008 fixed midpointrounding (2.5 becomes 3.0 instead of 2.0, default = ToEven)
  240. public LSL_Types.LSLInteger llRound(double f)
  241. {
  242. m_host.AddScriptLPS(1);
  243. return (int)Math.Round(f, MidpointRounding.AwayFromZero);
  244. }
  245. //This next group are vector operations involving squaring and square root. ckrinke
  246. public double llVecMag(LSL_Types.Vector3 v)
  247. {
  248. m_host.AddScriptLPS(1);
  249. return LSL_Types.Vector3.Mag(v);
  250. }
  251. public LSL_Types.Vector3 llVecNorm(LSL_Types.Vector3 v)
  252. {
  253. m_host.AddScriptLPS(1);
  254. double mag = LSL_Types.Vector3.Mag(v);
  255. LSL_Types.Vector3 nor = new LSL_Types.Vector3();
  256. nor.x = v.x / mag;
  257. nor.y = v.y / mag;
  258. nor.z = v.z / mag;
  259. return nor;
  260. }
  261. public double llVecDist(LSL_Types.Vector3 a, LSL_Types.Vector3 b)
  262. {
  263. m_host.AddScriptLPS(1);
  264. double dx = a.x - b.x;
  265. double dy = a.y - b.y;
  266. double dz = a.z - b.z;
  267. return Math.Sqrt(dx * dx + dy * dy + dz * dz);
  268. }
  269. //Now we start getting into quaternions which means sin/cos, matrices and vectors. ckrinke
  270. // Utility function for llRot2Euler
  271. // normalize an angle between 0 - 2*PI (0 and 360 degrees)
  272. private double NormalizeAngle(double angle)
  273. {
  274. angle = angle % (Math.PI * 2);
  275. if (angle < 0) angle = angle + Math.PI * 2;
  276. return angle;
  277. }
  278. // Old implementation of llRot2Euler, now normalized
  279. public LSL_Types.Vector3 llRot2Euler(LSL_Types.Quaternion r)
  280. {
  281. m_host.AddScriptLPS(1);
  282. //This implementation is from http://lslwiki.net/lslwiki/wakka.php?wakka=LibraryRotationFunctions. ckrinke
  283. LSL_Types.Quaternion t = new LSL_Types.Quaternion(r.x * r.x, r.y * r.y, r.z * r.z, r.s * r.s);
  284. double m = (t.x + t.y + t.z + t.s);
  285. if (m == 0) return new LSL_Types.Vector3();
  286. double n = 2 * (r.y * r.s + r.x * r.z);
  287. double p = m * m - n * n;
  288. if (p > 0)
  289. return new LSL_Types.Vector3(NormalizeAngle(Math.Atan2(2.0 * (r.x * r.s - r.y * r.z), (-t.x - t.y + t.z + t.s))),
  290. NormalizeAngle(Math.Atan2(n, Math.Sqrt(p))),
  291. NormalizeAngle(Math.Atan2(2.0 * (r.z * r.s - r.x * r.y), (t.x - t.y - t.z + t.s))));
  292. else if (n > 0)
  293. return new LSL_Types.Vector3(0.0, Math.PI / 2, NormalizeAngle(Math.Atan2((r.z * r.s + r.x * r.y), 0.5 - t.x - t.z)));
  294. else
  295. return new LSL_Types.Vector3(0.0, -Math.PI / 2, NormalizeAngle(Math.Atan2((r.z * r.s + r.x * r.y), 0.5 - t.x - t.z)));
  296. }
  297. // Xantor's newer llEuler2Rot() *try the second* inverted quaternions (-x,-y,-z,w) as LL seems to like
  298. // New and improved, now actually works as described. Prim rotates as expected as does llRot2Euler.
  299. /* From wiki:
  300. The Euler angle vector (in radians) is converted to a rotation by doing the rotations around the 3 axes
  301. in Z, Y, X order. So llEuler2Rot(<1.0, 2.0, 3.0> * DEG_TO_RAD) generates a rotation by taking the zero rotation,
  302. a vector pointing along the X axis, first rotating it 3 degrees around the global Z axis, then rotating the resulting
  303. vector 2 degrees around the global Y axis, and finally rotating that 1 degree around the global X axis.
  304. */
  305. public LSL_Types.Quaternion llEuler2Rot(LSL_Types.Vector3 v)
  306. {
  307. m_host.AddScriptLPS(1);
  308. double x,y,z,s,s_i;
  309. double cosX = Math.Cos(v.x);
  310. double cosY = Math.Cos(v.y);
  311. double cosZ = Math.Cos(v.z);
  312. double sinX = Math.Sin(v.x);
  313. double sinY = Math.Sin(v.y);
  314. double sinZ = Math.Sin(v.z);
  315. s = Math.Sqrt(cosY * cosZ - sinX * sinY * sinZ + cosX * cosZ + cosX * cosY + 1.0f) * 0.5f;
  316. if (Math.Abs(s) < 0.00001) // null rotation
  317. {
  318. x = 0.0f;
  319. y = 1.0f;
  320. z = 0.0f;
  321. }
  322. else
  323. {
  324. s_i = 1.0f / (4.0f * s);
  325. x = - (-sinX * cosY - cosX * sinY * sinZ - sinX * cosZ) * s_i;
  326. y = - (-cosX * sinY * cosZ + sinX * sinZ - sinY) * s_i;
  327. z = - (-cosY * sinZ - sinX * sinY * cosZ - cosX * sinZ) * s_i;
  328. }
  329. return new LSL_Types.Quaternion(x, y, z, s);
  330. }
  331. public LSL_Types.Quaternion llAxes2Rot(LSL_Types.Vector3 fwd, LSL_Types.Vector3 left, LSL_Types.Vector3 up)
  332. {
  333. m_host.AddScriptLPS(1);
  334. NotImplemented("llAxes2Rot");
  335. return new LSL_Types.Quaternion();
  336. }
  337. public LSL_Types.Vector3 llRot2Fwd(LSL_Types.Quaternion r)
  338. {
  339. m_host.AddScriptLPS(1);
  340. return (new LSL_Types.Vector3(1,0,0) * r);
  341. }
  342. public LSL_Types.Vector3 llRot2Left(LSL_Types.Quaternion r)
  343. {
  344. m_host.AddScriptLPS(1);
  345. return (new LSL_Types.Vector3(0, 1, 0) * r);
  346. }
  347. public LSL_Types.Vector3 llRot2Up(LSL_Types.Quaternion r)
  348. {
  349. m_host.AddScriptLPS(1);
  350. return (new LSL_Types.Vector3(0, 0, 1) * r);
  351. }
  352. public LSL_Types.Quaternion llRotBetween(LSL_Types.Vector3 a, LSL_Types.Vector3 b)
  353. {
  354. //A and B should both be normalized
  355. m_host.AddScriptLPS(1);
  356. double dotProduct = LSL_Types.Vector3.Dot(a, b);
  357. LSL_Types.Vector3 crossProduct = LSL_Types.Vector3.Cross(a, b);
  358. double magProduct = LSL_Types.Vector3.Mag(a) * LSL_Types.Vector3.Mag(b);
  359. double angle = Math.Acos(dotProduct / magProduct);
  360. LSL_Types.Vector3 axis = LSL_Types.Vector3.Norm(crossProduct);
  361. double s = Math.Sin(angle / 2);
  362. return new LSL_Types.Quaternion(axis.x * s, axis.y * s, axis.z * s, (float)Math.Cos(angle / 2));
  363. }
  364. public void llWhisper(int channelID, string text)
  365. {
  366. m_host.AddScriptLPS(1);
  367. if (text.Length > 1023)
  368. text = text.Substring(0, 1023);
  369. World.SimChat(Helpers.StringToField(text),
  370. ChatTypeEnum.Whisper, channelID, m_host.AbsolutePosition, m_host.Name, m_host.UUID, false);
  371. IWorldComm wComm = m_ScriptEngine.World.RequestModuleInterface<IWorldComm>();
  372. wComm.DeliverMessage(ChatTypeEnum.Whisper, channelID, m_host.Name, m_host.UUID, text);
  373. }
  374. public void llShout(int channelID, string text)
  375. {
  376. m_host.AddScriptLPS(1);
  377. if (text.Length > 1023)
  378. text = text.Substring(0, 1023);
  379. World.SimChat(Helpers.StringToField(text),
  380. ChatTypeEnum.Shout, channelID, m_host.AbsolutePosition, m_host.Name, m_host.UUID, true);
  381. IWorldComm wComm = m_ScriptEngine.World.RequestModuleInterface<IWorldComm>();
  382. wComm.DeliverMessage(ChatTypeEnum.Shout, channelID, m_host.Name, m_host.UUID, text);
  383. }
  384. public void llRegionSay(int channelID, string text)
  385. {
  386. if (channelID == 0)
  387. {
  388. LSLError("Cannot use llRegionSay() on channel 0");
  389. return;
  390. }
  391. if (text.Length > 1023)
  392. text = text.Substring(0, 1023);
  393. m_host.AddScriptLPS(1);
  394. IWorldComm wComm = m_ScriptEngine.World.RequestModuleInterface<IWorldComm>();
  395. wComm.DeliverMessage(ChatTypeEnum.Region, channelID, m_host.Name, m_host.UUID, text);
  396. }
  397. public LSL_Types.LSLInteger llListen(int channelID, string name, string ID, string msg)
  398. {
  399. m_host.AddScriptLPS(1);
  400. LLUUID keyID;
  401. LLUUID.TryParse(ID, out keyID);
  402. IWorldComm wComm = m_ScriptEngine.World.RequestModuleInterface<IWorldComm>();
  403. return wComm.Listen(m_localID, m_itemID, m_host.UUID, channelID, name, keyID, msg);
  404. }
  405. public void llListenControl(int number, int active)
  406. {
  407. m_host.AddScriptLPS(1);
  408. IWorldComm wComm = m_ScriptEngine.World.RequestModuleInterface<IWorldComm>();
  409. wComm.ListenControl(m_itemID, number, active);
  410. }
  411. public void llListenRemove(int number)
  412. {
  413. m_host.AddScriptLPS(1);
  414. IWorldComm wComm = m_ScriptEngine.World.RequestModuleInterface<IWorldComm>();
  415. wComm.ListenRemove(m_itemID, number);
  416. }
  417. public void llSensor(string name, string id, int type, double range, double arc)
  418. {
  419. m_host.AddScriptLPS(1);
  420. LLUUID keyID = LLUUID.Zero;
  421. LLUUID.TryParse(id, out keyID);
  422. AsyncCommands.SensorRepeatPlugin.SenseOnce(m_localID, m_itemID, name, keyID, type, range, arc, m_host);
  423. }
  424. public void llSensorRepeat(string name, string id, int type, double range, double arc, double rate)
  425. {
  426. m_host.AddScriptLPS(1);
  427. LLUUID keyID = LLUUID.Zero;
  428. LLUUID.TryParse(id, out keyID);
  429. AsyncCommands.SensorRepeatPlugin.SetSenseRepeatEvent(m_localID, m_itemID, name, keyID, type, range, arc, rate, m_host);
  430. }
  431. public void llSensorRemove()
  432. {
  433. m_host.AddScriptLPS(1);
  434. AsyncCommands.SensorRepeatPlugin.UnSetSenseRepeaterEvents(m_localID, m_itemID);
  435. }
  436. public string resolveName(LLUUID objecUUID)
  437. {
  438. // try avatar username surname
  439. UserProfileData profile = World.CommsManager.UserService.GetUserProfile(objecUUID);
  440. if (profile != null)
  441. {
  442. string avatarname = profile.FirstName + " " + profile.SurName;
  443. return avatarname;
  444. }
  445. // try an scene object
  446. SceneObjectPart SOP = World.GetSceneObjectPart(objecUUID);
  447. if (SOP != null)
  448. {
  449. string objectname = SOP.Name;
  450. return objectname;
  451. }
  452. EntityBase SensedObject;
  453. lock (World.Entities)
  454. {
  455. World.Entities.TryGetValue(objecUUID, out SensedObject);
  456. }
  457. if (SensedObject == null)
  458. return String.Empty;
  459. return SensedObject.Name;
  460. }
  461. public string llDetectedName(int number)
  462. {
  463. m_host.AddScriptLPS(1);
  464. DetectParams d = m_ScriptEngine.GetDetectParams(m_itemID, number);
  465. if (d == null)
  466. return String.Empty;
  467. return d.Name;
  468. }
  469. public string llDetectedKey(int number)
  470. {
  471. m_host.AddScriptLPS(1);
  472. DetectParams d = m_ScriptEngine.GetDetectParams(m_itemID, number);
  473. if (d == null)
  474. return String.Empty;
  475. return d.Key.ToString();
  476. }
  477. public string llDetectedOwner(int number)
  478. {
  479. m_host.AddScriptLPS(1);
  480. DetectParams d = m_ScriptEngine.GetDetectParams(m_itemID, number);
  481. if (d == null)
  482. return String.Empty;
  483. return d.Owner.ToString();
  484. }
  485. public LSL_Types.LSLInteger llDetectedType(int number)
  486. {
  487. m_host.AddScriptLPS(1);
  488. DetectParams d = m_ScriptEngine.GetDetectParams(m_itemID, number);
  489. if (d == null)
  490. return 0;
  491. return new LSL_Types.LSLInteger(d.Type);
  492. }
  493. public LSL_Types.Vector3 llDetectedPos(int number)
  494. {
  495. m_host.AddScriptLPS(1);
  496. DetectParams d = m_ScriptEngine.GetDetectParams(m_itemID, number);
  497. if (d == null)
  498. return new LSL_Types.Vector3();
  499. return d.Position;
  500. }
  501. public LSL_Types.Vector3 llDetectedVel(int number)
  502. {
  503. m_host.AddScriptLPS(1);
  504. DetectParams d = m_ScriptEngine.GetDetectParams(m_itemID, number);
  505. if (d == null)
  506. return new LSL_Types.Vector3();
  507. return d.Velocity;
  508. }
  509. public LSL_Types.Vector3 llDetectedGrab(int number)
  510. {
  511. m_host.AddScriptLPS(1);
  512. DetectParams parms = m_ScriptEngine.GetDetectParams(m_itemID, number);
  513. if (parms == null)
  514. return new LSL_Types.Vector3(0, 0, 0);
  515. return parms.OffsetPos;
  516. }
  517. public LSL_Types.Quaternion llDetectedRot(int number)
  518. {
  519. m_host.AddScriptLPS(1);
  520. DetectParams d = m_ScriptEngine.GetDetectParams(m_itemID, number);
  521. if (d == null)
  522. return new LSL_Types.Quaternion();
  523. return d.Rotation;
  524. }
  525. public LSL_Types.LSLInteger llDetectedGroup(int number)
  526. {
  527. m_host.AddScriptLPS(1);
  528. DetectParams d = m_ScriptEngine.GetDetectParams(m_itemID, number);
  529. if (d == null)
  530. return new LSL_Types.LSLInteger(0);
  531. if (m_host.GroupID == d.Group)
  532. return new LSL_Types.LSLInteger(1);
  533. return new LSL_Types.LSLInteger(0);
  534. }
  535. public LSL_Types.LSLInteger llDetectedLinkNumber(int number)
  536. {
  537. m_host.AddScriptLPS(1);
  538. DetectParams parms = m_ScriptEngine.GetDetectParams(m_itemID, number);
  539. if (parms == null)
  540. return new LSL_Types.LSLInteger(0);
  541. return new LSL_Types.LSLInteger(parms.LinkNum);
  542. }
  543. public void llDie()
  544. {
  545. m_host.AddScriptLPS(1);
  546. World.DeleteSceneObject(m_host.ParentGroup);
  547. }
  548. public double llGround(LSL_Types.Vector3 offset)
  549. {
  550. m_host.AddScriptLPS(1);
  551. int x = (int)(m_host.AbsolutePosition.X + offset.x);
  552. int y = (int)(m_host.AbsolutePosition.Y + offset.y);
  553. return World.GetLandHeight(x, y);
  554. }
  555. public double llCloud(LSL_Types.Vector3 offset)
  556. {
  557. m_host.AddScriptLPS(1);
  558. NotImplemented("llCloud");
  559. return 0;
  560. }
  561. public LSL_Types.Vector3 llWind(LSL_Types.Vector3 offset)
  562. {
  563. m_host.AddScriptLPS(1);
  564. NotImplemented("llWind");
  565. return new LSL_Types.Vector3();
  566. }
  567. public void llSetStatus(int status, int value)
  568. {
  569. m_host.AddScriptLPS(1);
  570. int statusrotationaxis = 0;
  571. if ((status & ScriptBaseClass.STATUS_PHYSICS) == ScriptBaseClass.STATUS_PHYSICS)
  572. {
  573. if (value == 1)
  574. m_host.ScriptSetPhysicsStatus(true);
  575. else
  576. m_host.ScriptSetPhysicsStatus(false);
  577. }
  578. if ((status & ScriptBaseClass.STATUS_PHANTOM) == ScriptBaseClass.STATUS_PHANTOM)
  579. {
  580. if (value == 1)
  581. m_host.ScriptSetPhantomStatus(true);
  582. else
  583. m_host.ScriptSetPhantomStatus(false);
  584. }
  585. if ((status & ScriptBaseClass.STATUS_CAST_SHADOWS) == ScriptBaseClass.STATUS_CAST_SHADOWS)
  586. {
  587. m_host.AddFlag(LLObject.ObjectFlags.CastShadows);
  588. }
  589. if ((status & ScriptBaseClass.STATUS_ROTATE_X) == ScriptBaseClass.STATUS_ROTATE_X)
  590. {
  591. statusrotationaxis |= ScriptBaseClass.STATUS_ROTATE_X;
  592. }
  593. if ((status & ScriptBaseClass.STATUS_ROTATE_Y) == ScriptBaseClass.STATUS_ROTATE_Y)
  594. {
  595. statusrotationaxis |= ScriptBaseClass.STATUS_ROTATE_Y;
  596. }
  597. if ((status & ScriptBaseClass.STATUS_ROTATE_Z) == ScriptBaseClass.STATUS_ROTATE_Z)
  598. {
  599. statusrotationaxis |= ScriptBaseClass.STATUS_ROTATE_Z;
  600. }
  601. if ((status & ScriptBaseClass.STATUS_BLOCK_GRAB) == ScriptBaseClass.STATUS_BLOCK_GRAB)
  602. {
  603. NotImplemented("llSetStatus - STATUS_BLOCK_GRAB");
  604. }
  605. if ((status & ScriptBaseClass.STATUS_DIE_AT_EDGE) == ScriptBaseClass.STATUS_DIE_AT_EDGE)
  606. {
  607. if (value == 1)
  608. m_host.SetDieAtEdge(true);
  609. else
  610. m_host.SetDieAtEdge(false);
  611. }
  612. if ((status & ScriptBaseClass.STATUS_RETURN_AT_EDGE) == ScriptBaseClass.STATUS_RETURN_AT_EDGE)
  613. {
  614. NotImplemented("llSetStatus - STATUS_RETURN_AT_EDGE");
  615. }
  616. if ((status & ScriptBaseClass.STATUS_SANDBOX) == ScriptBaseClass.STATUS_SANDBOX)
  617. {
  618. NotImplemented("llSetStatus - STATUS_SANDBOX");
  619. }
  620. if (statusrotationaxis != 0)
  621. {
  622. m_host.SetAxisRotation(statusrotationaxis, value);
  623. }
  624. }
  625. public LSL_Types.LSLInteger llGetStatus(int status)
  626. {
  627. m_host.AddScriptLPS(1);
  628. // Console.WriteLine(m_host.UUID.ToString() + " status is " + m_host.GetEffectiveObjectFlags().ToString());
  629. switch (status)
  630. {
  631. case ScriptBaseClass.STATUS_PHYSICS:
  632. if ((m_host.GetEffectiveObjectFlags() & (uint)LLObject.ObjectFlags.Physics) == (uint)LLObject.ObjectFlags.Physics)
  633. {
  634. return 1;
  635. }
  636. return 0;
  637. case ScriptBaseClass.STATUS_PHANTOM:
  638. if ((m_host.GetEffectiveObjectFlags() & (uint)LLObject.ObjectFlags.Phantom) == (uint)LLObject.ObjectFlags.Phantom)
  639. {
  640. return 1;
  641. }
  642. return 0;
  643. case ScriptBaseClass.STATUS_CAST_SHADOWS:
  644. if ((m_host.GetEffectiveObjectFlags() & (uint)LLObject.ObjectFlags.CastShadows) == (uint)LLObject.ObjectFlags.CastShadows)
  645. {
  646. return 1;
  647. }
  648. return 0;
  649. case ScriptBaseClass.STATUS_BLOCK_GRAB:
  650. NotImplemented("llGetStatus - STATUS_BLOCK_GRAB");
  651. return 0;
  652. case ScriptBaseClass.STATUS_DIE_AT_EDGE:
  653. if (m_host.GetDieAtEdge())
  654. return 1;
  655. else
  656. return 0;
  657. case ScriptBaseClass.STATUS_RETURN_AT_EDGE:
  658. NotImplemented("llGetStatus - STATUS_RETURN_AT_EDGE");
  659. return 0;
  660. case ScriptBaseClass.STATUS_ROTATE_X:
  661. NotImplemented("llGetStatus - STATUS_ROTATE_X");
  662. return 0;
  663. case ScriptBaseClass.STATUS_ROTATE_Y:
  664. NotImplemented("llGetStatus - STATUS_ROTATE_Y");
  665. return 0;
  666. case ScriptBaseClass.STATUS_ROTATE_Z:
  667. NotImplemented("llGetStatus - STATUS_ROTATE_Z");
  668. return 0;
  669. case ScriptBaseClass.STATUS_SANDBOX:
  670. NotImplemented("llGetStatus - STATUS_SANDBOX");
  671. return 0;
  672. }
  673. return 0;
  674. }
  675. public void llSetScale(LSL_Types.Vector3 scale)
  676. {
  677. m_host.AddScriptLPS(1);
  678. SetScale(m_host, scale);
  679. }
  680. private void SetScale(SceneObjectPart part, LSL_Types.Vector3 scale)
  681. {
  682. // TODO: this needs to trigger a persistance save as well
  683. LLVector3 tmp = part.Scale;
  684. tmp.X = (float)scale.x;
  685. tmp.Y = (float)scale.y;
  686. tmp.Z = (float)scale.z;
  687. part.Scale = tmp;
  688. part.SendFullUpdateToAllClients();
  689. }
  690. public LSL_Types.Vector3 llGetScale()
  691. {
  692. m_host.AddScriptLPS(1);
  693. return new LSL_Types.Vector3(m_host.Scale.X, m_host.Scale.Y, m_host.Scale.Z);
  694. }
  695. public void llSetColor(LSL_Types.Vector3 color, int face)
  696. {
  697. m_host.AddScriptLPS(1);
  698. SetColor(m_host, color, face);
  699. }
  700. private void SetColor(SceneObjectPart part, LSL_Types.Vector3 color, int face)
  701. {
  702. LLObject.TextureEntry tex = part.Shape.Textures;
  703. LLColor texcolor;
  704. if (face > -1)
  705. {
  706. texcolor = tex.CreateFace((uint)face).RGBA;
  707. texcolor.R = (float)Math.Abs(color.x - 1);
  708. texcolor.G = (float)Math.Abs(color.y - 1);
  709. texcolor.B = (float)Math.Abs(color.z - 1);
  710. tex.FaceTextures[face].RGBA = texcolor;
  711. part.UpdateTexture(tex);
  712. return;
  713. }
  714. else if (face == -1)
  715. {
  716. for (uint i = 0; i < 32; i++)
  717. {
  718. if (tex.FaceTextures[i] != null)
  719. {
  720. texcolor = tex.FaceTextures[i].RGBA;
  721. texcolor.R = (float)Math.Abs(color.x - 1);
  722. texcolor.G = (float)Math.Abs(color.y - 1);
  723. texcolor.B = (float)Math.Abs(color.z - 1);
  724. tex.FaceTextures[i].RGBA = texcolor;
  725. }
  726. texcolor = tex.DefaultTexture.RGBA;
  727. texcolor.R = (float)Math.Abs(color.x - 1);
  728. texcolor.G = (float)Math.Abs(color.y - 1);
  729. texcolor.B = (float)Math.Abs(color.z - 1);
  730. tex.DefaultTexture.RGBA = texcolor;
  731. }
  732. part.UpdateTexture(tex);
  733. return;
  734. }
  735. }
  736. public double llGetAlpha(int face)
  737. {
  738. m_host.AddScriptLPS(1);
  739. LLObject.TextureEntry tex = m_host.Shape.Textures;
  740. if (face == -1) // TMP: Until we can determine number of sides, ALL_SIDES (-1) will return default color
  741. {
  742. return (double)((tex.DefaultTexture.RGBA.A * 255) / 255);
  743. }
  744. if (face > -1)
  745. {
  746. return (double)((tex.GetFace((uint)face).RGBA.A * 255) / 255);
  747. }
  748. return 0;
  749. }
  750. public void llSetAlpha(double alpha, int face)
  751. {
  752. m_host.AddScriptLPS(1);
  753. SetAlpha(m_host, alpha, face);
  754. }
  755. private void SetAlpha(SceneObjectPart part, double alpha, int face)
  756. {
  757. LLObject.TextureEntry tex = part.Shape.Textures;
  758. LLColor texcolor;
  759. if (face > -1)
  760. {
  761. texcolor = tex.CreateFace((uint)face).RGBA;
  762. texcolor.A = (float)Math.Abs(alpha - 1);
  763. tex.FaceTextures[face].RGBA = texcolor;
  764. part.UpdateTexture(tex);
  765. return;
  766. }
  767. else if (face == -1)
  768. {
  769. for (int i = 0; i < 32; i++)
  770. {
  771. if (tex.FaceTextures[i] != null)
  772. {
  773. texcolor = tex.FaceTextures[i].RGBA;
  774. texcolor.A = (float)Math.Abs(alpha - 1);
  775. tex.FaceTextures[i].RGBA = texcolor;
  776. }
  777. }
  778. texcolor = tex.DefaultTexture.RGBA;
  779. texcolor.A = (float)Math.Abs(alpha - 1);
  780. tex.DefaultTexture.RGBA = texcolor;
  781. part.UpdateTexture(tex);
  782. return;
  783. }
  784. }
  785. /// <summary>
  786. /// Set flexi parameters of a part.
  787. ///
  788. /// FIXME: Much of this code should probably be within the part itself.
  789. /// </summary>
  790. /// <param name="part"></param>
  791. /// <param name="flexi"></param>
  792. /// <param name="softness"></param>
  793. /// <param name="gravity"></param>
  794. /// <param name="friction"></param>
  795. /// <param name="wind"></param>
  796. /// <param name="tension"></param>
  797. /// <param name="Force"></param>
  798. private void SetFlexi(SceneObjectPart part, bool flexi, int softness, float gravity, float friction,
  799. float wind, float tension, LSL_Types.Vector3 Force)
  800. {
  801. if (part == null)
  802. return;
  803. bool needs_fakedelete = false;
  804. if (flexi)
  805. {
  806. if (!part.Shape.FlexiEntry)
  807. {
  808. needs_fakedelete = true;
  809. }
  810. part.Shape.FlexiEntry = true; // this setting flexi true isn't working, but the below parameters do
  811. // work once the prim is already flexi
  812. part.Shape.FlexiSoftness = softness;
  813. part.Shape.FlexiGravity = gravity;
  814. part.Shape.FlexiDrag = friction;
  815. part.Shape.FlexiWind = wind;
  816. part.Shape.FlexiTension = tension;
  817. part.Shape.FlexiForceX = (float)Force.x;
  818. part.Shape.FlexiForceY = (float)Force.y;
  819. part.Shape.FlexiForceZ = (float)Force.z;
  820. part.Shape.PathCurve = 0x80;
  821. }
  822. else
  823. {
  824. if (part.Shape.FlexiEntry)
  825. {
  826. needs_fakedelete = true;
  827. }
  828. part.Shape.FlexiEntry = false;
  829. }
  830. needs_fakedelete = false;
  831. if (needs_fakedelete)
  832. {
  833. if (part.ParentGroup != null)
  834. {
  835. part.ParentGroup.FakeDeleteGroup();
  836. }
  837. }
  838. part.ParentGroup.HasGroupChanged = true;
  839. part.ScheduleFullUpdate();
  840. }
  841. /// <summary>
  842. /// Set a light point on a part
  843. ///
  844. /// FIXME: Much of this code should probably be in SceneObjectGroup
  845. /// </summary>
  846. /// <param name="part"></param>
  847. /// <param name="light"></param>
  848. /// <param name="color"></param>
  849. /// <param name="intensity"></param>
  850. /// <param name="radius"></param>
  851. /// <param name="falloff"></param>
  852. private void SetPointLight(SceneObjectPart part, bool light, LSL_Types.Vector3 color, float intensity, float radius, float falloff)
  853. {
  854. if (part == null)
  855. return;
  856. if (light)
  857. {
  858. part.Shape.LightEntry = true;
  859. part.Shape.LightColorR = (float)color.x;
  860. part.Shape.LightColorG = (float)color.y;
  861. part.Shape.LightColorB = (float)color.z;
  862. part.Shape.LightIntensity = intensity;
  863. part.Shape.LightRadius = radius;
  864. part.Shape.LightFalloff = falloff;
  865. }
  866. else
  867. {
  868. part.Shape.LightEntry = false;
  869. }
  870. part.ParentGroup.HasGroupChanged = true;
  871. part.ScheduleFullUpdate();
  872. }
  873. public LSL_Types.Vector3 llGetColor(int face)
  874. {
  875. m_host.AddScriptLPS(1);
  876. LLObject.TextureEntry tex = m_host.Shape.Textures;
  877. LLColor texcolor;
  878. LSL_Types.Vector3 rgb;
  879. if (face == -1) // TMP: Until we can determine number of sides, ALL_SIDES (-1) will return default color
  880. {
  881. texcolor = tex.DefaultTexture.RGBA;
  882. rgb.x = (255 - (texcolor.R * 255)) / 255;
  883. rgb.y = (255 - (texcolor.G * 255)) / 255;
  884. rgb.z = (255 - (texcolor.B * 255)) / 255;
  885. return rgb;
  886. }
  887. if (face > -1)
  888. {
  889. texcolor = tex.GetFace((uint)face).RGBA;
  890. rgb.x = (255 - (texcolor.R * 255)) / 255;
  891. rgb.y = (255 - (texcolor.G * 255)) / 255;
  892. rgb.z = (255 - (texcolor.B * 255)) / 255;
  893. return rgb;
  894. }
  895. else
  896. {
  897. return new LSL_Types.Vector3();
  898. }
  899. }
  900. public void llSetTexture(string texture, int face)
  901. {
  902. m_host.AddScriptLPS(1);
  903. SetTexture(m_host, texture, face);
  904. }
  905. private void SetTexture(SceneObjectPart part, string texture, int face)
  906. {
  907. LLUUID textureID=new LLUUID();
  908. if (!LLUUID.TryParse(texture, out textureID))
  909. {
  910. textureID=InventoryKey(texture, (int)AssetType.Texture);
  911. }
  912. if (textureID == LLUUID.Zero)
  913. return;
  914. LLObject.TextureEntry tex = part.Shape.Textures;
  915. if (face > -1)
  916. {
  917. LLObject.TextureEntryFace texface = tex.CreateFace((uint)face);
  918. texface.TextureID = textureID;
  919. tex.FaceTextures[face] = texface;
  920. part.UpdateTexture(tex);
  921. return;
  922. }
  923. else if (face == -1)
  924. {
  925. for (uint i = 0; i < 32; i++)
  926. {
  927. if (tex.FaceTextures[i] != null)
  928. {
  929. tex.FaceTextures[i].TextureID = textureID;
  930. }
  931. }
  932. tex.DefaultTexture.TextureID = textureID;
  933. part.UpdateTexture(tex);
  934. return;
  935. }
  936. }
  937. public void llScaleTexture(double u, double v, int face)
  938. {
  939. m_host.AddScriptLPS(1);
  940. ScaleTexture(m_host, u, v, face);
  941. }
  942. private void ScaleTexture(SceneObjectPart part, double u, double v, int face)
  943. {
  944. LLObject.TextureEntry tex = part.Shape.Textures;
  945. if (face > -1)
  946. {
  947. LLObject.TextureEntryFace texface = tex.CreateFace((uint)face);
  948. texface.RepeatU = (float)u;
  949. texface.RepeatV = (float)v;
  950. tex.FaceTextures[face] = texface;
  951. part.UpdateTexture(tex);
  952. return;
  953. }
  954. if (face == -1)
  955. {
  956. for (int i = 0; i < 32; i++)
  957. {
  958. if (tex.FaceTextures[i] != null)
  959. {
  960. tex.FaceTextures[i].RepeatU = (float)u;
  961. tex.FaceTextures[i].RepeatV = (float)v;
  962. }
  963. }
  964. tex.DefaultTexture.RepeatU = (float)u;
  965. tex.DefaultTexture.RepeatV = (float)v;
  966. part.UpdateTexture(tex);
  967. return;
  968. }
  969. }
  970. public void llOffsetTexture(double u, double v, int face)
  971. {
  972. m_host.AddScriptLPS(1);
  973. OffsetTexture(m_host, u, v, face);
  974. }
  975. private void OffsetTexture(SceneObjectPart part, double u, double v, int face)
  976. {
  977. LLObject.TextureEntry tex = part.Shape.Textures;
  978. if (face > -1)
  979. {
  980. LLObject.TextureEntryFace texface = tex.CreateFace((uint)face);
  981. texface.OffsetU = (float)u;
  982. texface.OffsetV = (float)v;
  983. tex.FaceTextures[face] = texface;
  984. part.UpdateTexture(tex);
  985. return;
  986. }
  987. if (face == -1)
  988. {
  989. for (int i = 0; i < 32; i++)
  990. {
  991. if (tex.FaceTextures[i] != null)
  992. {
  993. tex.FaceTextures[i].OffsetU = (float)u;
  994. tex.FaceTextures[i].OffsetV = (float)v;
  995. }
  996. }
  997. tex.DefaultTexture.OffsetU = (float)u;
  998. tex.DefaultTexture.OffsetV = (float)v;
  999. part.UpdateTexture(tex);
  1000. return;
  1001. }
  1002. }
  1003. public void llRotateTexture(double rotation, int face)
  1004. {
  1005. m_host.AddScriptLPS(1);
  1006. RotateTexture(m_host, rotation, face);
  1007. }
  1008. private void RotateTexture(SceneObjectPart part, double rotation, int face)
  1009. {
  1010. LLObject.TextureEntry tex = part.Shape.Textures;
  1011. if (face > -1)
  1012. {
  1013. LLObject.TextureEntryFace texface = tex.CreateFace((uint)face);
  1014. texface.Rotation = (float)rotation;
  1015. tex.FaceTextures[face] = texface;
  1016. part.UpdateTexture(tex);
  1017. return;
  1018. }
  1019. if (face == -1)
  1020. {
  1021. for (int i = 0; i < 32; i++)
  1022. {
  1023. if (tex.FaceTextures[i] != null)
  1024. {
  1025. tex.FaceTextures[i].Rotation = (float)rotation;
  1026. }
  1027. }
  1028. tex.DefaultTexture.Rotation = (float)rotation;
  1029. part.UpdateTexture(tex);
  1030. return;
  1031. }
  1032. }
  1033. public string llGetTexture(int face)
  1034. {
  1035. m_host.AddScriptLPS(1);
  1036. LLObject.TextureEntry tex = m_host.Shape.Textures;
  1037. if (face == -1)
  1038. {
  1039. face = 0;
  1040. }
  1041. if (face > -1)
  1042. {
  1043. LLObject.TextureEntryFace texface;
  1044. texface = tex.GetFace((uint)face);
  1045. return texface.TextureID.ToString();
  1046. }
  1047. else
  1048. {
  1049. return String.Empty;
  1050. }
  1051. }
  1052. public void llSetPos(LSL_Types.Vector3 pos)
  1053. {
  1054. m_host.AddScriptLPS(1);
  1055. SetPos(m_host, pos);
  1056. }
  1057. private void SetPos(SceneObjectPart part, LSL_Types.Vector3 pos)
  1058. {
  1059. if (part.ParentID != 0)
  1060. {
  1061. part.UpdateOffSet(new LLVector3((float)pos.x, (float)pos.y, (float)pos.z));
  1062. }
  1063. else
  1064. {
  1065. part.UpdateGroupPosition(new LLVector3((float)pos.x, (float)pos.y, (float)pos.z));
  1066. }
  1067. }
  1068. public LSL_Types.Vector3 llGetPos()
  1069. {
  1070. m_host.AddScriptLPS(1);
  1071. return new LSL_Types.Vector3(m_host.AbsolutePosition.X,
  1072. m_host.AbsolutePosition.Y,
  1073. m_host.AbsolutePosition.Z);
  1074. }
  1075. public LSL_Types.Vector3 llGetLocalPos()
  1076. {
  1077. m_host.AddScriptLPS(1);
  1078. if (m_host.ParentID != 0)
  1079. {
  1080. return new LSL_Types.Vector3(m_host.OffsetPosition.X,
  1081. m_host.OffsetPosition.Y,
  1082. m_host.OffsetPosition.Z);
  1083. }
  1084. else
  1085. {
  1086. return new LSL_Types.Vector3(m_host.AbsolutePosition.X,
  1087. m_host.AbsolutePosition.Y,
  1088. m_host.AbsolutePosition.Z);
  1089. }
  1090. }
  1091. public void llSetRot(LSL_Types.Quaternion rot)
  1092. {
  1093. m_host.AddScriptLPS(1);
  1094. SetRot(m_host, rot);
  1095. }
  1096. private void SetRot(SceneObjectPart part, LSL_Types.Quaternion rot)
  1097. {
  1098. part.UpdateRotation(new LLQuaternion((float)rot.x, (float)rot.y, (float)rot.z, (float)rot.s));
  1099. // Update rotation does not move the object in the physics scene if it's a linkset.
  1100. part.ParentGroup.AbsolutePosition = part.ParentGroup.AbsolutePosition;
  1101. }
  1102. public LSL_Types.Quaternion llGetRot()
  1103. {
  1104. m_host.AddScriptLPS(1);
  1105. LLQuaternion q = m_host.RotationOffset;
  1106. return new LSL_Types.Quaternion(q.X, q.Y, q.Z, q.W);
  1107. }
  1108. public LSL_Types.Quaternion llGetLocalRot()
  1109. {
  1110. m_host.AddScriptLPS(1);
  1111. return new LSL_Types.Quaternion(m_host.RotationOffset.X, m_host.RotationOffset.Y, m_host.RotationOffset.Z, m_host.RotationOffset.W);
  1112. }
  1113. public void llSetForce(LSL_Types.Vector3 force, int local)
  1114. {
  1115. m_host.AddScriptLPS(1);
  1116. NotImplemented("llSetForce");
  1117. }
  1118. public LSL_Types.Vector3 llGetForce()
  1119. {
  1120. m_host.AddScriptLPS(1);
  1121. NotImplemented("llGetForce");
  1122. return new LSL_Types.Vector3();
  1123. }
  1124. public LSL_Types.LSLInteger llTarget(LSL_Types.Vector3 position, double range)
  1125. {
  1126. m_host.AddScriptLPS(1);
  1127. return m_host.registerTargetWaypoint(new LLVector3((float)position.x, (float)position.y, (float)position.z), (float)range);
  1128. }
  1129. public void llTargetRemove(int number)
  1130. {
  1131. m_host.AddScriptLPS(1);
  1132. m_host.unregisterTargetWaypoint(number);
  1133. }
  1134. public LSL_Types.LSLInteger llRotTarget(LSL_Types.Quaternion rot, double error)
  1135. {
  1136. m_host.AddScriptLPS(1);
  1137. NotImplemented("llRotTarget");
  1138. return 0;
  1139. }
  1140. public void llRotTargetRemove(int number)
  1141. {
  1142. m_host.AddScriptLPS(1);
  1143. NotImplemented("llRotTargetRemove");
  1144. }
  1145. public void llMoveToTarget(LSL_Types.Vector3 target, double tau)
  1146. {
  1147. m_host.AddScriptLPS(1);
  1148. m_host.MoveToTarget(new LLVector3((float)target.x, (float)target.y, (float)target.z), (float)tau);
  1149. }
  1150. public void llStopMoveToTarget()
  1151. {
  1152. m_host.AddScriptLPS(1);
  1153. m_host.StopMoveToTarget();
  1154. }
  1155. public void llApplyImpulse(LSL_Types.Vector3 force, int local)
  1156. {
  1157. m_host.AddScriptLPS(1);
  1158. //No energy force yet
  1159. if (force.x > 20000)
  1160. force.x = 20000;
  1161. if (force.y > 20000)
  1162. force.y = 20000;
  1163. if (force.z > 20000)
  1164. force.z = 20000;
  1165. if (local == 1)
  1166. {
  1167. m_host.ApplyImpulse(new LLVector3((float)force.x, (float)force.y, (float)force.z), true);
  1168. }
  1169. else
  1170. {
  1171. m_host.ApplyImpulse(new LLVector3((float)force.x,(float)force.y,(float)force.z), false);
  1172. }
  1173. }
  1174. public void llApplyRotationalImpulse(LSL_Types.Vector3 force, int local)
  1175. {
  1176. m_host.AddScriptLPS(1);
  1177. NotImplemented("llApplyRotationalImpulse");
  1178. }
  1179. public void llSetTorque(LSL_Types.Vector3 torque, int local)
  1180. {
  1181. m_host.AddScriptLPS(1);
  1182. NotImplemented("llSetTorque");
  1183. }
  1184. public LSL_Types.Vector3 llGetTorque()
  1185. {
  1186. m_host.AddScriptLPS(1);
  1187. NotImplemented("llGetTorque");
  1188. return new LSL_Types.Vector3();
  1189. }
  1190. public void llSetForceAndTorque(LSL_Types.Vector3 force, LSL_Types.Vector3 torque, int local)
  1191. {
  1192. m_host.AddScriptLPS(1);
  1193. NotImplemented("llSetForceAndTorque");
  1194. }
  1195. public LSL_Types.Vector3 llGetVel()
  1196. {
  1197. m_host.AddScriptLPS(1);
  1198. return new LSL_Types.Vector3(m_host.Velocity.X, m_host.Velocity.Y, m_host.Velocity.Z);
  1199. }
  1200. public LSL_Types.Vector3 llGetAccel()
  1201. {
  1202. m_host.AddScriptLPS(1);
  1203. return new LSL_Types.Vector3(m_host.Acceleration.X, m_host.Acceleration.Y, m_host.Acceleration.Z);
  1204. }
  1205. public LSL_Types.Vector3 llGetOmega()
  1206. {
  1207. m_host.AddScriptLPS(1);
  1208. return new LSL_Types.Vector3(m_host.RotationalVelocity.X, m_host.RotationalVelocity.Y, m_host.RotationalVelocity.Z);
  1209. }
  1210. public double llGetTimeOfDay()
  1211. {
  1212. m_host.AddScriptLPS(1);
  1213. return (double) (((DateTime.Now.TimeOfDay.TotalMilliseconds / 1000) % (3600*4))*World.TimeDilation);
  1214. }
  1215. public double llGetWallclock()
  1216. {
  1217. m_host.AddScriptLPS(1);
  1218. return DateTime.Now.TimeOfDay.TotalSeconds;
  1219. }
  1220. public double llGetTime()
  1221. {
  1222. m_host.AddScriptLPS(1);
  1223. TimeSpan ScriptTime = DateTime.Now - m_timer;
  1224. return (double)((ScriptTime.TotalMilliseconds / 1000)*World.TimeDilation);
  1225. }
  1226. public void llResetTime()
  1227. {
  1228. m_host.AddScriptLPS(1);
  1229. m_timer = DateTime.Now;
  1230. }
  1231. public double llGetAndResetTime()
  1232. {
  1233. m_host.AddScriptLPS(1);
  1234. TimeSpan ScriptTime = DateTime.Now - m_timer;
  1235. m_timer = DateTime.Now;
  1236. return (double)((ScriptTime.TotalMilliseconds / 1000)*World.TimeDilation);
  1237. }
  1238. public void llSound()
  1239. {
  1240. m_host.AddScriptLPS(1);
  1241. // This function has been deprecated
  1242. // see http://www.lslwiki.net/lslwiki/wakka.php?wakka=llSound
  1243. Deprecated("llSound");
  1244. }
  1245. // Xantor 20080528 PlaySound updated so it accepts an objectinventory name -or- a key to a sound
  1246. // 20080530 Updated to remove code duplication
  1247. public void llPlaySound(string sound, double volume)
  1248. {
  1249. m_host.AddScriptLPS(1);
  1250. // send the sound, once, to all clients in range
  1251. m_host.SendSound(KeyOrName(sound).ToString(), volume, false, 0);
  1252. }
  1253. // Xantor 20080528 we should do this differently.
  1254. // 1) apply the sound to the object
  1255. // 2) schedule full update
  1256. // just sending the sound out once doesn't work so well when other avatars come in view later on
  1257. // or when the prim gets moved, changed, sat on, whatever
  1258. // see large number of mantises (mantes?)
  1259. // 20080530 Updated to remove code duplication
  1260. // 20080530 Stop sound if there is one, otherwise volume only changes don't work
  1261. public void llLoopSound(string sound, double volume)
  1262. {
  1263. m_host.AddScriptLPS(1);
  1264. if (m_host.Sound != LLUUID.Zero)
  1265. llStopSound();
  1266. m_host.Sound = KeyOrName(sound);
  1267. m_host.SoundGain = volume;
  1268. m_host.SoundFlags = 1; // looping
  1269. m_host.SoundRadius = 20; // Magic number, 20 seems reasonable. Make configurable?
  1270. m_host.ScheduleFullUpdate();
  1271. m_host.SendFullUpdateToAllClients();
  1272. }
  1273. public void llLoopSoundMaster(string sound, double volume)
  1274. {
  1275. m_host.AddScriptLPS(1);
  1276. NotImplemented("llLoopSoundMaster");
  1277. }
  1278. public void llLoopSoundSlave(string sound, double volume)
  1279. {
  1280. m_host.AddScriptLPS(1);
  1281. NotImplemented("llLoopSoundSlave");
  1282. }
  1283. public void llPlaySoundSlave(string sound, double volume)
  1284. {
  1285. m_host.AddScriptLPS(1);
  1286. NotImplemented("llPlaySoundSlave");
  1287. }
  1288. public void llTriggerSound(string sound, double volume)
  1289. {
  1290. m_host.AddScriptLPS(1);
  1291. m_host.SendSound(sound, volume, true, 0);
  1292. }
  1293. // Xantor 20080528: Clear prim data of sound instead
  1294. public void llStopSound()
  1295. {
  1296. m_host.AddScriptLPS(1);
  1297. m_host.Sound = LLUUID.Zero;
  1298. m_host.SoundGain = 0;
  1299. m_host.SoundFlags = 0;
  1300. m_host.SoundRadius = 0;
  1301. m_host.ScheduleFullUpdate();
  1302. m_host.SendFullUpdateToAllClients();
  1303. // m_host.SendSound(LLUUID.Zero.ToString(), 1.0, false, 2);
  1304. }
  1305. public void llPreloadSound(string sound)
  1306. {
  1307. m_host.AddScriptLPS(1);
  1308. m_host.PreloadSound(sound);
  1309. }
  1310. /// <summary>
  1311. /// Return a portion of the designated string bounded by
  1312. /// inclusive indices (start and end). As usual, the negative
  1313. /// indices, and the tolerance for out-of-bound values, makes
  1314. /// this more complicated than it might otherwise seem.
  1315. /// </summary>
  1316. public string llGetSubString(string src, int start, int end)
  1317. {
  1318. m_host.AddScriptLPS(1);
  1319. // Normalize indices (if negative).
  1320. // After normlaization they may still be
  1321. // negative, but that is now relative to
  1322. // the start, rather than the end, of the
  1323. // sequence.
  1324. if (start < 0)
  1325. {
  1326. start = src.Length+start;
  1327. }
  1328. if (end < 0)
  1329. {
  1330. end = src.Length+end;
  1331. }
  1332. // Conventional substring
  1333. if (start <= end)
  1334. {
  1335. // Implies both bounds are out-of-range.
  1336. if (end < 0 || start >= src.Length)
  1337. {
  1338. return String.Empty;
  1339. }
  1340. // If end is positive, then it directly
  1341. // corresponds to the lengt of the substring
  1342. // needed (plus one of course). BUT, it
  1343. // must be within bounds.
  1344. if (end >= src.Length)
  1345. {
  1346. end = src.Length-1;
  1347. }
  1348. if (start < 0)
  1349. {
  1350. return src.Substring(0,end+1);
  1351. }
  1352. // Both indices are positive
  1353. return src.Substring(start, (end+1) - start);
  1354. }
  1355. // Inverted substring (end < start)
  1356. else
  1357. {
  1358. // Implies both indices are below the
  1359. // lower bound. In the inverted case, that
  1360. // means the entire string will be returned
  1361. // unchanged.
  1362. if (start < 0)
  1363. {
  1364. return src;
  1365. }
  1366. // If both indices are greater than the upper
  1367. // bound the result may seem initially counter
  1368. // intuitive.
  1369. if (end >= src.Length)
  1370. {
  1371. return src;
  1372. }
  1373. if (end < 0)
  1374. {
  1375. if (start < src.Length)
  1376. {
  1377. return src.Substring(start);
  1378. }
  1379. else
  1380. {
  1381. return String.Empty;
  1382. }
  1383. }
  1384. else
  1385. {
  1386. if (start < src.Length)
  1387. {
  1388. return src.Substring(0,end+1) + src.Substring(start);
  1389. }
  1390. else
  1391. {
  1392. return src.Substring(0,end+1);
  1393. }
  1394. }
  1395. }
  1396. }
  1397. /// <summary>
  1398. /// Delete substring removes the specified substring bounded
  1399. /// by the inclusive indices start and end. Indices may be
  1400. /// negative (indicating end-relative) and may be inverted,
  1401. /// i.e. end < start.
  1402. /// </summary>
  1403. public string llDeleteSubString(string src, int start, int end)
  1404. {
  1405. m_host.AddScriptLPS(1);
  1406. // Normalize indices (if negative).
  1407. // After normlaization they may still be
  1408. // negative, but that is now relative to
  1409. // the start, rather than the end, of the
  1410. // sequence.
  1411. if (start < 0)
  1412. {
  1413. start = src.Length+start;
  1414. }
  1415. if (end < 0)
  1416. {
  1417. end = src.Length+end;
  1418. }
  1419. // Conventionally delimited substring
  1420. if (start <= end)
  1421. {
  1422. // If both bounds are outside of the existing
  1423. // string, then return unchanges.
  1424. if (end < 0 || start >= src.Length)
  1425. {
  1426. return src;
  1427. }
  1428. // At least one bound is in-range, so we
  1429. // need to clip the out-of-bound argument.
  1430. if (start < 0)
  1431. {
  1432. start = 0;
  1433. }
  1434. if (end >= src.Length)
  1435. {
  1436. end = src.Length-1;
  1437. }
  1438. return src.Remove(start,end-start+1);
  1439. }
  1440. // Inverted substring
  1441. else
  1442. {
  1443. // In this case, out of bounds means that
  1444. // the existing string is part of the cut.
  1445. if (start < 0 || end >= src.Length)
  1446. {
  1447. return String.Empty;
  1448. }
  1449. if (end > 0)
  1450. {
  1451. if (start < src.Length)
  1452. {
  1453. return src.Remove(start).Remove(0,end+1);
  1454. }
  1455. else
  1456. {
  1457. return src.Remove(0,end+1);
  1458. }
  1459. }
  1460. else
  1461. {
  1462. if (start < src.Length)
  1463. {
  1464. return src.Remove(start);
  1465. }
  1466. else
  1467. {
  1468. return src;
  1469. }
  1470. }
  1471. }
  1472. }
  1473. /// <summary>
  1474. /// Insert string inserts the specified string identified by src
  1475. /// at the index indicated by index. Index may be negative, in
  1476. /// which case it is end-relative. The index may exceed either
  1477. /// string bound, with the result being a concatenation.
  1478. /// </summary>
  1479. public string llInsertString(string dest, int index, string src)
  1480. {
  1481. m_host.AddScriptLPS(1);
  1482. // Normalize indices (if negative).
  1483. // After normlaization they may still be
  1484. // negative, but that is now relative to
  1485. // the start, rather than the end, of the
  1486. // sequence.
  1487. if (index < 0)
  1488. {
  1489. index = dest.Length+index;
  1490. // Negative now means it is less than the lower
  1491. // bound of the string.
  1492. if (index < 0)
  1493. {
  1494. return src+dest;
  1495. }
  1496. }
  1497. if (index >= dest.Length)
  1498. {
  1499. return dest+src;
  1500. }
  1501. // The index is in bounds.
  1502. // In this case the index refers to the index that will
  1503. // be assigned to the first character of the inserted string.
  1504. // So unlike the other string operations, we do not add one
  1505. // to get the correct string length.
  1506. return dest.Substring(0,index)+src+dest.Substring(index);
  1507. }
  1508. public string llToUpper(string src)
  1509. {
  1510. m_host.AddScriptLPS(1);
  1511. return src.ToUpper();
  1512. }
  1513. public string llToLower(string src)
  1514. {
  1515. m_host.AddScriptLPS(1);
  1516. return src.ToLower();
  1517. }
  1518. public LSL_Types.LSLInteger llGiveMoney(string destination, int amount)
  1519. {
  1520. LLUUID invItemID=InventorySelf();
  1521. if (invItemID == LLUUID.Zero)
  1522. return 0;
  1523. m_host.AddScriptLPS(1);
  1524. if (m_host.TaskInventory[invItemID].PermsGranter == LLUUID.Zero)
  1525. return 0;
  1526. if ((m_host.TaskInventory[invItemID].PermsMask & ScriptBaseClass.PERMISSION_DEBIT) == 0)
  1527. {
  1528. LSLError("No permissions to give money");
  1529. return 0;
  1530. }
  1531. LLUUID toID=new LLUUID();
  1532. if (!LLUUID.TryParse(destination, out toID))
  1533. {
  1534. LSLError("Bad key in llGiveMoney");
  1535. return 0;
  1536. }
  1537. IMoneyModule money=World.RequestModuleInterface<IMoneyModule>();
  1538. if (money == null)
  1539. {
  1540. NotImplemented("llGiveMoney");
  1541. return 0;
  1542. }
  1543. bool result=money.ObjectGiveMoney(m_host.ParentGroup.RootPart.UUID, m_host.ParentGroup.RootPart.OwnerID, toID, amount);
  1544. if (result)
  1545. return 1;
  1546. return 0;
  1547. }
  1548. public void llMakeExplosion()
  1549. {
  1550. m_host.AddScriptLPS(1);
  1551. NotImplemented("llMakeExplosion");
  1552. }
  1553. public void llMakeFountain()
  1554. {
  1555. m_host.AddScriptLPS(1);
  1556. NotImplemented("llMakeFountain");
  1557. }
  1558. public void llMakeSmoke()
  1559. {
  1560. m_host.AddScriptLPS(1);
  1561. NotImplemented("llMakeSmoke");
  1562. }
  1563. public void llMakeFire()
  1564. {
  1565. m_host.AddScriptLPS(1);
  1566. NotImplemented("llMakeFire");
  1567. }
  1568. public void llRezObject(string inventory, LSL_Types.Vector3 pos, LSL_Types.Vector3 vel, LSL_Types.Quaternion rot, int param)
  1569. {
  1570. m_host.AddScriptLPS(1);
  1571. //NotImplemented("llRezObject");
  1572. bool found = false;
  1573. // Instead of using return;, I'm using continue; because in our TaskInventory implementation
  1574. // it's possible to have two items with the same task inventory name.
  1575. // this is an easter egg of sorts.
  1576. foreach (KeyValuePair<LLUUID, TaskInventoryItem> inv in m_host.TaskInventory)
  1577. {
  1578. if (inv.Value.Name == inventory)
  1579. {
  1580. // make sure we're an object.
  1581. if (inv.Value.InvType != (int)InventoryType.Object)
  1582. {
  1583. llSay(0, "Unable to create requested object. Object is missing from database.");
  1584. continue;
  1585. }
  1586. LLVector3 llpos = new LLVector3((float)pos.x, (float)pos.y, (float)pos.z);
  1587. // test if we're further away then 10m
  1588. if (Util.GetDistanceTo(llpos, m_host.AbsolutePosition) > 10)
  1589. return; // wiki says, if it's further away then 10m, silently fail.
  1590. LLVector3 llvel = new LLVector3((float)vel.x, (float)vel.y, (float)vel.z);
  1591. // need the magnitude later
  1592. float velmag = (float)Util.GetMagnitude(llvel);
  1593. SceneObjectGroup new_group = World.RezObject(m_host, inv.Value, llpos, new LLQuaternion((float)rot.x, (float)rot.y, (float)rot.z, (float)rot.s), llvel, param);
  1594. // If either of these are null, then there was an unknown error.
  1595. if (new_group == null)
  1596. continue;
  1597. if (new_group.RootPart == null)
  1598. continue;
  1599. // objects rezzed with this method are die_at_edge by default.
  1600. new_group.RootPart.SetDieAtEdge(true);
  1601. m_ScriptEngine.PostScriptEvent(m_itemID, new EventParams(
  1602. "object_rez", new Object[] {
  1603. new LSL_Types.LSLString(
  1604. new_group.RootPart.UUID.ToString()) },
  1605. new DetectParams[0]));
  1606. float groupmass = new_group.GetMass();
  1607. //Recoil.
  1608. llApplyImpulse(new LSL_Types.Vector3(llvel.X * groupmass, llvel.Y * groupmass, llvel.Z * groupmass), 0);
  1609. found = true;
  1610. //script delay
  1611. System.Threading.Thread.Sleep((int)((groupmass * velmag) / 10));
  1612. break;
  1613. }
  1614. }
  1615. if (!found)
  1616. llSay(0, "Could not find object " + inventory);
  1617. }
  1618. public void llLookAt(LSL_Types.Vector3 target, double strength, double damping)
  1619. {
  1620. m_host.AddScriptLPS(1);
  1621. NotImplemented("llLookAt");
  1622. }
  1623. public void llStopLookAt()
  1624. {
  1625. m_host.AddScriptLPS(1);
  1626. NotImplemented("llStopLookAt");
  1627. }
  1628. public void llSetTimerEvent(double sec)
  1629. {
  1630. m_host.AddScriptLPS(1);
  1631. // Setting timer repeat
  1632. AsyncCommands.TimerPlugin.SetTimerEvent(m_localID, m_itemID, sec);
  1633. }
  1634. public void llSleep(double sec)
  1635. {
  1636. m_host.AddScriptLPS(1);
  1637. Thread.Sleep((int)(sec * 1000));
  1638. }
  1639. public double llGetMass()
  1640. {
  1641. m_host.AddScriptLPS(1);
  1642. return m_host.GetMass();
  1643. }
  1644. public void llCollisionFilter(string name, string id, int accept)
  1645. {
  1646. m_host.AddScriptLPS(1);
  1647. NotImplemented("llCollisionFilter");
  1648. }
  1649. public void llTakeControls(int controls, int accept, int pass_on)
  1650. {
  1651. if (!m_host.TaskInventory.ContainsKey(InventorySelf()))
  1652. {
  1653. return;
  1654. }
  1655. if (m_host.TaskInventory[InventorySelf()].PermsGranter != LLUUID.Zero)
  1656. {
  1657. ScenePresence presence = World.GetScenePresence(m_host.TaskInventory[InventorySelf()].PermsGranter);
  1658. if (presence != null)
  1659. {
  1660. if ((m_host.TaskInventory[InventorySelf()].PermsMask & ScriptBaseClass.PERMISSION_TAKE_CONTROLS) != 0)
  1661. {
  1662. presence.RegisterControlEventsToScript(controls, accept, pass_on, m_localID, m_itemID);
  1663. }
  1664. }
  1665. }
  1666. m_host.AddScriptLPS(1);
  1667. //NotImplemented("llTakeControls");
  1668. }
  1669. public void llReleaseControls()
  1670. {
  1671. m_host.AddScriptLPS(1);
  1672. if (!m_host.TaskInventory.ContainsKey(InventorySelf()))
  1673. {
  1674. return;
  1675. }
  1676. if (m_host.TaskInventory[InventorySelf()].PermsGranter != LLUUID.Zero)
  1677. {
  1678. ScenePresence presence = World.GetScenePresence(m_host.TaskInventory[InventorySelf()].PermsGranter);
  1679. if (presence != null)
  1680. {
  1681. if ((m_host.TaskInventory[InventorySelf()].PermsMask & ScriptBaseClass.PERMISSION_TAKE_CONTROLS) != 0)
  1682. {
  1683. // Unregister controls from Presence
  1684. presence.UnRegisterControlEventsToScript(m_localID, m_itemID);
  1685. // Remove Take Control permission.
  1686. m_host.TaskInventory[InventorySelf()].PermsMask &= ~ScriptBaseClass.PERMISSION_TAKE_CONTROLS;
  1687. }
  1688. }
  1689. }
  1690. }
  1691. public void llAttachToAvatar(int attachment)
  1692. {
  1693. m_host.AddScriptLPS(1);
  1694. NotImplemented("llAttachToAvatar");
  1695. }
  1696. public void llDetachFromAvatar()
  1697. {
  1698. m_host.AddScriptLPS(1);
  1699. NotImplemented("llDetachFromAvatar");
  1700. }
  1701. public void llTakeCamera(string avatar)
  1702. {
  1703. m_host.AddScriptLPS(1);
  1704. Deprecated("llTakeCamera");
  1705. }
  1706. public void llReleaseCamera(string avatar)
  1707. {
  1708. m_host.AddScriptLPS(1);
  1709. Deprecated("llReleaseCamera");
  1710. }
  1711. public string llGetOwner()
  1712. {
  1713. m_host.AddScriptLPS(1);
  1714. return m_host.ObjectOwner.ToString();
  1715. }
  1716. public void llInstantMessage(string user, string message)
  1717. {
  1718. m_host.AddScriptLPS(1);
  1719. // We may be able to use ClientView.SendInstantMessage here, but we need a client instance.
  1720. // InstantMessageModule.OnInstantMessage searches through a list of scenes for a client matching the toAgent,
  1721. // but I don't think we have a list of scenes available from here.
  1722. // (We also don't want to duplicate the code in OnInstantMessage if we can avoid it.)
  1723. // user is a UUID
  1724. // TODO: figure out values for client, fromSession, and imSessionID
  1725. // client.SendInstantMessage(m_host.UUID, fromSession, message, user, imSessionID, m_host.Name, AgentManager.InstantMessageDialog.MessageFromAgent, (uint)Util.UnixTimeSinceEpoch());
  1726. LLUUID friendTransactionID = LLUUID.Random();
  1727. //m_pendingFriendRequests.Add(friendTransactionID, fromAgentID);
  1728. GridInstantMessage msg = new GridInstantMessage();
  1729. msg.fromAgentID = new Guid(m_host.UUID.ToString()); // fromAgentID.UUID;
  1730. msg.fromAgentSession = new Guid(friendTransactionID.ToString());// fromAgentSession.UUID;
  1731. msg.toAgentID = new Guid(user); // toAgentID.UUID;
  1732. msg.imSessionID = new Guid(friendTransactionID.ToString()); // This is the item we're mucking with here
  1733. // Console.WriteLine("[Scripting IM]: From:" + msg.fromAgentID.ToString() + " To: " + msg.toAgentID.ToString() + " Session:" + msg.imSessionID.ToString() + " Message:" + message);
  1734. // Console.WriteLine("[Scripting IM]: Filling Session: " + msg.imSessionID.ToString());
  1735. msg.timestamp = (uint)Util.UnixTimeSinceEpoch();// timestamp;
  1736. //if (client != null)
  1737. //{
  1738. msg.fromAgentName = m_host.Name;//client.FirstName + " " + client.LastName;// fromAgentName;
  1739. //}
  1740. //else
  1741. //{
  1742. // msg.fromAgentName = "(hippos)";// Added for posterity. This means that we can't figure out who sent it
  1743. //}
  1744. msg.message = message;
  1745. msg.dialog = (byte)19; // messgage from script ??? // dialog;
  1746. msg.fromGroup = false;// fromGroup;
  1747. msg.offline = (byte)0; //offline;
  1748. msg.ParentEstateID = 0; //ParentEstateID;
  1749. msg.Position = new sLLVector3();// new sLLVector3(m_host.AbsolutePosition);
  1750. msg.RegionID = World.RegionInfo.RegionID.UUID;//RegionID.UUID;
  1751. msg.binaryBucket = new byte[0];// binaryBucket;
  1752. World.TriggerGridInstantMessage(msg, InstantMessageReceiver.IMModule);
  1753. // NotImplemented("llInstantMessage");
  1754. }
  1755. public void llEmail(string address, string subject, string message)
  1756. {
  1757. m_host.AddScriptLPS(1);
  1758. IEmailModule emailModule = m_ScriptEngine.World.RequestModuleInterface<IEmailModule>();
  1759. if (emailModule == null)
  1760. return;
  1761. emailModule.SendEmail(m_host.UUID, address, subject, message);
  1762. }
  1763. public void llGetNextEmail(string address, string subject)
  1764. {
  1765. m_host.AddScriptLPS(1);
  1766. IEmailModule emailModule = m_ScriptEngine.World.RequestModuleInterface<IEmailModule>();
  1767. if (emailModule == null)
  1768. return;
  1769. Email email;
  1770. email = emailModule.GetNextEmail(m_host.UUID, address, subject);
  1771. if (email == null)
  1772. return;
  1773. m_ScriptEngine.PostObjectEvent(m_host.LocalId,
  1774. new EventParams("email",
  1775. new Object[] {
  1776. new LSL_Types.LSLString(email.time),
  1777. new LSL_Types.LSLString(email.sender),
  1778. new LSL_Types.LSLString(email.subject),
  1779. new LSL_Types.LSLString(email.message),
  1780. new LSL_Types.LSLInteger(email.numLeft)},
  1781. new DetectParams[0]));
  1782. }
  1783. public string llGetKey()
  1784. {
  1785. m_host.AddScriptLPS(1);
  1786. return m_host.UUID.ToString();
  1787. }
  1788. public void llSetBuoyancy(double buoyancy)
  1789. {
  1790. m_host.AddScriptLPS(1);
  1791. if (m_host.ParentGroup != null)
  1792. {
  1793. if (m_host.ParentGroup.RootPart != null)
  1794. {
  1795. m_host.ParentGroup.RootPart.SetBuoyancy((float)buoyancy);
  1796. }
  1797. }
  1798. }
  1799. public void llSetHoverHeight(double height, int water, double tau)
  1800. {
  1801. m_host.AddScriptLPS(1);
  1802. NotImplemented("llSetHoverHeight");
  1803. }
  1804. public void llStopHover()
  1805. {
  1806. m_host.AddScriptLPS(1);
  1807. NotImplemented("llStopHover");
  1808. }
  1809. public void llMinEventDelay(double delay)
  1810. {
  1811. m_host.AddScriptLPS(1);
  1812. NotImplemented("llMinEventDelay");
  1813. }
  1814. public void llSoundPreload()
  1815. {
  1816. m_host.AddScriptLPS(1);
  1817. NotImplemented("llSoundPreload");
  1818. }
  1819. public void llRotLookAt(LSL_Types.Quaternion target, double strength, double damping)
  1820. {
  1821. m_host.AddScriptLPS(1);
  1822. NotImplemented("llRotLookAt");
  1823. }
  1824. public LSL_Types.LSLInteger llStringLength(string str)
  1825. {
  1826. m_host.AddScriptLPS(1);
  1827. if (str.Length > 0)
  1828. {
  1829. return str.Length;
  1830. }
  1831. else
  1832. {
  1833. return 0;
  1834. }
  1835. }
  1836. public void llStartAnimation(string anim)
  1837. {
  1838. m_host.AddScriptLPS(1);
  1839. LLUUID invItemID=InventorySelf();
  1840. if (invItemID == LLUUID.Zero)
  1841. return;
  1842. if (m_host.TaskInventory[invItemID].PermsGranter == LLUUID.Zero)
  1843. return;
  1844. if ((m_host.TaskInventory[invItemID].PermsMask & ScriptBaseClass.PERMISSION_TRIGGER_ANIMATION) != 0)
  1845. {
  1846. ScenePresence presence = World.GetScenePresence(m_host.TaskInventory[invItemID].PermsGranter);
  1847. if (presence != null)
  1848. {
  1849. // Do NOT try to parse LLUUID, animations cannot be triggered by ID
  1850. LLUUID animID=InventoryKey(anim, (int)AssetType.Animation);
  1851. if (animID == LLUUID.Zero)
  1852. presence.AddAnimation(anim);
  1853. else
  1854. presence.AddAnimation(animID);
  1855. }
  1856. }
  1857. }
  1858. public void llStopAnimation(string anim)
  1859. {
  1860. m_host.AddScriptLPS(1);
  1861. LLUUID invItemID=InventorySelf();
  1862. if (invItemID == LLUUID.Zero)
  1863. return;
  1864. if (m_host.TaskInventory[invItemID].PermsGranter == LLUUID.Zero)
  1865. return;
  1866. if ((m_host.TaskInventory[invItemID].PermsMask & ScriptBaseClass.PERMISSION_TRIGGER_ANIMATION) != 0)
  1867. {
  1868. LLUUID animID = new LLUUID();
  1869. if (!LLUUID.TryParse(anim, out animID))
  1870. {
  1871. animID=InventoryKey(anim);
  1872. }
  1873. if (animID == LLUUID.Zero)
  1874. return;
  1875. ScenePresence presence = World.GetScenePresence(m_host.TaskInventory[invItemID].PermsGranter);
  1876. if (presence != null)
  1877. {
  1878. if (animID == LLUUID.Zero)
  1879. presence.RemoveAnimation(anim);
  1880. else
  1881. presence.RemoveAnimation(animID);
  1882. }
  1883. }
  1884. }
  1885. public void llPointAt()
  1886. {
  1887. m_host.AddScriptLPS(1);
  1888. NotImplemented("llPointAt");
  1889. }
  1890. public void llStopPointAt()
  1891. {
  1892. m_host.AddScriptLPS(1);
  1893. NotImplemented("llStopPointAt");
  1894. }
  1895. public void llTargetOmega(LSL_Types.Vector3 axis, double spinrate, double gain)
  1896. {
  1897. m_host.AddScriptLPS(1);
  1898. m_host.RotationalVelocity = new LLVector3((float)(axis.x * spinrate), (float)(axis.y * spinrate), (float)(axis.z * spinrate));
  1899. m_host.AngularVelocity = new LLVector3((float)(axis.x * spinrate), (float)(axis.y * spinrate), (float)(axis.z * spinrate));
  1900. m_host.ScheduleTerseUpdate();
  1901. m_host.SendTerseUpdateToAllClients();
  1902. }
  1903. public LSL_Types.LSLInteger llGetStartParameter()
  1904. {
  1905. m_host.AddScriptLPS(1);
  1906. return m_ScriptEngine.GetStartParameter(m_itemID);
  1907. }
  1908. public void llGodLikeRezObject(string inventory, LSL_Types.Vector3 pos)
  1909. {
  1910. m_host.AddScriptLPS(1);
  1911. NotImplemented("llGodLikeRezObject");
  1912. }
  1913. public void llRequestPermissions(string agent, int perm)
  1914. {
  1915. LLUUID agentID=new LLUUID();
  1916. if (!LLUUID.TryParse(agent, out agentID))
  1917. return;
  1918. LLUUID invItemID=InventorySelf();
  1919. if (invItemID == LLUUID.Zero)
  1920. return; // Not in a prim? How??
  1921. if (agentID == LLUUID.Zero || perm == 0) // Releasing permissions
  1922. {
  1923. m_host.TaskInventory[invItemID].PermsGranter=LLUUID.Zero;
  1924. m_host.TaskInventory[invItemID].PermsMask=0;
  1925. m_ScriptEngine.PostScriptEvent(m_itemID, new EventParams(
  1926. "run_time_permissions", new Object[] {
  1927. new LSL_Types.LSLInteger(0) },
  1928. new DetectParams[0]));
  1929. return;
  1930. }
  1931. m_host.AddScriptLPS(1);
  1932. if (m_host.ParentGroup.RootPart.m_IsAttachment && agent == m_host.ParentGroup.RootPart.m_attachedAvatar)
  1933. {
  1934. // When attached, certain permissions are implicit if requested from owner
  1935. int implicitPerms = ScriptBaseClass.PERMISSION_TAKE_CONTROLS |
  1936. ScriptBaseClass.PERMISSION_TRIGGER_ANIMATION |
  1937. ScriptBaseClass.PERMISSION_ATTACH;
  1938. if ((perm & (~implicitPerms)) == 0) // Requested only implicit perms
  1939. {
  1940. m_host.TaskInventory[invItemID].PermsGranter=agentID;
  1941. m_host.TaskInventory[invItemID].PermsMask=perm;
  1942. m_ScriptEngine.PostScriptEvent(m_itemID, new EventParams(
  1943. "run_time_permissions", new Object[] {
  1944. new LSL_Types.LSLInteger(perm) },
  1945. new DetectParams[0]));
  1946. return;
  1947. }
  1948. }
  1949. else if (m_host.SitTargetAvatar == agentID) // Sitting avatar
  1950. {
  1951. // When agent is sitting, certain permissions are implicit if requested from sitting agent
  1952. int implicitPerms = ScriptBaseClass.PERMISSION_TRIGGER_ANIMATION |
  1953. ScriptBaseClass.PERMISSION_TRACK_CAMERA;
  1954. if ((perm & (~implicitPerms)) == 0) // Requested only implicit perms
  1955. {
  1956. m_host.TaskInventory[invItemID].PermsGranter=agentID;
  1957. m_host.TaskInventory[invItemID].PermsMask=perm;
  1958. m_ScriptEngine.PostScriptEvent(m_itemID, new EventParams(
  1959. "run_time_permissions", new Object[] {
  1960. new LSL_Types.LSLInteger(perm) },
  1961. new DetectParams[0]));
  1962. return;
  1963. }
  1964. }
  1965. ScenePresence presence = World.GetScenePresence(agentID);
  1966. if (presence != null)
  1967. {
  1968. string ownerName=resolveName(m_host.ParentGroup.RootPart.OwnerID);
  1969. if (ownerName == String.Empty)
  1970. ownerName="(hippos)";
  1971. if (!m_waitingForScriptAnswer)
  1972. {
  1973. m_host.TaskInventory[invItemID].PermsGranter=agentID;
  1974. m_host.TaskInventory[invItemID].PermsMask=0;
  1975. presence.ControllingClient.OnScriptAnswer+=handleScriptAnswer;
  1976. m_waitingForScriptAnswer=true;
  1977. }
  1978. presence.ControllingClient.SendScriptQuestion(m_host.UUID, m_host.ParentGroup.RootPart.Name, ownerName, invItemID, perm);
  1979. return;
  1980. }
  1981. // Requested agent is not in range, refuse perms
  1982. m_ScriptEngine.PostScriptEvent(m_itemID, new EventParams(
  1983. "run_time_permissions", new Object[] {
  1984. new LSL_Types.LSLInteger(0) },
  1985. new DetectParams[0]));
  1986. }
  1987. void handleScriptAnswer(IClientAPI client, LLUUID taskID, LLUUID itemID, int answer)
  1988. {
  1989. if (taskID != m_host.UUID)
  1990. return;
  1991. LLUUID invItemID=InventorySelf();
  1992. if (invItemID == LLUUID.Zero)
  1993. return;
  1994. client.OnScriptAnswer-=handleScriptAnswer;
  1995. m_waitingForScriptAnswer=false;
  1996. m_host.TaskInventory[invItemID].PermsMask=answer;
  1997. m_ScriptEngine.PostScriptEvent(m_itemID, new EventParams(
  1998. "run_time_permissions", new Object[] {
  1999. new LSL_Types.LSLInteger(answer) },
  2000. new DetectParams[0]));
  2001. }
  2002. public string llGetPermissionsKey()
  2003. {
  2004. m_host.AddScriptLPS(1);
  2005. foreach (TaskInventoryItem item in m_host.TaskInventory.Values)
  2006. {
  2007. if (item.Type == 10 && item.ItemID == m_itemID)
  2008. {
  2009. return item.PermsGranter.ToString();
  2010. }
  2011. }
  2012. return LLUUID.Zero.ToString();
  2013. }
  2014. public LSL_Types.LSLInteger llGetPermissions()
  2015. {
  2016. m_host.AddScriptLPS(1);
  2017. foreach (TaskInventoryItem item in m_host.TaskInventory.Values)
  2018. {
  2019. if (item.Type == 10 && item.ItemID == m_itemID)
  2020. {
  2021. return item.PermsMask;
  2022. }
  2023. }
  2024. return 0;
  2025. }
  2026. public LSL_Types.LSLInteger llGetLinkNumber()
  2027. {
  2028. m_host.AddScriptLPS(1);
  2029. if (m_host.ParentGroup.Children.Count > 0)
  2030. {
  2031. return m_host.LinkNum + 1;
  2032. }
  2033. else
  2034. {
  2035. return 0;
  2036. }
  2037. }
  2038. public void llSetLinkColor(int linknumber, LSL_Types.Vector3 color, int face)
  2039. {
  2040. m_host.AddScriptLPS(1);
  2041. SceneObjectPart part = m_host.ParentGroup.GetLinkNumPart(linknumber);
  2042. if (linknumber > -1)
  2043. {
  2044. LLObject.TextureEntry tex = part.Shape.Textures;
  2045. LLColor texcolor;
  2046. if (face > -1)
  2047. {
  2048. texcolor = tex.CreateFace((uint)face).RGBA;
  2049. texcolor.R = (float)Math.Abs(color.x - 1);
  2050. texcolor.G = (float)Math.Abs(color.y - 1);
  2051. texcolor.B = (float)Math.Abs(color.z - 1);
  2052. tex.FaceTextures[face].RGBA = texcolor;
  2053. part.UpdateTexture(tex);
  2054. return;
  2055. }
  2056. else if (face == -1)
  2057. {
  2058. texcolor = tex.DefaultTexture.RGBA;
  2059. texcolor.R = (float)Math.Abs(color.x - 1);
  2060. texcolor.G = (float)Math.Abs(color.y - 1);
  2061. texcolor.B = (float)Math.Abs(color.z - 1);
  2062. tex.DefaultTexture.RGBA = texcolor;
  2063. for (uint i = 0; i < 32; i++)
  2064. {
  2065. if (tex.FaceTextures[i] != null)
  2066. {
  2067. texcolor = tex.FaceTextures[i].RGBA;
  2068. texcolor.R = (float)Math.Abs(color.x - 1);
  2069. texcolor.G = (float)Math.Abs(color.y - 1);
  2070. texcolor.B = (float)Math.Abs(color.z - 1);
  2071. tex.FaceTextures[i].RGBA = texcolor;
  2072. }
  2073. }
  2074. texcolor = tex.DefaultTexture.RGBA;
  2075. texcolor.R = (float)Math.Abs(color.x - 1);
  2076. texcolor.G = (float)Math.Abs(color.y - 1);
  2077. texcolor.B = (float)Math.Abs(color.z - 1);
  2078. tex.DefaultTexture.RGBA = texcolor;
  2079. part.UpdateTexture(tex);
  2080. return;
  2081. }
  2082. return;
  2083. }
  2084. else if (linknumber == -1)
  2085. {
  2086. int num = m_host.ParentGroup.PrimCount;
  2087. for (int w = 0; w < num; w++)
  2088. {
  2089. linknumber = w;
  2090. part = m_host.ParentGroup.GetLinkNumPart(linknumber);
  2091. LLObject.TextureEntry tex = part.Shape.Textures;
  2092. LLColor texcolor;
  2093. if (face > -1)
  2094. {
  2095. texcolor = tex.CreateFace((uint)face).RGBA;
  2096. texcolor.R = (float)Math.Abs(color.x - 1);
  2097. texcolor.G = (float)Math.Abs(color.y - 1);
  2098. texcolor.B = (float)Math.Abs(color.z - 1);
  2099. tex.FaceTextures[face].RGBA = texcolor;
  2100. part.UpdateTexture(tex);
  2101. }
  2102. else if (face == -1)
  2103. {
  2104. texcolor = tex.DefaultTexture.RGBA;
  2105. texcolor.R = (float)Math.Abs(color.x - 1);
  2106. texcolor.G = (float)Math.Abs(color.y - 1);
  2107. texcolor.B = (float)Math.Abs(color.z - 1);
  2108. tex.DefaultTexture.RGBA = texcolor;
  2109. for (uint i = 0; i < 32; i++)
  2110. {
  2111. if (tex.FaceTextures[i] != null)
  2112. {
  2113. texcolor = tex.FaceTextures[i].RGBA;
  2114. texcolor.R = (float)Math.Abs(color.x - 1);
  2115. texcolor.G = (float)Math.Abs(color.y - 1);
  2116. texcolor.B = (float)Math.Abs(color.z - 1);
  2117. tex.FaceTextures[i].RGBA = texcolor;
  2118. }
  2119. }
  2120. texcolor = tex.DefaultTexture.RGBA;
  2121. texcolor.R = (float)Math.Abs(color.x - 1);
  2122. texcolor.G = (float)Math.Abs(color.y - 1);
  2123. texcolor.B = (float)Math.Abs(color.z - 1);
  2124. tex.DefaultTexture.RGBA = texcolor;
  2125. part.UpdateTexture(tex);
  2126. }
  2127. }
  2128. return;
  2129. }
  2130. }
  2131. public void llCreateLink(string target, int parent)
  2132. {
  2133. m_host.AddScriptLPS(1);
  2134. NotImplemented("llCreateLink");
  2135. }
  2136. public void llBreakLink(int linknum)
  2137. {
  2138. m_host.AddScriptLPS(1);
  2139. NotImplemented("llBreakLink");
  2140. }
  2141. public void llBreakAllLinks()
  2142. {
  2143. m_host.AddScriptLPS(1);
  2144. NotImplemented("llBreakAllLinks");
  2145. }
  2146. public string llGetLinkKey(int linknum)
  2147. {
  2148. m_host.AddScriptLPS(1);
  2149. SceneObjectPart part = m_host.ParentGroup.GetLinkNumPart(linknum);
  2150. if (part != null)
  2151. {
  2152. return part.UUID.ToString();
  2153. }
  2154. else
  2155. {
  2156. return LLUUID.Zero.ToString();
  2157. }
  2158. }
  2159. public string llGetLinkName(int linknum)
  2160. {
  2161. m_host.AddScriptLPS(1);
  2162. SceneObjectPart part = m_host.ParentGroup.GetLinkNumPart(linknum);
  2163. if (part != null)
  2164. {
  2165. return part.Name;
  2166. }
  2167. else
  2168. {
  2169. return LLUUID.Zero.ToString();
  2170. }
  2171. }
  2172. public LSL_Types.LSLInteger llGetInventoryNumber(int type)
  2173. {
  2174. m_host.AddScriptLPS(1);
  2175. int count = 0;
  2176. foreach (KeyValuePair<LLUUID, TaskInventoryItem> inv in m_host.TaskInventory)
  2177. {
  2178. if (inv.Value.Type == type || type == -1)
  2179. {
  2180. count = count + 1;
  2181. }
  2182. }
  2183. return count;
  2184. }
  2185. public string llGetInventoryName(int type, int number)
  2186. {
  2187. m_host.AddScriptLPS(1);
  2188. ArrayList keys = new ArrayList();
  2189. foreach (KeyValuePair<LLUUID, TaskInventoryItem> inv in m_host.TaskInventory)
  2190. {
  2191. if (inv.Value.Type == type || type == -1)
  2192. {
  2193. keys.Add(inv.Value.Name);
  2194. }
  2195. }
  2196. if (keys.Count == 0)
  2197. {
  2198. return String.Empty;
  2199. }
  2200. keys.Sort();
  2201. if (keys.Count > number)
  2202. {
  2203. return (string)keys[number];
  2204. }
  2205. return String.Empty;
  2206. }
  2207. public void llSetScriptState(string name, int run)
  2208. {
  2209. LLUUID item;
  2210. m_host.AddScriptLPS(1);
  2211. // These functions are supposed to be robust,
  2212. // so get the state one step at a time.
  2213. if ((item = ScriptByName(name)) != LLUUID.Zero)
  2214. {
  2215. m_ScriptEngine.SetScriptState(item, run == 0 ? false : true);
  2216. }
  2217. else
  2218. {
  2219. ShoutError("llSetScriptState: script "+name+" not found");
  2220. }
  2221. }
  2222. public double llGetEnergy()
  2223. {
  2224. m_host.AddScriptLPS(1);
  2225. // TODO: figure out real energy value
  2226. return 1.0f;
  2227. }
  2228. public void llGiveInventory(string destination, string inventory)
  2229. {
  2230. m_host.AddScriptLPS(1);
  2231. bool found = false;
  2232. LLUUID destId = LLUUID.Zero;
  2233. LLUUID objId = LLUUID.Zero;
  2234. if (!LLUUID.TryParse(destination, out destId))
  2235. {
  2236. llSay(0, "Could not parse key " + destination);
  2237. return;
  2238. }
  2239. // move the first object found with this inventory name
  2240. foreach (KeyValuePair<LLUUID, TaskInventoryItem> inv in m_host.TaskInventory)
  2241. {
  2242. if (inv.Value.Name == inventory)
  2243. {
  2244. found = true;
  2245. objId = inv.Key;
  2246. break;
  2247. }
  2248. }
  2249. // check if destination is an avatar
  2250. if (World.GetScenePresence(destId) != null)
  2251. {
  2252. // destination is an avatar
  2253. World.MoveTaskInventoryItem(destId, null, m_host, objId);
  2254. }
  2255. else
  2256. {
  2257. // destination is an object
  2258. World.MoveTaskInventoryItem(destId, m_host, objId);
  2259. }
  2260. if (!found)
  2261. llSay(0, "Could not find object " + inventory);
  2262. }
  2263. public void llRemoveInventory(string item)
  2264. {
  2265. m_host.AddScriptLPS(1);
  2266. NotImplemented("llRemoveInventory");
  2267. }
  2268. public void llSetText(string text, LSL_Types.Vector3 color, double alpha)
  2269. {
  2270. m_host.AddScriptLPS(1);
  2271. Vector3 av3 = new Vector3((float)color.x, (float)color.y, (float)color.z);
  2272. m_host.SetText(text, av3, alpha);
  2273. }
  2274. public double llWater(LSL_Types.Vector3 offset)
  2275. {
  2276. m_host.AddScriptLPS(1);
  2277. return World.RegionInfo.EstateSettings.waterHeight;
  2278. }
  2279. public void llPassTouches(int pass)
  2280. {
  2281. m_host.AddScriptLPS(1);
  2282. NotImplemented("llPassTouches");
  2283. }
  2284. public string llRequestAgentData(string id, int data)
  2285. {
  2286. m_host.AddScriptLPS(1);
  2287. UserProfileData userProfile =
  2288. World.CommsManager.UserService.GetUserProfile(id);
  2289. UserAgentData userAgent =
  2290. World.CommsManager.UserService.GetAgentByUUID(id);
  2291. if (userProfile == null || userAgent == null)
  2292. return LLUUID.Zero.ToString();
  2293. string reply = String.Empty;
  2294. switch (data)
  2295. {
  2296. case 1: // DATA_ONLINE (0|1)
  2297. // TODO: implement fetching of this information
  2298. if (userProfile.CurrentAgent.AgentOnline)
  2299. reply = "1";
  2300. else
  2301. reply = "0";
  2302. break;
  2303. case 2: // DATA_NAME (First Last)
  2304. reply = userProfile.FirstName + " " + userProfile.SurName;
  2305. break;
  2306. case 3: // DATA_BORN (YYYY-MM-DD)
  2307. DateTime born = new DateTime(1970, 1, 1, 0, 0, 0, 0);
  2308. born = born.AddSeconds(userProfile.Created);
  2309. reply = born.ToString("yyyy-MM-dd");
  2310. break;
  2311. case 4: // DATA_RATING (0,0,0,0,0,0)
  2312. reply = "0,0,0,0,0,0";
  2313. break;
  2314. case 8: // DATA_PAYINFO (0|1|2|3)
  2315. reply = "0";
  2316. break;
  2317. default:
  2318. return LLUUID.Zero.ToString(); // Raise no event
  2319. }
  2320. LLUUID rq = LLUUID.Random();
  2321. LLUUID tid = AsyncCommands.
  2322. DataserverPlugin.RegisterRequest(m_localID,
  2323. m_itemID, rq.ToString());
  2324. AsyncCommands.
  2325. DataserverPlugin.DataserverReply(rq.ToString(), reply);
  2326. return tid.ToString();
  2327. }
  2328. public string llRequestInventoryData(string name)
  2329. {
  2330. m_host.AddScriptLPS(1);
  2331. foreach (TaskInventoryItem item in m_host.TaskInventory.Values)
  2332. {
  2333. if (item.Type == 3 && item.Name == name)
  2334. {
  2335. LLUUID tid = AsyncCommands.
  2336. DataserverPlugin.RegisterRequest(m_localID,
  2337. m_itemID, item.AssetID.ToString());
  2338. LLVector3 region = new LLVector3(
  2339. World.RegionInfo.RegionLocX * Constants.RegionSize,
  2340. World.RegionInfo.RegionLocY * Constants.RegionSize,
  2341. 0);
  2342. World.AssetCache.GetAsset(item.AssetID,
  2343. delegate(LLUUID i, AssetBase a)
  2344. {
  2345. AssetLandmark lm = new AssetLandmark(a);
  2346. region += lm.Position;
  2347. string reply = region.ToString();
  2348. AsyncCommands.
  2349. DataserverPlugin.DataserverReply(i.ToString(),
  2350. reply);
  2351. }, false);
  2352. return tid.ToString();
  2353. }
  2354. }
  2355. return String.Empty;
  2356. }
  2357. public void llSetDamage(double damage)
  2358. {
  2359. m_host.AddScriptLPS(1);
  2360. NotImplemented("llSetDamage");
  2361. }
  2362. public void llTeleportAgentHome(string agent)
  2363. {
  2364. m_host.AddScriptLPS(1);
  2365. NotImplemented("llTeleportAgentHome");
  2366. }
  2367. public void llModifyLand(int action, int brush)
  2368. {
  2369. m_host.AddScriptLPS(1);
  2370. World.ExternalChecks.ExternalChecksCanTerraformLand(m_host.OwnerID, new LLVector3(m_host.AbsolutePosition.X, m_host.AbsolutePosition.Y, 0));
  2371. }
  2372. public void llCollisionSound(string impact_sound, double impact_volume)
  2373. {
  2374. m_host.AddScriptLPS(1);
  2375. NotImplemented("llCollisionSound");
  2376. }
  2377. public void llCollisionSprite(string impact_sprite)
  2378. {
  2379. m_host.AddScriptLPS(1);
  2380. NotImplemented("llCollisionSprite");
  2381. }
  2382. public string llGetAnimation(string id)
  2383. {
  2384. m_host.AddScriptLPS(1);
  2385. NotImplemented("llGetAnimation");
  2386. return String.Empty;
  2387. }
  2388. public void llResetScript()
  2389. {
  2390. m_host.AddScriptLPS(1);
  2391. m_ScriptEngine.ApiResetScript(m_itemID);
  2392. throw new EventAbortException();
  2393. }
  2394. public void llMessageLinked(int linknum, int num, string msg, string id)
  2395. {
  2396. m_host.AddScriptLPS(1);
  2397. // uint partLocalID;
  2398. LLUUID partItemID;
  2399. switch ((int)linknum)
  2400. {
  2401. case (int)ScriptBaseClass.LINK_ROOT:
  2402. SceneObjectPart part = m_host.ParentGroup.RootPart;
  2403. foreach (TaskInventoryItem item in part.TaskInventory.Values)
  2404. {
  2405. if (item.Type == 10)
  2406. {
  2407. // partLocalID = part.LocalId;
  2408. partItemID = item.ItemID;
  2409. object[] resobj = new object[]
  2410. {
  2411. new LSL_Types.LSLInteger(m_host.LinkNum + 1), new LSL_Types.LSLInteger(num), new LSL_Types.LSLString(msg), new LSL_Types.LSLString(id)
  2412. };
  2413. m_ScriptEngine.PostScriptEvent(partItemID,
  2414. new EventParams("link_message",
  2415. resobj, new DetectParams[0]));
  2416. }
  2417. }
  2418. break;
  2419. case (int)ScriptBaseClass.LINK_SET:
  2420. foreach (SceneObjectPart partInst in m_host.ParentGroup.GetParts())
  2421. {
  2422. foreach (TaskInventoryItem item in partInst.TaskInventory.Values)
  2423. {
  2424. if (item.Type == 10)
  2425. {
  2426. // partLocalID = partInst.LocalId;
  2427. partItemID = item.ItemID;
  2428. Object[] resobj = new object[]
  2429. {
  2430. new LSL_Types.LSLInteger(m_host.LinkNum + 1), new LSL_Types.LSLInteger(num), new LSL_Types.LSLString(msg), new LSL_Types.LSLString(id)
  2431. };
  2432. m_ScriptEngine.PostScriptEvent(partItemID,
  2433. new EventParams("link_message",
  2434. resobj, new DetectParams[0]));
  2435. }
  2436. }
  2437. }
  2438. break;
  2439. case (int)ScriptBaseClass.LINK_ALL_OTHERS:
  2440. foreach (SceneObjectPart partInst in m_host.ParentGroup.GetParts())
  2441. {
  2442. if (partInst.LocalId != m_host.LocalId)
  2443. {
  2444. foreach (TaskInventoryItem item in partInst.TaskInventory.Values)
  2445. {
  2446. if (item.Type == 10)
  2447. {
  2448. // partLocalID = partInst.LocalId;
  2449. partItemID = item.ItemID;
  2450. Object[] resobj = new object[]
  2451. {
  2452. new LSL_Types.LSLInteger(m_host.LinkNum + 1), new LSL_Types.LSLInteger(num), new LSL_Types.LSLString(msg), new LSL_Types.LSLString(id)
  2453. };
  2454. m_ScriptEngine.PostScriptEvent(partItemID,
  2455. new EventParams("link_message",
  2456. resobj, new DetectParams[0]));
  2457. }
  2458. }
  2459. }
  2460. }
  2461. break;
  2462. case (int)ScriptBaseClass.LINK_ALL_CHILDREN:
  2463. foreach (SceneObjectPart partInst in m_host.ParentGroup.GetParts())
  2464. {
  2465. if (partInst.LocalId != m_host.ParentGroup.RootPart.LocalId)
  2466. {
  2467. foreach (TaskInventoryItem item in partInst.TaskInventory.Values)
  2468. {
  2469. if (item.Type == 10)
  2470. {
  2471. // partLocalID = partInst.LocalId;
  2472. partItemID = item.ItemID;
  2473. Object[] resobj = new object[]
  2474. {
  2475. new LSL_Types.LSLInteger(m_host.LinkNum + 1), new LSL_Types.LSLInteger(num), new LSL_Types.LSLString(msg), new LSL_Types.LSLString(id)
  2476. };
  2477. m_ScriptEngine.PostScriptEvent(partItemID,
  2478. new EventParams("link_message",
  2479. resobj, new DetectParams[0]));
  2480. }
  2481. }
  2482. }
  2483. }
  2484. break;
  2485. case (int)ScriptBaseClass.LINK_THIS:
  2486. foreach (TaskInventoryItem item in m_host.TaskInventory.Values)
  2487. {
  2488. if (item.Type == 10)
  2489. {
  2490. partItemID = item.ItemID;
  2491. object[] resobj = new object[]
  2492. {
  2493. new LSL_Types.LSLInteger(m_host.LinkNum + 1), new LSL_Types.LSLInteger(num), new LSL_Types.LSLString(msg), new LSL_Types.LSLString(id)
  2494. };
  2495. m_ScriptEngine.PostScriptEvent(partItemID,
  2496. new EventParams("link_message",
  2497. resobj, new DetectParams[0]));
  2498. }
  2499. }
  2500. break;
  2501. default:
  2502. foreach (SceneObjectPart partInst in m_host.ParentGroup.GetParts())
  2503. {
  2504. if ((partInst.LinkNum + 1) == linknum)
  2505. {
  2506. foreach (TaskInventoryItem item in partInst.TaskInventory.Values)
  2507. {
  2508. if (item.Type == 10)
  2509. {
  2510. // partLocalID = partInst.LocalId;
  2511. partItemID = item.ItemID;
  2512. Object[] resObjDef = new object[]
  2513. {
  2514. new LSL_Types.LSLInteger(m_host.LinkNum + 1), new LSL_Types.LSLInteger(num), new LSL_Types.LSLString(msg), new LSL_Types.LSLString(id)
  2515. };
  2516. m_ScriptEngine.PostScriptEvent(partItemID,
  2517. new EventParams("link_message",
  2518. resObjDef, new DetectParams[0]));
  2519. }
  2520. }
  2521. }
  2522. }
  2523. break;
  2524. }
  2525. }
  2526. public void llPushObject(string target, LSL_Types.Vector3 impulse, LSL_Types.Vector3 ang_impulse, int local)
  2527. {
  2528. m_host.AddScriptLPS(1);
  2529. NotImplemented("llPushObject");
  2530. }
  2531. public void llPassCollisions(int pass)
  2532. {
  2533. m_host.AddScriptLPS(1);
  2534. NotImplemented("llPassCollisions");
  2535. }
  2536. public string llGetScriptName()
  2537. {
  2538. string result = String.Empty;
  2539. m_host.AddScriptLPS(1);
  2540. foreach (TaskInventoryItem item in m_host.TaskInventory.Values)
  2541. {
  2542. if (item.Type == 10 && item.ItemID == m_itemID)
  2543. {
  2544. result = item.Name!=null?item.Name:String.Empty;
  2545. break;
  2546. }
  2547. }
  2548. return result;
  2549. }
  2550. public LSL_Types.LSLInteger llGetNumberOfSides()
  2551. {
  2552. m_host.AddScriptLPS(1);
  2553. NotImplemented("llGetNumberOfSides");
  2554. return 0;
  2555. }
  2556. /* The new / changed functions were tested with the following LSL script:
  2557. default
  2558. {
  2559. state_entry()
  2560. {
  2561. rotation rot = llEuler2Rot(<0,70,0> * DEG_TO_RAD);
  2562. llOwnerSay("to get here, we rotate over: "+ (string) llRot2Axis(rot));
  2563. llOwnerSay("and we rotate for: "+ (llRot2Angle(rot) * RAD_TO_DEG));
  2564. // convert back and forth between quaternion <-> vector and angle
  2565. rotation newrot = llAxisAngle2Rot(llRot2Axis(rot),llRot2Angle(rot));
  2566. llOwnerSay("Old rotation was: "+(string) rot);
  2567. llOwnerSay("re-converted rotation is: "+(string) newrot);
  2568. llSetRot(rot); // to check the parameters in the prim
  2569. }
  2570. }
  2571. */
  2572. // Xantor 29/apr/2008
  2573. // Returns rotation described by rotating angle radians about axis.
  2574. // q = cos(a/2) + i (x * sin(a/2)) + j (y * sin(a/2)) + k (z * sin(a/2))
  2575. public LSL_Types.Quaternion llAxisAngle2Rot(LSL_Types.Vector3 axis, double angle)
  2576. {
  2577. m_host.AddScriptLPS(1);
  2578. double x, y, z, s, t;
  2579. s = Math.Cos(angle / 2);
  2580. t = Math.Sin(angle / 2); // temp value to avoid 2 more sin() calcs
  2581. x = axis.x * t;
  2582. y = axis.y * t;
  2583. z = axis.z * t;
  2584. return new LSL_Types.Quaternion(x,y,z,s);
  2585. }
  2586. // Xantor 29/apr/2008
  2587. // converts a Quaternion to X,Y,Z axis rotations
  2588. public LSL_Types.Vector3 llRot2Axis(LSL_Types.Quaternion rot)
  2589. {
  2590. m_host.AddScriptLPS(1);
  2591. double x,y,z;
  2592. if (rot.s > 1) // normalization needed
  2593. {
  2594. double length = Math.Sqrt(rot.x * rot.x + rot.y * rot.y +
  2595. rot.z * rot.z + rot.s * rot.s);
  2596. rot.x /= length;
  2597. rot.y /= length;
  2598. rot.z /= length;
  2599. rot.s /= length;
  2600. }
  2601. // double angle = 2 * Math.Acos(rot.s);
  2602. double s = Math.Sqrt(1 - rot.s * rot.s);
  2603. if (s < 0.001)
  2604. {
  2605. x = 1;
  2606. y = z = 0;
  2607. }
  2608. else
  2609. {
  2610. x = rot.x / s; // normalise axis
  2611. y = rot.y / s;
  2612. z = rot.z / s;
  2613. }
  2614. return new LSL_Types.Vector3(x,y,z);
  2615. // NotImplemented("llRot2Axis");
  2616. }
  2617. // Returns the angle of a quaternion (see llRot2Axis for the axis)
  2618. public double llRot2Angle(LSL_Types.Quaternion rot)
  2619. {
  2620. m_host.AddScriptLPS(1);
  2621. if (rot.s > 1) // normalization needed
  2622. {
  2623. double length = Math.Sqrt(rot.x * rot.x + rot.y * rot.y +
  2624. rot.z * rot.z + rot.s * rot.s);
  2625. rot.x /= length;
  2626. rot.y /= length;
  2627. rot.z /= length;
  2628. rot.s /= length;
  2629. }
  2630. double angle = 2 * Math.Acos(rot.s);
  2631. return angle;
  2632. // NotImplemented("llRot2Angle");
  2633. }
  2634. public double llAcos(double val)
  2635. {
  2636. m_host.AddScriptLPS(1);
  2637. return (double)Math.Acos(val);
  2638. }
  2639. public double llAsin(double val)
  2640. {
  2641. m_host.AddScriptLPS(1);
  2642. return (double)Math.Asin(val);
  2643. }
  2644. // Xantor 30/apr/2008
  2645. public double llAngleBetween(LSL_Types.Quaternion a, LSL_Types.Quaternion b)
  2646. {
  2647. m_host.AddScriptLPS(1);
  2648. return (double) Math.Acos(a.x * b.x + a.y * b.y + a.z * b.z + a.s * b.s) * 2;
  2649. }
  2650. public string llGetInventoryKey(string name)
  2651. {
  2652. m_host.AddScriptLPS(1);
  2653. foreach (KeyValuePair<LLUUID, TaskInventoryItem> inv in m_host.TaskInventory)
  2654. {
  2655. if (inv.Value.Name == name)
  2656. {
  2657. if ((inv.Value.OwnerMask & (uint)(PermissionMask.Copy | PermissionMask.Transfer | PermissionMask.Modify)) == (uint)(PermissionMask.Copy | PermissionMask.Transfer | PermissionMask.Modify))
  2658. {
  2659. return inv.Value.AssetID.ToString();
  2660. }
  2661. else
  2662. {
  2663. return LLUUID.Zero.ToString();
  2664. }
  2665. }
  2666. }
  2667. return LLUUID.Zero.ToString();
  2668. }
  2669. public void llAllowInventoryDrop(int add)
  2670. {
  2671. m_host.AddScriptLPS(1);
  2672. if (add != 0)
  2673. m_host.ParentGroup.RootPart.AllowedDrop = true;
  2674. else
  2675. m_host.ParentGroup.RootPart.AllowedDrop = false;
  2676. }
  2677. public LSL_Types.Vector3 llGetSunDirection()
  2678. {
  2679. m_host.AddScriptLPS(1);
  2680. LSL_Types.Vector3 SunDoubleVector3;
  2681. LLVector3 SunFloatVector3;
  2682. // sunPosition estate setting is set in OpenSim.Region.Environment.Modules.SunModule
  2683. // have to convert from LLVector3 (float) to LSL_Types.Vector3 (double)
  2684. SunFloatVector3 = World.RegionInfo.EstateSettings.sunPosition;
  2685. SunDoubleVector3.x = (double)SunFloatVector3.X;
  2686. SunDoubleVector3.y = (double)SunFloatVector3.Y;
  2687. SunDoubleVector3.z = (double)SunFloatVector3.Z;
  2688. return SunDoubleVector3;
  2689. }
  2690. public LSL_Types.Vector3 llGetTextureOffset(int face)
  2691. {
  2692. m_host.AddScriptLPS(1);
  2693. LLObject.TextureEntry tex = m_host.Shape.Textures;
  2694. LSL_Types.Vector3 offset;
  2695. if (face == -1)
  2696. {
  2697. face = 0;
  2698. }
  2699. offset.x = tex.GetFace((uint)face).OffsetU;
  2700. offset.y = tex.GetFace((uint)face).OffsetV;
  2701. offset.z = 0.0;
  2702. return offset;
  2703. }
  2704. public LSL_Types.Vector3 llGetTextureScale(int side)
  2705. {
  2706. m_host.AddScriptLPS(1);
  2707. LLObject.TextureEntry tex = m_host.Shape.Textures;
  2708. LSL_Types.Vector3 scale;
  2709. if (side == -1)
  2710. {
  2711. side = 0;
  2712. }
  2713. scale.x = tex.GetFace((uint)side).RepeatU;
  2714. scale.y = tex.GetFace((uint)side).RepeatV;
  2715. scale.z = 0.0;
  2716. return scale;
  2717. }
  2718. public double llGetTextureRot(int face)
  2719. {
  2720. m_host.AddScriptLPS(1);
  2721. LLObject.TextureEntry tex = m_host.Shape.Textures;
  2722. if (face == -1)
  2723. {
  2724. face = 0;
  2725. }
  2726. return tex.GetFace((uint)face).Rotation;
  2727. }
  2728. public LSL_Types.LSLInteger llSubStringIndex(string source, string pattern)
  2729. {
  2730. m_host.AddScriptLPS(1);
  2731. return source.IndexOf(pattern);
  2732. }
  2733. public string llGetOwnerKey(string id)
  2734. {
  2735. m_host.AddScriptLPS(1);
  2736. LLUUID key = new LLUUID();
  2737. if (LLUUID.TryParse(id, out key))
  2738. {
  2739. return World.GetSceneObjectPart(World.Entities[key].LocalId).OwnerID.ToString();
  2740. }
  2741. else
  2742. {
  2743. return LLUUID.Zero.ToString();
  2744. }
  2745. }
  2746. public LSL_Types.Vector3 llGetCenterOfMass()
  2747. {
  2748. m_host.AddScriptLPS(1);
  2749. NotImplemented("llGetCenterOfMass");
  2750. return new LSL_Types.Vector3();
  2751. }
  2752. public LSL_Types.list llListSort(LSL_Types.list src, int stride, int ascending)
  2753. {
  2754. m_host.AddScriptLPS(1);
  2755. return src.Sort(stride, ascending);
  2756. }
  2757. public LSL_Types.LSLInteger llGetListLength(LSL_Types.list src)
  2758. {
  2759. m_host.AddScriptLPS(1);
  2760. return src.Length;
  2761. }
  2762. public LSL_Types.LSLInteger llList2Integer(LSL_Types.list src, int index)
  2763. {
  2764. m_host.AddScriptLPS(1);
  2765. if (index < 0)
  2766. {
  2767. index = src.Length + index;
  2768. }
  2769. if (index >= src.Length)
  2770. {
  2771. return 0;
  2772. }
  2773. try
  2774. {
  2775. return Convert.ToInt32(src.Data[index]);
  2776. }
  2777. catch (FormatException)
  2778. {
  2779. return 0;
  2780. }
  2781. }
  2782. public double osList2Double(LSL_Types.list src, int index)
  2783. {
  2784. m_host.AddScriptLPS(1);
  2785. if (index < 0)
  2786. {
  2787. index = src.Length + index;
  2788. }
  2789. if (index >= src.Length)
  2790. {
  2791. return 0.0;
  2792. }
  2793. return Convert.ToDouble(src.Data[index]);
  2794. }
  2795. public double llList2Float(LSL_Types.list src, int index)
  2796. {
  2797. m_host.AddScriptLPS(1);
  2798. if (index < 0)
  2799. {
  2800. index = src.Length + index;
  2801. }
  2802. if (index >= src.Length)
  2803. {
  2804. return 0.0;
  2805. }
  2806. try
  2807. {
  2808. return Convert.ToDouble(src.Data[index]);
  2809. }
  2810. catch (FormatException)
  2811. {
  2812. return 0.0;
  2813. }
  2814. }
  2815. public string llList2String(LSL_Types.list src, int index)
  2816. {
  2817. m_host.AddScriptLPS(1);
  2818. if (index < 0)
  2819. {
  2820. index = src.Length + index;
  2821. }
  2822. if (index >= src.Length)
  2823. {
  2824. return String.Empty;
  2825. }
  2826. return src.Data[index].ToString();
  2827. }
  2828. public string llList2Key(LSL_Types.list src, int index)
  2829. {
  2830. m_host.AddScriptLPS(1);
  2831. if (index < 0)
  2832. {
  2833. index = src.Length + index;
  2834. }
  2835. if (index >= src.Length)
  2836. {
  2837. return "";
  2838. }
  2839. return src.Data[index].ToString();
  2840. }
  2841. public LSL_Types.Vector3 llList2Vector(LSL_Types.list src, int index)
  2842. {
  2843. m_host.AddScriptLPS(1);
  2844. if (index < 0)
  2845. {
  2846. index = src.Length + index;
  2847. }
  2848. if (index >= src.Length)
  2849. {
  2850. return new LSL_Types.Vector3(0, 0, 0);
  2851. }
  2852. if (src.Data[index].GetType() == typeof(LSL_Types.Vector3))
  2853. {
  2854. return (LSL_Types.Vector3)src.Data[index];
  2855. }
  2856. else
  2857. {
  2858. return new LSL_Types.Vector3(src.Data[index].ToString());
  2859. }
  2860. }
  2861. public LSL_Types.Quaternion llList2Rot(LSL_Types.list src, int index)
  2862. {
  2863. m_host.AddScriptLPS(1);
  2864. if (index < 0)
  2865. {
  2866. index = src.Length + index;
  2867. }
  2868. if (index >= src.Length)
  2869. {
  2870. return new LSL_Types.Quaternion(0, 0, 0, 1);
  2871. }
  2872. if (src.Data[index].GetType() == typeof(LSL_Types.Quaternion))
  2873. {
  2874. return (LSL_Types.Quaternion)src.Data[index];
  2875. }
  2876. else
  2877. {
  2878. return new LSL_Types.Quaternion(src.Data[index].ToString());
  2879. }
  2880. }
  2881. public LSL_Types.list llList2List(LSL_Types.list src, int start, int end)
  2882. {
  2883. m_host.AddScriptLPS(1);
  2884. return src.GetSublist(start, end);
  2885. }
  2886. public LSL_Types.list llDeleteSubList(LSL_Types.list src, int start, int end)
  2887. {
  2888. return src.DeleteSublist(end, start);
  2889. }
  2890. public LSL_Types.LSLInteger llGetListEntryType(LSL_Types.list src, int index)
  2891. {
  2892. m_host.AddScriptLPS(1);
  2893. if (index < 0)
  2894. {
  2895. index = src.Length + index;
  2896. }
  2897. if (index >= src.Length)
  2898. {
  2899. return 0;
  2900. }
  2901. if (src.Data[index] is Int32)
  2902. return 1;
  2903. if (src.Data[index] is Double)
  2904. return 2;
  2905. if (src.Data[index] is String)
  2906. {
  2907. LLUUID tuuid;
  2908. if (LLUUID.TryParse(src.Data[index].ToString(), out tuuid))
  2909. {
  2910. return 3;
  2911. }
  2912. else
  2913. {
  2914. return 4;
  2915. }
  2916. }
  2917. if (src.Data[index] is LSL_Types.Vector3)
  2918. return 5;
  2919. if (src.Data[index] is LSL_Types.Quaternion)
  2920. return 6;
  2921. if (src.Data[index] is LSL_Types.list)
  2922. return 7;
  2923. return 0;
  2924. }
  2925. /// <summary>
  2926. /// Process the supplied list and return the
  2927. /// content of the list formatted as a comma
  2928. /// separated list. There is a space after
  2929. /// each comma.
  2930. /// </summary>
  2931. public string llList2CSV(LSL_Types.list src)
  2932. {
  2933. string ret = String.Empty;
  2934. int x = 0;
  2935. m_host.AddScriptLPS(1);
  2936. if (src.Data.Length > 0)
  2937. {
  2938. ret = src.Data[x++].ToString();
  2939. for (; x < src.Data.Length; x++)
  2940. {
  2941. ret += ", "+src.Data[x].ToString();
  2942. }
  2943. }
  2944. return ret;
  2945. }
  2946. /// <summary>
  2947. /// The supplied string is scanned for commas
  2948. /// and converted into a list. Commas are only
  2949. /// effective if they are encountered outside
  2950. /// of '<' '>' delimiters. Any whitespace
  2951. /// before or after an element is trimmed.
  2952. /// </summary>
  2953. public LSL_Types.list llCSV2List(string src)
  2954. {
  2955. LSL_Types.list result = new LSL_Types.list();
  2956. int parens = 0;
  2957. int start = 0;
  2958. int length = 0;
  2959. m_host.AddScriptLPS(1);
  2960. for (int i = 0; i < src.Length; i++)
  2961. {
  2962. switch (src[i])
  2963. {
  2964. case '<':
  2965. parens++;
  2966. length++;
  2967. break;
  2968. case '>':
  2969. if (parens > 0)
  2970. parens--;
  2971. length++;
  2972. break;
  2973. case ',':
  2974. if (parens == 0)
  2975. {
  2976. result.Add(src.Substring(start,length).Trim());
  2977. start += length+1;
  2978. length = 0;
  2979. }
  2980. else
  2981. {
  2982. length++;
  2983. }
  2984. break;
  2985. default:
  2986. length++;
  2987. break;
  2988. }
  2989. }
  2990. result.Add(src.Substring(start,length).Trim());
  2991. return result;
  2992. }
  2993. /// <summary>
  2994. /// Randomizes the list, be arbitrarily reordering
  2995. /// sublists of stride elements. As the stride approaches
  2996. /// the size of the list, the options become very
  2997. /// limited.
  2998. /// </summary>
  2999. /// <remarks>
  3000. /// This could take a while for very large list
  3001. /// sizes.
  3002. /// </remarks>
  3003. public LSL_Types.list llListRandomize(LSL_Types.list src, int stride)
  3004. {
  3005. LSL_Types.list result;
  3006. Random rand = new Random();
  3007. int chunkk;
  3008. int[] chunks;
  3009. int index1;
  3010. int index2;
  3011. int tmp;
  3012. m_host.AddScriptLPS(1);
  3013. if (stride == 0)
  3014. stride = 1;
  3015. // Stride MUST be a factor of the list length
  3016. // If not, then return the src list. This also
  3017. // traps those cases where stride > length.
  3018. if (src.Length != stride && src.Length%stride == 0)
  3019. {
  3020. chunkk = src.Length/stride;
  3021. chunks = new int[chunkk];
  3022. for (int i = 0; i < chunkk; i++)
  3023. chunks[i] = i;
  3024. for (int i = 0; i < chunkk - 1; i++)
  3025. {
  3026. // randomly select 2 chunks
  3027. index1 = rand.Next(rand.Next(65536));
  3028. index1 = index1%chunkk;
  3029. index2 = rand.Next(rand.Next(65536));
  3030. index2 = index2%chunkk;
  3031. // and swap their relative positions
  3032. tmp = chunks[index1];
  3033. chunks[index1] = chunks[index2];
  3034. chunks[index2] = tmp;
  3035. }
  3036. // Construct the randomized list
  3037. result = new LSL_Types.list();
  3038. for (int i = 0; i < chunkk; i++)
  3039. {
  3040. for (int j = 0; j < stride; j++)
  3041. {
  3042. result.Add(src.Data[chunks[i]*stride+j]);
  3043. }
  3044. }
  3045. }
  3046. else {
  3047. object[] array = new object[src.Length];
  3048. Array.Copy(src.Data, 0, array, 0, src.Length);
  3049. result = new LSL_Types.list(array);
  3050. }
  3051. return result;
  3052. }
  3053. /// <summary>
  3054. /// Elements in the source list starting with 0 and then
  3055. /// every i+stride. If the stride is negative then the scan
  3056. /// is backwards producing an inverted result.
  3057. /// Only those elements that are also in the specified
  3058. /// range are included in the result.
  3059. /// </summary>
  3060. public LSL_Types.list llList2ListStrided(LSL_Types.list src, int start, int end, int stride)
  3061. {
  3062. LSL_Types.list result = new LSL_Types.list();
  3063. int[] si = new int[2];
  3064. int[] ei = new int[2];
  3065. bool twopass = false;
  3066. m_host.AddScriptLPS(1);
  3067. // First step is always to deal with negative indices
  3068. if (start < 0)
  3069. start = src.Length+start;
  3070. if (end < 0)
  3071. end = src.Length+end;
  3072. // Out of bounds indices are OK, just trim them
  3073. // accordingly
  3074. if (start > src.Length)
  3075. start = src.Length;
  3076. if (end > src.Length)
  3077. end = src.Length;
  3078. // There may be one or two ranges to be considered
  3079. if (start != end)
  3080. {
  3081. if (start <= end)
  3082. {
  3083. si[0] = start;
  3084. ei[0] = end;
  3085. }
  3086. else
  3087. {
  3088. si[1] = start;
  3089. ei[1] = src.Length;
  3090. si[0] = 0;
  3091. ei[0] = end;
  3092. twopass = true;
  3093. }
  3094. // The scan always starts from the beginning of the
  3095. // source list, but members are only selected if they
  3096. // fall within the specified sub-range. The specified
  3097. // range values are inclusive.
  3098. // A negative stride reverses the direction of the
  3099. // scan producing an inverted list as a result.
  3100. if (stride == 0)
  3101. stride = 1;
  3102. if (stride > 0)
  3103. {
  3104. for (int i = 0; i < src.Length; i += stride)
  3105. {
  3106. if (i<=ei[0] && i>=si[0])
  3107. result.Add(src.Data[i]);
  3108. if (twopass && i>=si[1] && i<=ei[1])
  3109. result.Add(src.Data[i]);
  3110. }
  3111. }
  3112. else if (stride < 0)
  3113. {
  3114. for (int i = src.Length - 1; i >= 0; i += stride)
  3115. {
  3116. if (i <= ei[0] && i >= si[0])
  3117. result.Add(src.Data[i]);
  3118. if (twopass && i >= si[1] && i <= ei[1])
  3119. result.Add(src.Data[i]);
  3120. }
  3121. }
  3122. }
  3123. return result;
  3124. }
  3125. public LSL_Types.Vector3 llGetRegionCorner()
  3126. {
  3127. m_host.AddScriptLPS(1);
  3128. return new LSL_Types.Vector3(World.RegionInfo.RegionLocX * Constants.RegionSize, World.RegionInfo.RegionLocY * Constants.RegionSize, 0);
  3129. }
  3130. /// <summary>
  3131. /// Insert the list identified by <src> into the
  3132. /// list designated by <dest> such that the first
  3133. /// new element has the index specified by <index>
  3134. /// </summary>
  3135. public LSL_Types.list llListInsertList(LSL_Types.list dest, LSL_Types.list src, int index)
  3136. {
  3137. LSL_Types.list pref = null;
  3138. LSL_Types.list suff = null;
  3139. m_host.AddScriptLPS(1);
  3140. if (index < 0)
  3141. {
  3142. index = index+dest.Length;
  3143. if (index < 0)
  3144. {
  3145. index = 0;
  3146. }
  3147. }
  3148. if (index != 0)
  3149. {
  3150. pref = dest.GetSublist(0,index-1);
  3151. if (index < dest.Length)
  3152. {
  3153. suff = dest.GetSublist(index,-1);
  3154. return pref + src + suff;
  3155. }
  3156. else
  3157. {
  3158. return pref + src;
  3159. }
  3160. }
  3161. else
  3162. {
  3163. if (index < dest.Length)
  3164. {
  3165. suff = dest.GetSublist(index,-1);
  3166. return src + suff;
  3167. }
  3168. else
  3169. {
  3170. return src;
  3171. }
  3172. }
  3173. }
  3174. /// <summary>
  3175. /// Returns the index of the first occurrence of test
  3176. /// in src.
  3177. /// </summary>
  3178. public LSL_Types.LSLInteger llListFindList(LSL_Types.list src, LSL_Types.list test)
  3179. {
  3180. int index = -1;
  3181. int length = src.Length - test.Length + 1;
  3182. m_host.AddScriptLPS(1);
  3183. // If either list is empty, do not match
  3184. if (src.Length != 0 && test.Length != 0)
  3185. {
  3186. for (int i = 0; i < length; i++)
  3187. {
  3188. if (src.Data[i].Equals(test.Data[0]))
  3189. {
  3190. int j;
  3191. for (j = 1; j < test.Length; j++)
  3192. if (!src.Data[i+j].Equals(test.Data[j]))
  3193. break;
  3194. if (j == test.Length)
  3195. {
  3196. index = i;
  3197. break;
  3198. }
  3199. }
  3200. }
  3201. }
  3202. return index;
  3203. }
  3204. public string llGetObjectName()
  3205. {
  3206. m_host.AddScriptLPS(1);
  3207. return m_host.Name!=null?m_host.Name:String.Empty;
  3208. }
  3209. public void llSetObjectName(string name)
  3210. {
  3211. m_host.AddScriptLPS(1);
  3212. m_host.Name = name!=null?name:String.Empty;
  3213. }
  3214. public string llGetDate()
  3215. {
  3216. m_host.AddScriptLPS(1);
  3217. DateTime date = DateTime.Now.ToUniversalTime();
  3218. string result = date.ToString("yyyy-MM-dd");
  3219. return result;
  3220. }
  3221. public LSL_Types.LSLInteger llEdgeOfWorld(LSL_Types.Vector3 pos, LSL_Types.Vector3 dir)
  3222. {
  3223. m_host.AddScriptLPS(1);
  3224. NotImplemented("llEdgeOfWorld");
  3225. return 0;
  3226. }
  3227. public LSL_Types.LSLInteger llGetAgentInfo(string id)
  3228. {
  3229. m_host.AddScriptLPS(1);
  3230. NotImplemented("llGetAgentInfo");
  3231. return 0;
  3232. }
  3233. public void llAdjustSoundVolume(double volume)
  3234. {
  3235. m_host.AddScriptLPS(1);
  3236. m_host.AdjustSoundGain(volume);
  3237. }
  3238. public void llSetSoundQueueing(int queue)
  3239. {
  3240. m_host.AddScriptLPS(1);
  3241. NotImplemented("llSetSoundQueueing");
  3242. }
  3243. public void llSetSoundRadius(double radius)
  3244. {
  3245. m_host.AddScriptLPS(1);
  3246. NotImplemented("llSetSoundRadius");
  3247. }
  3248. public string llKey2Name(string id)
  3249. {
  3250. m_host.AddScriptLPS(1);
  3251. LLUUID key = new LLUUID();
  3252. if (LLUUID.TryParse(id,out key))
  3253. {
  3254. ScenePresence presence = World.GetScenePresence(key);
  3255. if (presence != null)
  3256. {
  3257. return presence.ControllingClient.Name;
  3258. //return presence.Name;
  3259. }
  3260. if (World.GetSceneObjectPart(key) != null)
  3261. {
  3262. return World.GetSceneObjectPart(key).Name;
  3263. }
  3264. }
  3265. return String.Empty;
  3266. }
  3267. public void llSetTextureAnim(int mode, int face, int sizex, int sizey, double start, double length, double rate)
  3268. {
  3269. m_host.AddScriptLPS(1);
  3270. Primitive.TextureAnimation pTexAnim = new Primitive.TextureAnimation();
  3271. pTexAnim.Flags =(uint) mode;
  3272. //ALL_SIDES
  3273. if (face == -1)
  3274. face = 255;
  3275. pTexAnim.Face = (uint)face;
  3276. pTexAnim.Length = (float)length;
  3277. pTexAnim.Rate = (float)rate;
  3278. pTexAnim.SizeX = (uint)sizex;
  3279. pTexAnim.SizeY = (uint)sizey;
  3280. pTexAnim.Start = (float)start;
  3281. m_host.AddTextureAnimation(pTexAnim);
  3282. m_host.SendFullUpdateToAllClients();
  3283. }
  3284. public void llTriggerSoundLimited(string sound, double volume, LSL_Types.Vector3 top_north_east,
  3285. LSL_Types.Vector3 bottom_south_west)
  3286. {
  3287. m_host.AddScriptLPS(1);
  3288. NotImplemented("llTriggerSoundLimited");
  3289. }
  3290. public void llEjectFromLand(string pest)
  3291. {
  3292. m_host.AddScriptLPS(1);
  3293. NotImplemented("llEjectFromLand");
  3294. }
  3295. public LSL_Types.list llParseString2List(string str, LSL_Types.list separators, LSL_Types.list spacers)
  3296. {
  3297. m_host.AddScriptLPS(1);
  3298. LSL_Types.list ret = new LSL_Types.list();
  3299. object[] delimiters = new object[separators.Length + spacers.Length];
  3300. separators.Data.CopyTo(delimiters, 0);
  3301. spacers.Data.CopyTo(delimiters, separators.Length);
  3302. bool dfound = false;
  3303. do
  3304. {
  3305. dfound = false;
  3306. int cindex = -1;
  3307. string cdeli = "";
  3308. for (int i = 0; i < delimiters.Length; i++)
  3309. {
  3310. int index = str.IndexOf(delimiters[i].ToString());
  3311. bool found = index != -1;
  3312. if (found)
  3313. {
  3314. if ((cindex > index) || (cindex == -1))
  3315. {
  3316. cindex = index;
  3317. cdeli = (string)delimiters[i];
  3318. }
  3319. dfound = dfound || found;
  3320. }
  3321. }
  3322. if (cindex != -1)
  3323. {
  3324. if (cindex > 0)
  3325. {
  3326. ret.Add(str.Substring(0, cindex));
  3327. if (spacers.Contains(cdeli))
  3328. {
  3329. ret.Add(cdeli);
  3330. }
  3331. }
  3332. if (cindex == 0 && spacers.Contains(cdeli))
  3333. {
  3334. ret.Add(cdeli);
  3335. }
  3336. str = str.Substring(cindex + cdeli.Length);
  3337. }
  3338. } while (dfound);
  3339. if (str != "")
  3340. {
  3341. ret.Add(str);
  3342. }
  3343. return ret;
  3344. }
  3345. public LSL_Types.LSLInteger llOverMyLand(string id)
  3346. {
  3347. m_host.AddScriptLPS(1);
  3348. LLUUID key = new LLUUID();
  3349. if (LLUUID.TryParse(id,out key))
  3350. {
  3351. SceneObjectPart obj = new SceneObjectPart();
  3352. obj = World.GetSceneObjectPart(World.Entities[key].LocalId);
  3353. if (obj.OwnerID == World.GetLandOwner(obj.AbsolutePosition.X, obj.AbsolutePosition.Y))
  3354. {
  3355. return 1;
  3356. }
  3357. else
  3358. {
  3359. return 0;
  3360. }
  3361. }
  3362. else
  3363. {
  3364. return 0;
  3365. }
  3366. }
  3367. public string llGetLandOwnerAt(LSL_Types.Vector3 pos)
  3368. {
  3369. m_host.AddScriptLPS(1);
  3370. return World.GetLandOwner((float)pos.x, (float)pos.y).ToString();
  3371. }
  3372. public LSL_Types.Vector3 llGetAgentSize(string id)
  3373. {
  3374. m_host.AddScriptLPS(1);
  3375. NotImplemented("llGetAgentSize");
  3376. return new LSL_Types.Vector3();
  3377. }
  3378. public LSL_Types.LSLInteger llSameGroup(string agent)
  3379. {
  3380. m_host.AddScriptLPS(1);
  3381. NotImplemented("llSameGroup");
  3382. return 0;
  3383. }
  3384. public void llUnSit(string id)
  3385. {
  3386. m_host.AddScriptLPS(1);
  3387. LLUUID key = new LLUUID();
  3388. if (LLUUID.TryParse(id, out key))
  3389. {
  3390. ScenePresence av = World.GetScenePresence(key);
  3391. if (av != null)
  3392. {
  3393. if (llAvatarOnSitTarget() == id)
  3394. {
  3395. // if the avatar is sitting on this object, then
  3396. // we can unsit them. We don't want random scripts unsitting random people
  3397. // Lets avoid the popcorn avatar scenario.
  3398. av.StandUp();
  3399. }
  3400. else
  3401. {
  3402. // If the object owner also owns the parcel
  3403. // or
  3404. // if the land is group owned and the object is group owned by the same group
  3405. // or
  3406. // if the object is owned by a person with estate access.
  3407. ILandObject parcel = World.LandChannel.GetLandObject(av.AbsolutePosition.X, av.AbsolutePosition.Y);
  3408. if (parcel != null)
  3409. {
  3410. if (m_host.ObjectOwner == parcel.landData.ownerID ||
  3411. (m_host.OwnerID == m_host.GroupID && m_host.GroupID == parcel.landData.groupID
  3412. && parcel.landData.isGroupOwned) || World.ExternalChecks.ExternalChecksCanBeGodLike(m_host.OwnerID))
  3413. {
  3414. av.StandUp();
  3415. }
  3416. }
  3417. }
  3418. }
  3419. }
  3420. }
  3421. public LSL_Types.Vector3 llGroundSlope(LSL_Types.Vector3 offset)
  3422. {
  3423. m_host.AddScriptLPS(1);
  3424. NotImplemented("llGroundSlope");
  3425. return new LSL_Types.Vector3();
  3426. }
  3427. public LSL_Types.Vector3 llGroundNormal(LSL_Types.Vector3 offset)
  3428. {
  3429. m_host.AddScriptLPS(1);
  3430. NotImplemented("llGroundNormal");
  3431. return new LSL_Types.Vector3();
  3432. }
  3433. public LSL_Types.Vector3 llGroundContour(LSL_Types.Vector3 offset)
  3434. {
  3435. m_host.AddScriptLPS(1);
  3436. NotImplemented("llGroundContour");
  3437. return new LSL_Types.Vector3();
  3438. }
  3439. public LSL_Types.LSLInteger llGetAttached()
  3440. {
  3441. m_host.AddScriptLPS(1);
  3442. NotImplemented("llGetAttached");
  3443. return 0;
  3444. }
  3445. public LSL_Types.LSLInteger llGetFreeMemory()
  3446. {
  3447. m_host.AddScriptLPS(1);
  3448. NotImplemented("llGetFreeMemory");
  3449. return 0;
  3450. }
  3451. public string llGetRegionName()
  3452. {
  3453. m_host.AddScriptLPS(1);
  3454. return World.RegionInfo.RegionName;
  3455. }
  3456. public double llGetRegionTimeDilation()
  3457. {
  3458. m_host.AddScriptLPS(1);
  3459. return (double)World.TimeDilation;
  3460. }
  3461. public double llGetRegionFPS()
  3462. {
  3463. m_host.AddScriptLPS(1);
  3464. //TODO: return actual FPS
  3465. return 10.0f;
  3466. }
  3467. /* particle system rules should be coming into this routine as doubles, that is
  3468. rule[0] should be an integer from this list and rule[1] should be the arg
  3469. for the same integer. wiki.secondlife.com has most of this mapping, but some
  3470. came from http://www.caligari-designs.com/p4u2
  3471. We iterate through the list for 'Count' elements, incrementing by two for each
  3472. iteration and set the members of Primitive.ParticleSystem, one at a time.
  3473. */
  3474. public enum PrimitiveRule : int
  3475. {
  3476. PSYS_PART_FLAGS = 0,
  3477. PSYS_PART_START_COLOR = 1,
  3478. PSYS_PART_START_ALPHA = 2,
  3479. PSYS_PART_END_COLOR = 3,
  3480. PSYS_PART_END_ALPHA = 4,
  3481. PSYS_PART_START_SCALE = 5,
  3482. PSYS_PART_END_SCALE = 6,
  3483. PSYS_PART_MAX_AGE = 7,
  3484. PSYS_SRC_ACCEL = 8,
  3485. PSYS_SRC_PATTERN = 9,
  3486. PSYS_SRC_TEXTURE = 12,
  3487. PSYS_SRC_BURST_RATE = 13,
  3488. PSYS_SRC_BURST_PART_COUNT = 15,
  3489. PSYS_SRC_BURST_RADIUS = 16,
  3490. PSYS_SRC_BURST_SPEED_MIN = 17,
  3491. PSYS_SRC_BURST_SPEED_MAX = 18,
  3492. PSYS_SRC_MAX_AGE = 19,
  3493. PSYS_SRC_TARGET_KEY = 20,
  3494. PSYS_SRC_OMEGA = 21,
  3495. PSYS_SRC_ANGLE_BEGIN = 22,
  3496. PSYS_SRC_ANGLE_END = 23
  3497. }
  3498. internal Primitive.ParticleSystem.ParticleDataFlags ConvertUINTtoFlags(uint flags)
  3499. {
  3500. Primitive.ParticleSystem.ParticleDataFlags returnval = Primitive.ParticleSystem.ParticleDataFlags.None;
  3501. return returnval;
  3502. }
  3503. public void llParticleSystem(LSL_Types.list rules)
  3504. {
  3505. m_host.AddScriptLPS(1);
  3506. Primitive.ParticleSystem prules = new Primitive.ParticleSystem();
  3507. LSL_Types.Vector3 tempv = new LSL_Types.Vector3();
  3508. float tempf = 0;
  3509. for (int i = 0; i < rules.Length; i += 2)
  3510. {
  3511. switch ((int)rules.Data[i])
  3512. {
  3513. case (int)ScriptBaseClass.PSYS_PART_FLAGS:
  3514. prules.PartDataFlags = (Primitive.ParticleSystem.ParticleDataFlags)((uint)Convert.ToInt32(rules.Data[i + 1].ToString()));
  3515. break;
  3516. case (int)ScriptBaseClass.PSYS_PART_START_COLOR:
  3517. tempv = (LSL_Types.Vector3)rules.Data[i + 1];
  3518. prules.PartStartColor.R = (float)tempv.x;
  3519. prules.PartStartColor.G = (float)tempv.y;
  3520. prules.PartStartColor.B = (float)tempv.z;
  3521. break;
  3522. case (int)ScriptBaseClass.PSYS_PART_START_ALPHA:
  3523. tempf = Convert.ToSingle(rules.Data[i + 1].ToString());
  3524. prules.PartStartColor.A = (float)tempf;
  3525. break;
  3526. case (int)ScriptBaseClass.PSYS_PART_END_COLOR:
  3527. tempv = (LSL_Types.Vector3)rules.Data[i + 1];
  3528. //prules.PartEndColor = new LLColor(tempv.x,tempv.y,tempv.z,1);
  3529. prules.PartEndColor.R = (float)tempv.x;
  3530. prules.PartEndColor.G = (float)tempv.y;
  3531. prules.PartEndColor.B = (float)tempv.z;
  3532. break;
  3533. case (int)ScriptBaseClass.PSYS_PART_END_ALPHA:
  3534. tempf = Convert.ToSingle(rules.Data[i + 1].ToString());
  3535. prules.PartEndColor.A = (float)tempf;
  3536. break;
  3537. case (int)ScriptBaseClass.PSYS_PART_START_SCALE:
  3538. tempv = (LSL_Types.Vector3)rules.Data[i + 1];
  3539. prules.PartStartScaleX = (float)tempv.x;
  3540. prules.PartStartScaleY = (float)tempv.y;
  3541. break;
  3542. case (int)ScriptBaseClass.PSYS_PART_END_SCALE:
  3543. tempv = (LSL_Types.Vector3)rules.Data[i + 1];
  3544. prules.PartEndScaleX = (float)tempv.x;
  3545. prules.PartEndScaleY = (float)tempv.y;
  3546. break;
  3547. case (int)ScriptBaseClass.PSYS_PART_MAX_AGE:
  3548. tempf = Convert.ToSingle(rules.Data[i + 1].ToString());
  3549. prules.PartMaxAge = (float)tempf;
  3550. break;
  3551. case (int)ScriptBaseClass.PSYS_SRC_ACCEL:
  3552. tempv = (LSL_Types.Vector3)rules.Data[i + 1];
  3553. prules.PartAcceleration.X = (float)tempv.x;
  3554. prules.PartAcceleration.Y = (float)tempv.y;
  3555. prules.PartAcceleration.Z = (float)tempv.z;
  3556. break;
  3557. case (int)ScriptBaseClass.PSYS_SRC_PATTERN:
  3558. int tmpi = int.Parse(rules.Data[i + 1].ToString());
  3559. prules.Pattern = (Primitive.ParticleSystem.SourcePattern)tmpi;
  3560. break;
  3561. // Xantor 20080503
  3562. // Wiki: PSYS_SRC_TEXTURE string inventory item name or key of the particle texture
  3563. // "" = default texture.
  3564. // 20080530 Updated to remove code duplication
  3565. case (int)ScriptBaseClass.PSYS_SRC_TEXTURE:
  3566. prules.Texture = KeyOrName(rules.Data[i + 1].ToString());
  3567. break;
  3568. case (int)ScriptBaseClass.PSYS_SRC_BURST_RATE:
  3569. tempf = Convert.ToSingle(rules.Data[i + 1].ToString());
  3570. prules.BurstRate = (float)tempf;
  3571. break;
  3572. case (int)ScriptBaseClass.PSYS_SRC_BURST_PART_COUNT:
  3573. prules.BurstPartCount = (byte)Convert.ToByte(rules.Data[i + 1].ToString());
  3574. break;
  3575. case (int)ScriptBaseClass.PSYS_SRC_BURST_RADIUS:
  3576. tempf = Convert.ToSingle(rules.Data[i + 1].ToString());
  3577. prules.BurstRadius = (float)tempf;
  3578. break;
  3579. case (int)ScriptBaseClass.PSYS_SRC_BURST_SPEED_MIN:
  3580. tempf = Convert.ToSingle(rules.Data[i + 1].ToString());
  3581. prules.BurstSpeedMin = (float)tempf;
  3582. break;
  3583. case (int)ScriptBaseClass.PSYS_SRC_BURST_SPEED_MAX:
  3584. tempf = Convert.ToSingle(rules.Data[i + 1].ToString());
  3585. prules.BurstSpeedMax = (float)tempf;
  3586. break;
  3587. case (int)ScriptBaseClass.PSYS_SRC_MAX_AGE:
  3588. tempf = Convert.ToSingle(rules.Data[i + 1].ToString());
  3589. prules.MaxAge = (float)tempf;
  3590. break;
  3591. case (int)ScriptBaseClass.PSYS_SRC_TARGET_KEY:
  3592. LLUUID key = LLUUID.Zero;
  3593. if (LLUUID.TryParse(rules.Data[i + 1].ToString(), out key))
  3594. {
  3595. prules.Target = key;
  3596. }
  3597. else
  3598. {
  3599. prules.Target = m_host.UUID;
  3600. }
  3601. break;
  3602. case (int)ScriptBaseClass.PSYS_SRC_OMEGA:
  3603. // AL: This is an assumption, since it is the only thing that would match.
  3604. tempv = (LSL_Types.Vector3)rules.Data[i + 1];
  3605. prules.AngularVelocity.X = (float)tempv.x;
  3606. prules.AngularVelocity.Y = (float)tempv.y;
  3607. prules.AngularVelocity.Z = (float)tempv.z;
  3608. //cast?? prules.MaxAge = (float)rules[i + 1];
  3609. break;
  3610. case (int)ScriptBaseClass.PSYS_SRC_ANGLE_BEGIN:
  3611. tempf = Convert.ToSingle(rules.Data[i + 1].ToString());
  3612. prules.InnerAngle = (float)tempf;
  3613. break;
  3614. case (int)ScriptBaseClass.PSYS_SRC_ANGLE_END:
  3615. tempf = Convert.ToSingle(rules.Data[i + 1].ToString());
  3616. prules.OuterAngle = (float)tempf;
  3617. break;
  3618. }
  3619. }
  3620. prules.CRC = 1;
  3621. m_host.AddNewParticleSystem(prules);
  3622. m_host.SendFullUpdateToAllClients();
  3623. }
  3624. public void llGroundRepel(double height, int water, double tau)
  3625. {
  3626. m_host.AddScriptLPS(1);
  3627. NotImplemented("llGroundRepel");
  3628. }
  3629. private LLUUID GetTaskInventoryItem(string name)
  3630. {
  3631. foreach (KeyValuePair<LLUUID, TaskInventoryItem> inv in m_host.TaskInventory)
  3632. {
  3633. if (inv.Value.Name == name)
  3634. return inv.Key;
  3635. }
  3636. return LLUUID.Zero;
  3637. }
  3638. public void llGiveInventoryList(string destination, string category, LSL_Types.list inventory)
  3639. {
  3640. m_host.AddScriptLPS(1);
  3641. LLUUID destID;
  3642. if (!LLUUID.TryParse(destination, out destID))
  3643. return;
  3644. List<LLUUID> itemList = new List<LLUUID>();
  3645. foreach (Object item in inventory.Data)
  3646. {
  3647. LLUUID itemID;
  3648. if (LLUUID.TryParse(item.ToString(), out itemID))
  3649. {
  3650. itemList.Add(itemID);
  3651. }
  3652. else
  3653. {
  3654. itemID = GetTaskInventoryItem(item.ToString());
  3655. if (itemID != LLUUID.Zero)
  3656. itemList.Add(itemID);
  3657. }
  3658. }
  3659. if (itemList.Count == 0)
  3660. return;
  3661. m_ScriptEngine.World.MoveTaskInventoryItems(destID, category, m_host, itemList);
  3662. }
  3663. public void llSetVehicleType(int type)
  3664. {
  3665. m_host.AddScriptLPS(1);
  3666. NotImplemented("llSetVehicleType");
  3667. }
  3668. public void llSetVehicledoubleParam(int param, double value)
  3669. {
  3670. m_host.AddScriptLPS(1);
  3671. NotImplemented("llSetVehicledoubleParam");
  3672. }
  3673. public void llSetVehicleFloatParam(int param, float value)
  3674. {
  3675. m_host.AddScriptLPS(1);
  3676. NotImplemented("llSetVehicleFloatParam");
  3677. }
  3678. public void llSetVehicleVectorParam(int param, LSL_Types.Vector3 vec)
  3679. {
  3680. m_host.AddScriptLPS(1);
  3681. NotImplemented("llSetVehicleVectorParam");
  3682. }
  3683. public void llSetVehicleRotationParam(int param, LSL_Types.Quaternion rot)
  3684. {
  3685. m_host.AddScriptLPS(1);
  3686. NotImplemented("llSetVehicleRotationParam");
  3687. }
  3688. public void llSetVehicleFlags(int flags)
  3689. {
  3690. m_host.AddScriptLPS(1);
  3691. NotImplemented("llSetVehicleFlags");
  3692. }
  3693. public void llRemoveVehicleFlags(int flags)
  3694. {
  3695. m_host.AddScriptLPS(1);
  3696. NotImplemented("llRemoveVehicleFlags");
  3697. }
  3698. public void llSitTarget(LSL_Types.Vector3 offset, LSL_Types.Quaternion rot)
  3699. {
  3700. m_host.AddScriptLPS(1);
  3701. // LSL quaternions can normalize to 0, normal Quaternions can't.
  3702. if (rot.s == 0 && rot.x == 0 && rot.y == 0 && rot.z == 0)
  3703. rot.z = 1; // ZERO_ROTATION = 0,0,0,1
  3704. m_host.SitTargetPosition = new Vector3((float)offset.x, (float)offset.y, (float)offset.z);
  3705. m_host.SitTargetOrientation = new Quaternion((float)rot.s, (float)rot.x, (float)rot.y, (float)rot.z);
  3706. }
  3707. public string llAvatarOnSitTarget()
  3708. {
  3709. m_host.AddScriptLPS(1);
  3710. return m_host.GetAvatarOnSitTarget().ToString();
  3711. }
  3712. public void llAddToLandPassList(string avatar, double hours)
  3713. {
  3714. m_host.AddScriptLPS(1);
  3715. LLUUID key;
  3716. LandData land = World.LandChannel.GetLandObject(m_host.AbsolutePosition.X, m_host.AbsolutePosition.Y).landData;
  3717. if (land.ownerID == m_host.OwnerID)
  3718. {
  3719. ParcelManager.ParcelAccessEntry entry = new ParcelManager.ParcelAccessEntry();
  3720. if (LLUUID.TryParse(avatar, out key))
  3721. {
  3722. entry.AgentID = key;
  3723. entry.Flags = ParcelManager.AccessList.Access;
  3724. entry.Time = DateTime.Now.AddHours(hours);
  3725. land.parcelAccessList.Add(entry);
  3726. }
  3727. }
  3728. }
  3729. public void llSetTouchText(string text)
  3730. {
  3731. m_host.AddScriptLPS(1);
  3732. m_host.TouchName = text;
  3733. }
  3734. public void llSetSitText(string text)
  3735. {
  3736. m_host.AddScriptLPS(1);
  3737. m_host.SitName = text;
  3738. }
  3739. public void llSetCameraEyeOffset(LSL_Types.Vector3 offset)
  3740. {
  3741. m_host.AddScriptLPS(1);
  3742. NotImplemented("llSetCameraEyeOffset");
  3743. }
  3744. public void llSetCameraAtOffset(LSL_Types.Vector3 offset)
  3745. {
  3746. m_host.AddScriptLPS(1);
  3747. NotImplemented("llSetCameraAtOffset");
  3748. }
  3749. public string llDumpList2String(LSL_Types.list src, string seperator)
  3750. {
  3751. m_host.AddScriptLPS(1);
  3752. if (src.Length == 0)
  3753. {
  3754. return String.Empty;
  3755. }
  3756. string ret = String.Empty;
  3757. foreach (object o in src.Data)
  3758. {
  3759. ret = ret + o.ToString() + seperator;
  3760. }
  3761. ret = ret.Substring(0, ret.Length - seperator.Length);
  3762. return ret;
  3763. }
  3764. public LSL_Types.LSLInteger llScriptDanger(LSL_Types.Vector3 pos)
  3765. {
  3766. m_host.AddScriptLPS(1);
  3767. bool result = World.scriptDanger(m_host.LocalId, new LLVector3((float)pos.x, (float)pos.y, (float)pos.z));
  3768. if (result)
  3769. {
  3770. return 1;
  3771. }
  3772. else
  3773. {
  3774. return 0;
  3775. }
  3776. }
  3777. public void llDialog(string avatar, string message, LSL_Types.list buttons, int chat_channel)
  3778. {
  3779. m_host.AddScriptLPS(1);
  3780. LLUUID av = new LLUUID();
  3781. if (!LLUUID.TryParse(avatar,out av))
  3782. {
  3783. LSLError("First parameter to llDialog needs to be a key");
  3784. return;
  3785. }
  3786. if (buttons.Length > 12)
  3787. {
  3788. LSLError("No more than 12 buttons can be shown");
  3789. return;
  3790. }
  3791. string[] buts = new string[buttons.Length];
  3792. for (int i = 0; i < buttons.Length; i++)
  3793. {
  3794. if (buttons.Data[i].ToString() == String.Empty)
  3795. {
  3796. LSLError("button label cannot be blank");
  3797. return;
  3798. }
  3799. if (buttons.Data[i].ToString().Length > 24)
  3800. {
  3801. LSLError("button label cannot be longer than 24 characters");
  3802. return;
  3803. }
  3804. buts[i] = buttons.Data[i].ToString();
  3805. }
  3806. World.SendDialogToUser(av, m_host.Name, m_host.UUID, m_host.OwnerID, message, new LLUUID("00000000-0000-2222-3333-100000001000"), chat_channel, buts);
  3807. }
  3808. public void llVolumeDetect(int detect)
  3809. {
  3810. m_host.AddScriptLPS(1);
  3811. NotImplemented("llVolumeDetect");
  3812. }
  3813. /// <summary>
  3814. /// Reset the named script. The script must be present
  3815. /// in the same prim.
  3816. /// </summary>
  3817. public void llResetOtherScript(string name)
  3818. {
  3819. LLUUID item;
  3820. m_host.AddScriptLPS(1);
  3821. if ((item = ScriptByName(name)) != LLUUID.Zero)
  3822. m_ScriptEngine.ResetScript(item);
  3823. else
  3824. ShoutError("llResetOtherScript: script "+name+" not found");
  3825. }
  3826. public LSL_Types.LSLInteger llGetScriptState(string name)
  3827. {
  3828. LLUUID item;
  3829. m_host.AddScriptLPS(1);
  3830. if ((item = ScriptByName(name)) != LLUUID.Zero)
  3831. {
  3832. return m_ScriptEngine.GetScriptState(item) ?1:0;
  3833. }
  3834. ShoutError("llGetScriptState: script "+name+" not found");
  3835. // If we didn't find it, then it's safe to
  3836. // assume it is not running.
  3837. return 0;
  3838. }
  3839. public void llRemoteLoadScript()
  3840. {
  3841. m_host.AddScriptLPS(1);
  3842. Deprecated("llRemoteLoadScript");
  3843. }
  3844. public void llSetRemoteScriptAccessPin(int pin)
  3845. {
  3846. m_host.AddScriptLPS(1);
  3847. NotImplemented("llSetRemoteScriptAccessPin");
  3848. }
  3849. public void llRemoteLoadScriptPin(string target, string name, int pin, int running, int start_param)
  3850. {
  3851. m_host.AddScriptLPS(1);
  3852. NotImplemented("llRemoteLoadScriptPin");
  3853. }
  3854. // remote_data(integer type, key channel, key message_id, string sender, integer ival, string sval)
  3855. // Not sure where these constants should live:
  3856. // REMOTE_DATA_CHANNEL = 1
  3857. // REMOTE_DATA_REQUEST = 2
  3858. // REMOTE_DATA_REPLY = 3
  3859. public void llOpenRemoteDataChannel()
  3860. {
  3861. m_host.AddScriptLPS(1);
  3862. IXMLRPC xmlrpcMod = m_ScriptEngine.World.RequestModuleInterface<IXMLRPC>();
  3863. if (xmlrpcMod.IsEnabled())
  3864. {
  3865. LLUUID channelID = xmlrpcMod.OpenXMLRPCChannel(m_localID, m_itemID, LLUUID.Zero);
  3866. object[] resobj = new object[] { new LSL_Types.LSLInteger(1), new LSL_Types.LSLString(channelID.ToString()), new LSL_Types.LSLString(LLUUID.Zero.ToString()), new LSL_Types.LSLString(String.Empty), new LSL_Types.LSLInteger(0), new LSL_Types.LSLString(String.Empty) };
  3867. m_ScriptEngine.PostScriptEvent(m_itemID, new EventParams(
  3868. "remote_data", resobj,
  3869. new DetectParams[0]));
  3870. }
  3871. }
  3872. public string llSendRemoteData(string channel, string dest, int idata, string sdata)
  3873. {
  3874. m_host.AddScriptLPS(1);
  3875. IXMLRPC xmlrpcMod = m_ScriptEngine.World.RequestModuleInterface<IXMLRPC>();
  3876. return (xmlrpcMod.SendRemoteData(m_localID, m_itemID, channel, dest, idata, sdata)).ToString();
  3877. }
  3878. public void llRemoteDataReply(string channel, string message_id, string sdata, int idata)
  3879. {
  3880. m_host.AddScriptLPS(1);
  3881. IXMLRPC xmlrpcMod = m_ScriptEngine.World.RequestModuleInterface<IXMLRPC>();
  3882. xmlrpcMod.RemoteDataReply(channel, message_id, sdata, idata);
  3883. }
  3884. public void llCloseRemoteDataChannel(string channel)
  3885. {
  3886. m_host.AddScriptLPS(1);
  3887. IXMLRPC xmlrpcMod = m_ScriptEngine.World.RequestModuleInterface<IXMLRPC>();
  3888. xmlrpcMod.CloseXMLRPCChannel(channel);
  3889. }
  3890. public string llMD5String(string src, int nonce)
  3891. {
  3892. m_host.AddScriptLPS(1);
  3893. return Util.Md5Hash(src + ":" + nonce.ToString());
  3894. }
  3895. private ObjectShapePacket.ObjectDataBlock SetPrimitiveShapeParams(int holeshape, LSL_Types.Vector3 cut, float hollow, LSL_Types.Vector3 twist)
  3896. {
  3897. ObjectShapePacket.ObjectDataBlock shapeBlock = new ObjectShapePacket.ObjectDataBlock();
  3898. if (holeshape != (int)ScriptBaseClass.PRIM_HOLE_DEFAULT &&
  3899. holeshape != (int)ScriptBaseClass.PRIM_HOLE_CIRCLE &&
  3900. holeshape != (int)ScriptBaseClass.PRIM_HOLE_SQUARE &&
  3901. holeshape != (int)ScriptBaseClass.PRIM_HOLE_TRIANGLE)
  3902. {
  3903. holeshape = (int)ScriptBaseClass.PRIM_HOLE_DEFAULT;
  3904. }
  3905. shapeBlock.ProfileCurve = (byte)holeshape;
  3906. if (cut.x < 0f)
  3907. {
  3908. cut.x = 0f;
  3909. }
  3910. if (cut.x > 1f)
  3911. {
  3912. cut.x = 1f;
  3913. }
  3914. if (cut.y < 0f)
  3915. {
  3916. cut.y = 0f;
  3917. }
  3918. if (cut.y > 1f)
  3919. {
  3920. cut.y = 1f;
  3921. }
  3922. if (cut.y - cut.x < 0.05f)
  3923. {
  3924. cut.x = cut.y - 0.05f;
  3925. }
  3926. shapeBlock.ProfileBegin = (ushort)(50000 * cut.x);
  3927. shapeBlock.ProfileEnd = (ushort)(50000 * (1 - cut.y));
  3928. if (hollow < 0f)
  3929. {
  3930. hollow = 0f;
  3931. }
  3932. if (hollow > 0.95)
  3933. {
  3934. hollow = 0.95f;
  3935. }
  3936. shapeBlock.ProfileHollow = (ushort)(50000 * hollow);
  3937. if (twist.x < -0.5f)
  3938. {
  3939. twist.x = -0.5f;
  3940. }
  3941. if (twist.x > 0.5f)
  3942. {
  3943. twist.x = 0.5f;
  3944. }
  3945. if (twist.y < -0.5f)
  3946. {
  3947. twist.y = -0.5f;
  3948. }
  3949. if (twist.y > 0.5f)
  3950. {
  3951. twist.y = 0.5f;
  3952. }
  3953. shapeBlock.PathTwistBegin = (sbyte)(200 * twist.x);
  3954. shapeBlock.PathTwist = (sbyte)(200 * twist.y);
  3955. shapeBlock.ObjectLocalID = m_host.LocalId;
  3956. // retain pathcurve
  3957. shapeBlock.PathCurve = m_host.Shape.PathCurve;
  3958. return shapeBlock;
  3959. }
  3960. private void SetPrimitiveShapeParams(int holeshape, LSL_Types.Vector3 cut, float hollow, LSL_Types.Vector3 twist, LSL_Types.Vector3 taper_b, LSL_Types.Vector3 topshear, byte fudge)
  3961. {
  3962. ObjectShapePacket.ObjectDataBlock shapeBlock;
  3963. shapeBlock = SetPrimitiveShapeParams(holeshape, cut, hollow, twist);
  3964. shapeBlock.ProfileCurve += fudge;
  3965. if (taper_b.x < 0f)
  3966. {
  3967. taper_b.x = 0f;
  3968. }
  3969. if (taper_b.x > 2f)
  3970. {
  3971. taper_b.x = 2f;
  3972. }
  3973. if (taper_b.y < 0f)
  3974. {
  3975. taper_b.y = 0f;
  3976. }
  3977. if (taper_b.y > 2f)
  3978. {
  3979. taper_b.y = 2f;
  3980. }
  3981. shapeBlock.PathScaleX = (byte)(100 * taper_b.x);
  3982. shapeBlock.PathScaleY = (byte)(100 * taper_b.y);
  3983. if (topshear.x < -0.5f)
  3984. {
  3985. topshear.x = -0.5f;
  3986. }
  3987. if (topshear.x > 0.5f)
  3988. {
  3989. topshear.x = 0.5f;
  3990. }
  3991. if (topshear.y < -0.5f)
  3992. {
  3993. topshear.y = -0.5f;
  3994. }
  3995. if (topshear.y > 0.5f)
  3996. {
  3997. topshear.y = 0.5f;
  3998. }
  3999. shapeBlock.PathShearX = (byte)(100 * topshear.x);
  4000. shapeBlock.PathShearY = (byte)(100 * topshear.y);
  4001. m_host.UpdateShape(shapeBlock);
  4002. }
  4003. private void SetPrimitiveShapeParams(int holeshape, LSL_Types.Vector3 cut, float hollow, LSL_Types.Vector3 twist, LSL_Types.Vector3 dimple, byte fudge)
  4004. {
  4005. ObjectShapePacket.ObjectDataBlock shapeBlock;
  4006. shapeBlock = SetPrimitiveShapeParams(holeshape, cut, hollow, twist);
  4007. // profile/path swapped for a sphere
  4008. shapeBlock.PathBegin = shapeBlock.ProfileBegin;
  4009. shapeBlock.PathEnd = shapeBlock.ProfileEnd;
  4010. shapeBlock.ProfileCurve += fudge;
  4011. shapeBlock.PathScaleX = 100;
  4012. shapeBlock.PathScaleY = 100;
  4013. if (dimple.x < 0f)
  4014. {
  4015. dimple.x = 0f;
  4016. }
  4017. if (dimple.x > 1f)
  4018. {
  4019. dimple.x = 1f;
  4020. }
  4021. if (dimple.y < 0f)
  4022. {
  4023. dimple.y = 0f;
  4024. }
  4025. if (dimple.y > 1f)
  4026. {
  4027. dimple.y = 1f;
  4028. }
  4029. if (dimple.y - cut.x < 0.05f)
  4030. {
  4031. dimple.x = cut.y - 0.05f;
  4032. }
  4033. shapeBlock.ProfileBegin = (ushort)(50000 * dimple.x);
  4034. shapeBlock.ProfileEnd = (ushort)(50000 * (1 - dimple.y));
  4035. m_host.UpdateShape(shapeBlock);
  4036. }
  4037. private void SetPrimitiveShapeParams(int holeshape, LSL_Types.Vector3 cut, float hollow, LSL_Types.Vector3 twist, LSL_Types.Vector3 holesize, LSL_Types.Vector3 topshear, LSL_Types.Vector3 profilecut, LSL_Types.Vector3 taper_a, float revolutions, float radiusoffset, float skew, byte fudge)
  4038. {
  4039. ObjectShapePacket.ObjectDataBlock shapeBlock;
  4040. shapeBlock = SetPrimitiveShapeParams(holeshape, cut, hollow, twist);
  4041. shapeBlock.ProfileCurve += fudge;
  4042. // profile/path swapped for a torrus, tube, ring
  4043. shapeBlock.PathBegin = shapeBlock.ProfileBegin;
  4044. shapeBlock.PathEnd = shapeBlock.ProfileEnd;
  4045. if (holesize.x < 0.05f)
  4046. {
  4047. holesize.x = 0.05f;
  4048. }
  4049. if (holesize.x > 1f)
  4050. {
  4051. holesize.x = 1f;
  4052. }
  4053. if (holesize.y < 0.05f)
  4054. {
  4055. holesize.y = 0.05f;
  4056. }
  4057. if (holesize.y > 0.5f)
  4058. {
  4059. holesize.y = 0.5f;
  4060. }
  4061. shapeBlock.PathScaleX = (byte)(100 * (2 - holesize.x));
  4062. shapeBlock.PathScaleY = (byte)(100 * (2 - holesize.y));
  4063. if (topshear.x < -0.5f)
  4064. {
  4065. topshear.x = -0.5f;
  4066. }
  4067. if (topshear.x > 0.5f)
  4068. {
  4069. topshear.x = 0.5f;
  4070. }
  4071. if (topshear.y < -0.5f)
  4072. {
  4073. topshear.y = -0.5f;
  4074. }
  4075. if (topshear.y > 0.5f)
  4076. {
  4077. topshear.y = 0.5f;
  4078. }
  4079. shapeBlock.PathShearX = (byte)(100 * topshear.x);
  4080. shapeBlock.PathShearY = (byte)(100 * topshear.y);
  4081. if (profilecut.x < 0f)
  4082. {
  4083. profilecut.x = 0f;
  4084. }
  4085. if (profilecut.x > 1f)
  4086. {
  4087. profilecut.x = 1f;
  4088. }
  4089. if (profilecut.y < 0f)
  4090. {
  4091. profilecut.y = 0f;
  4092. }
  4093. if (profilecut.y > 1f)
  4094. {
  4095. profilecut.y = 1f;
  4096. }
  4097. if (profilecut.y - cut.x < 0.05f)
  4098. {
  4099. profilecut.x = cut.y - 0.05f;
  4100. }
  4101. shapeBlock.ProfileBegin = (ushort)(50000 * profilecut.x);
  4102. shapeBlock.ProfileEnd = (ushort)(50000 * (1 - profilecut.y));
  4103. if (taper_a.x < -1f)
  4104. {
  4105. taper_a.x = -1f;
  4106. }
  4107. if (taper_a.x > 1f)
  4108. {
  4109. taper_a.x = 1f;
  4110. }
  4111. if (taper_a.y < -1f)
  4112. {
  4113. taper_a.y = -1f;
  4114. }
  4115. if (taper_a.y > 1f)
  4116. {
  4117. taper_a.y = 1f;
  4118. }
  4119. shapeBlock.PathTaperX = (sbyte)(100 * taper_a.x);
  4120. shapeBlock.PathTaperY = (sbyte)(100 * taper_a.y);
  4121. if (revolutions < 1f)
  4122. {
  4123. revolutions = 1f;
  4124. }
  4125. if (revolutions > 4f)
  4126. {
  4127. revolutions = 4f;
  4128. }
  4129. shapeBlock.PathRevolutions = (byte)(100 * revolutions);
  4130. // limits on radiusoffset depend on revolutions and hole size (how?) seems like the maximum range is 0 to 1
  4131. if (radiusoffset < 0f)
  4132. {
  4133. radiusoffset = 0f;
  4134. }
  4135. if (radiusoffset > 1f)
  4136. {
  4137. radiusoffset = 1f;
  4138. }
  4139. shapeBlock.PathRadiusOffset = (sbyte)(100 * radiusoffset);
  4140. if (skew < -0.95f)
  4141. {
  4142. skew = -0.95f;
  4143. }
  4144. if (skew > 0.95f)
  4145. {
  4146. skew = 0.95f;
  4147. }
  4148. shapeBlock.PathSkew = (sbyte)(100 * skew);
  4149. m_host.UpdateShape(shapeBlock);
  4150. }
  4151. private void SetPrimitiveShapeParams(string map, int type)
  4152. {
  4153. ObjectShapePacket.ObjectDataBlock shapeBlock = new ObjectShapePacket.ObjectDataBlock();
  4154. LLUUID sculptId;
  4155. if (!LLUUID.TryParse(map, out sculptId))
  4156. {
  4157. llSay(0, "Could not parse key " + map);
  4158. return;
  4159. }
  4160. shapeBlock.ObjectLocalID = m_host.LocalId;
  4161. shapeBlock.PathScaleX = 100;
  4162. shapeBlock.PathScaleY = 150;
  4163. if (type != (int)ScriptBaseClass.PRIM_SCULPT_TYPE_CYLINDER &&
  4164. type != (int)ScriptBaseClass.PRIM_SCULPT_TYPE_PLANE &&
  4165. type != (int)ScriptBaseClass.PRIM_SCULPT_TYPE_SPHERE &&
  4166. type != (int)ScriptBaseClass.PRIM_SCULPT_TYPE_TORUS)
  4167. {
  4168. // default
  4169. type = (int)ScriptBaseClass.PRIM_SCULPT_TYPE_SPHERE;
  4170. }
  4171. // retain pathcurve
  4172. shapeBlock.PathCurve = m_host.Shape.PathCurve;
  4173. m_host.Shape.SetSculptData((byte)type, sculptId);
  4174. m_host.Shape.SculptEntry = true;
  4175. m_host.UpdateShape(shapeBlock);
  4176. }
  4177. public void llSetPrimitiveParams(LSL_Types.list rules)
  4178. {
  4179. llSetLinkPrimitiveParams(m_host.LinkNum+1, rules);
  4180. }
  4181. public void llSetLinkPrimitiveParams(int linknumber, LSL_Types.list rules)
  4182. {
  4183. m_host.AddScriptLPS(1);
  4184. SceneObjectPart part=null;
  4185. if (m_host.LinkNum+1 != linknumber)
  4186. {
  4187. foreach (SceneObjectPart partInst in m_host.ParentGroup.GetParts())
  4188. {
  4189. if ((partInst.LinkNum + 1) == linknumber)
  4190. {
  4191. part = partInst;
  4192. break;
  4193. }
  4194. }
  4195. }
  4196. else
  4197. {
  4198. part = m_host;
  4199. }
  4200. if (part == null)
  4201. return;
  4202. int idx = 0;
  4203. while (idx < rules.Length)
  4204. {
  4205. int code = Convert.ToInt32(rules.Data[idx++]);
  4206. int remain = rules.Length - idx;
  4207. int face;
  4208. LSL_Types.Vector3 v;
  4209. switch (code)
  4210. {
  4211. case (int)ScriptBaseClass.PRIM_POSITION:
  4212. if (remain < 1)
  4213. return;
  4214. v=new LSL_Types.Vector3(rules.Data[idx++].ToString());
  4215. SetPos(part, v);
  4216. break;
  4217. case (int)ScriptBaseClass.PRIM_SIZE:
  4218. if (remain < 1)
  4219. return;
  4220. v=new LSL_Types.Vector3(rules.Data[idx++].ToString());
  4221. SetScale(part, v);
  4222. break;
  4223. case (int)ScriptBaseClass.PRIM_ROTATION:
  4224. if (remain < 1)
  4225. return;
  4226. LSL_Types.Quaternion q = new LSL_Types.Quaternion(rules.Data[idx++].ToString());
  4227. SetRot(part, q);
  4228. break;
  4229. case (int)ScriptBaseClass.PRIM_TYPE:
  4230. if (remain < 3)
  4231. return;
  4232. code = Convert.ToInt32(rules.Data[idx++]);
  4233. remain = rules.Length - idx;
  4234. float hollow;
  4235. LSL_Types.Vector3 twist;
  4236. LSL_Types.Vector3 taper_b;
  4237. LSL_Types.Vector3 topshear;
  4238. float revolutions;
  4239. float radiusoffset;
  4240. float skew;
  4241. LSL_Types.Vector3 holesize;
  4242. LSL_Types.Vector3 profilecut;
  4243. switch (code)
  4244. {
  4245. case (int)ScriptBaseClass.PRIM_TYPE_BOX:
  4246. if (remain < 6)
  4247. return;
  4248. face = Convert.ToInt32(rules.Data[idx++]); // holeshape
  4249. v = new LSL_Types.Vector3(rules.Data[idx++].ToString()); // cut
  4250. hollow = (float)Convert.ToDouble(rules.Data[idx++]);
  4251. twist = new LSL_Types.Vector3(rules.Data[idx++].ToString());
  4252. taper_b = new LSL_Types.Vector3(rules.Data[idx++].ToString());
  4253. topshear = new LSL_Types.Vector3(rules.Data[idx++].ToString());
  4254. m_host.Shape.PathCurve = (byte) Extrusion.Straight;
  4255. SetPrimitiveShapeParams(face, v, hollow, twist, taper_b, topshear, 1);
  4256. break;
  4257. case (int)ScriptBaseClass.PRIM_TYPE_CYLINDER:
  4258. if (remain < 6)
  4259. return;
  4260. face = Convert.ToInt32(rules.Data[idx++]); // holeshape
  4261. v = new LSL_Types.Vector3(rules.Data[idx++].ToString()); // cut
  4262. hollow = (float)Convert.ToDouble(rules.Data[idx++]);
  4263. twist = new LSL_Types.Vector3(rules.Data[idx++].ToString());
  4264. taper_b = new LSL_Types.Vector3(rules.Data[idx++].ToString());
  4265. topshear = new LSL_Types.Vector3(rules.Data[idx++].ToString());
  4266. m_host.Shape.ProfileShape = ProfileShape.Circle;
  4267. m_host.Shape.PathCurve = (byte) Extrusion.Straight;
  4268. SetPrimitiveShapeParams(face, v, hollow, twist, taper_b, topshear, 0);
  4269. break;
  4270. case (int)ScriptBaseClass.PRIM_TYPE_PRISM:
  4271. if (remain < 6)
  4272. return;
  4273. face = Convert.ToInt32(rules.Data[idx++]); // holeshape
  4274. v = new LSL_Types.Vector3(rules.Data[idx++].ToString()); //cut
  4275. hollow = (float)Convert.ToDouble(rules.Data[idx++]);
  4276. twist = new LSL_Types.Vector3(rules.Data[idx++].ToString());
  4277. taper_b = new LSL_Types.Vector3(rules.Data[idx++].ToString());
  4278. topshear = new LSL_Types.Vector3(rules.Data[idx++].ToString());
  4279. m_host.Shape.PathCurve = (byte) Extrusion.Straight;
  4280. SetPrimitiveShapeParams(face, v, hollow, twist, taper_b, topshear, 3);
  4281. break;
  4282. case (int)ScriptBaseClass.PRIM_TYPE_SPHERE:
  4283. if (remain < 5)
  4284. return;
  4285. face = Convert.ToInt32(rules.Data[idx++]); // holeshape
  4286. v = new LSL_Types.Vector3(rules.Data[idx++].ToString()); // cut
  4287. hollow = (float)Convert.ToDouble(rules.Data[idx++]);
  4288. twist = new LSL_Types.Vector3(rules.Data[idx++].ToString());
  4289. taper_b = new LSL_Types.Vector3(rules.Data[idx++].ToString()); // dimple
  4290. m_host.Shape.PathCurve = (byte) Extrusion.Curve1;
  4291. SetPrimitiveShapeParams(face, v, hollow, twist, taper_b, 5);
  4292. break;
  4293. case (int)ScriptBaseClass.PRIM_TYPE_TORUS:
  4294. if (remain < 11)
  4295. return;
  4296. face = Convert.ToInt32(rules.Data[idx++]); // holeshape
  4297. v = new LSL_Types.Vector3(rules.Data[idx++].ToString()); //cut
  4298. hollow = (float)Convert.ToDouble(rules.Data[idx++]);
  4299. twist = new LSL_Types.Vector3(rules.Data[idx++].ToString());
  4300. holesize = new LSL_Types.Vector3(rules.Data[idx++].ToString());
  4301. topshear = new LSL_Types.Vector3(rules.Data[idx++].ToString());
  4302. profilecut = new LSL_Types.Vector3(rules.Data[idx++].ToString());
  4303. taper_b = new LSL_Types.Vector3(rules.Data[idx++].ToString()); // taper_a
  4304. revolutions = (float)Convert.ToDouble(rules.Data[idx++]);
  4305. radiusoffset = (float)Convert.ToDouble(rules.Data[idx++]);
  4306. skew = (float)Convert.ToDouble(rules.Data[idx++]);
  4307. m_host.Shape.PathCurve = (byte) Extrusion.Curve1;
  4308. SetPrimitiveShapeParams(face, v, hollow, twist, holesize, topshear, profilecut, taper_b, revolutions, radiusoffset, skew, 0);
  4309. break;
  4310. case (int)ScriptBaseClass.PRIM_TYPE_TUBE:
  4311. if (remain < 11)
  4312. return;
  4313. face = Convert.ToInt32(rules.Data[idx++]); // holeshape
  4314. v = new LSL_Types.Vector3(rules.Data[idx++].ToString()); //cut
  4315. hollow = (float)Convert.ToDouble(rules.Data[idx++]);
  4316. twist = new LSL_Types.Vector3(rules.Data[idx++].ToString());
  4317. holesize = new LSL_Types.Vector3(rules.Data[idx++].ToString());
  4318. topshear = new LSL_Types.Vector3(rules.Data[idx++].ToString());
  4319. profilecut = new LSL_Types.Vector3(rules.Data[idx++].ToString());
  4320. taper_b = new LSL_Types.Vector3(rules.Data[idx++].ToString()); // taper_a
  4321. revolutions = (float)Convert.ToDouble(rules.Data[idx++]);
  4322. radiusoffset = (float)Convert.ToDouble(rules.Data[idx++]);
  4323. skew = (float)Convert.ToDouble(rules.Data[idx++]);
  4324. m_host.Shape.PathCurve = (byte) Extrusion.Curve1;
  4325. SetPrimitiveShapeParams(face, v, hollow, twist, holesize, topshear, profilecut, taper_b, revolutions, radiusoffset, skew, 1);
  4326. break;
  4327. case (int)ScriptBaseClass.PRIM_TYPE_RING:
  4328. if (remain < 11)
  4329. return;
  4330. face = Convert.ToInt32(rules.Data[idx++]); // holeshape
  4331. v = new LSL_Types.Vector3(rules.Data[idx++].ToString()); //cut
  4332. hollow = (float)Convert.ToDouble(rules.Data[idx++]);
  4333. twist = new LSL_Types.Vector3(rules.Data[idx++].ToString());
  4334. holesize = new LSL_Types.Vector3(rules.Data[idx++].ToString());
  4335. topshear = new LSL_Types.Vector3(rules.Data[idx++].ToString());
  4336. profilecut = new LSL_Types.Vector3(rules.Data[idx++].ToString());
  4337. taper_b = new LSL_Types.Vector3(rules.Data[idx++].ToString()); // taper_a
  4338. revolutions = (float)Convert.ToDouble(rules.Data[idx++]);
  4339. radiusoffset = (float)Convert.ToDouble(rules.Data[idx++]);
  4340. skew = (float)Convert.ToDouble(rules.Data[idx++]);
  4341. m_host.Shape.PathCurve = (byte) Extrusion.Curve1;
  4342. SetPrimitiveShapeParams(face, v, hollow, twist, holesize, topshear, profilecut, taper_b, revolutions, radiusoffset, skew, 3);
  4343. break;
  4344. case (int)ScriptBaseClass.PRIM_TYPE_SCULPT:
  4345. if (remain < 2)
  4346. return;
  4347. string map = rules.Data[idx++].ToString();
  4348. face = Convert.ToInt32(rules.Data[idx++]); // type
  4349. m_host.Shape.PathCurve = (byte) Extrusion.Curve1;
  4350. SetPrimitiveShapeParams(map, face);
  4351. break;
  4352. }
  4353. break;
  4354. case (int)ScriptBaseClass.PRIM_TEXTURE:
  4355. if (remain < 5)
  4356. return;
  4357. face=Convert.ToInt32(rules.Data[idx++]);
  4358. string tex=rules.Data[idx++].ToString();
  4359. LSL_Types.Vector3 repeats=new LSL_Types.Vector3(rules.Data[idx++].ToString());
  4360. LSL_Types.Vector3 offsets=new LSL_Types.Vector3(rules.Data[idx++].ToString());
  4361. double rotation=Convert.ToDouble(rules.Data[idx++]);
  4362. SetTexture(part, tex, face);
  4363. ScaleTexture(part, repeats.x, repeats.y, face);
  4364. OffsetTexture(part, offsets.x, offsets.y, face);
  4365. RotateTexture(part, rotation, face);
  4366. break;
  4367. case (int)ScriptBaseClass.PRIM_COLOR:
  4368. if (remain < 3)
  4369. return;
  4370. face=Convert.ToInt32(rules.Data[idx++]);
  4371. LSL_Types.Vector3 color=new LSL_Types.Vector3(rules.Data[idx++].ToString());
  4372. double alpha=Convert.ToDouble(rules.Data[idx++]);
  4373. SetColor(part, color, face);
  4374. SetAlpha(part, alpha, face);
  4375. break;
  4376. case (int)ScriptBaseClass.PRIM_FLEXIBLE:
  4377. if (remain < 7)
  4378. return;
  4379. int flexi = Convert.ToInt32(rules.Data[idx++]);
  4380. int softness = Convert.ToInt32(rules.Data[idx++]);
  4381. float gravity = (float)Convert.ToDouble(rules.Data[idx++]);
  4382. float friction = (float)Convert.ToDouble(rules.Data[idx++]);
  4383. float wind = (float)Convert.ToDouble(rules.Data[idx++]);
  4384. float tension = (float)Convert.ToDouble(rules.Data[idx++]);
  4385. LSL_Types.Vector3 force =new LSL_Types.Vector3(rules.Data[idx++].ToString());
  4386. SetFlexi(part, (flexi == 1), softness, gravity, friction, wind, tension, force);
  4387. break;
  4388. case (int)ScriptBaseClass.PRIM_POINT_LIGHT:
  4389. if (remain < 5)
  4390. return;
  4391. int light = Convert.ToInt32(rules.Data[idx++]);
  4392. LSL_Types.Vector3 lightcolor =new LSL_Types.Vector3(rules.Data[idx++].ToString());
  4393. float intensity = (float)Convert.ToDouble(rules.Data[idx++]);
  4394. float radius = (float)Convert.ToDouble(rules.Data[idx++]);
  4395. float falloff = (float)Convert.ToDouble(rules.Data[idx++]);
  4396. SetPointLight(part, (light == 1), lightcolor, intensity, radius, falloff);
  4397. break;
  4398. }
  4399. }
  4400. }
  4401. public string llStringToBase64(string str)
  4402. {
  4403. m_host.AddScriptLPS(1);
  4404. try
  4405. {
  4406. byte[] encData_byte = new byte[str.Length];
  4407. encData_byte = Encoding.UTF8.GetBytes(str);
  4408. string encodedData = Convert.ToBase64String(encData_byte);
  4409. return encodedData;
  4410. }
  4411. catch (Exception e)
  4412. {
  4413. throw new Exception("Error in base64Encode" + e.Message);
  4414. }
  4415. }
  4416. public string llBase64ToString(string str)
  4417. {
  4418. m_host.AddScriptLPS(1);
  4419. UTF8Encoding encoder = new UTF8Encoding();
  4420. Decoder utf8Decode = encoder.GetDecoder();
  4421. try
  4422. {
  4423. byte[] todecode_byte = Convert.FromBase64String(str);
  4424. int charCount = utf8Decode.GetCharCount(todecode_byte, 0, todecode_byte.Length);
  4425. char[] decoded_char = new char[charCount];
  4426. utf8Decode.GetChars(todecode_byte, 0, todecode_byte.Length, decoded_char, 0);
  4427. string result = new String(decoded_char);
  4428. return result;
  4429. }
  4430. catch (Exception e)
  4431. {
  4432. throw new Exception("Error in base64Decode" + e.Message);
  4433. }
  4434. }
  4435. public void llXorBase64Strings()
  4436. {
  4437. m_host.AddScriptLPS(1);
  4438. Deprecated("llXorBase64Strings");
  4439. }
  4440. public void llRemoteDataSetRegion()
  4441. {
  4442. m_host.AddScriptLPS(1);
  4443. NotImplemented("llRemoteDataSetRegion");
  4444. }
  4445. public double llLog10(double val)
  4446. {
  4447. m_host.AddScriptLPS(1);
  4448. return (double)Math.Log10(val);
  4449. }
  4450. public double llLog(double val)
  4451. {
  4452. m_host.AddScriptLPS(1);
  4453. return (double)Math.Log(val);
  4454. }
  4455. public LSL_Types.list llGetAnimationList(string id)
  4456. {
  4457. m_host.AddScriptLPS(1);
  4458. NotImplemented("llGetAnimationList");
  4459. return new LSL_Types.list();
  4460. }
  4461. public void llSetParcelMusicURL(string url)
  4462. {
  4463. m_host.AddScriptLPS(1);
  4464. LLUUID landowner = World.GetLandOwner(m_host.AbsolutePosition.X, m_host.AbsolutePosition.Y);
  4465. if (landowner == LLUUID.Zero)
  4466. {
  4467. return;
  4468. }
  4469. if (landowner != m_host.ObjectOwner)
  4470. {
  4471. return;
  4472. }
  4473. World.SetLandMusicURL(m_host.AbsolutePosition.X, m_host.AbsolutePosition.Y, url);
  4474. }
  4475. public void osSetParcelMediaURL(string url)
  4476. {
  4477. m_host.AddScriptLPS(1);
  4478. LLUUID landowner = World.GetLandOwner(m_host.AbsolutePosition.X, m_host.AbsolutePosition.Y);
  4479. if (landowner == LLUUID.Zero)
  4480. {
  4481. return;
  4482. }
  4483. if (landowner != m_host.ObjectOwner)
  4484. {
  4485. return;
  4486. }
  4487. World.SetLandMediaURL(m_host.AbsolutePosition.X, m_host.AbsolutePosition.Y, url);
  4488. }
  4489. public LSL_Types.Vector3 llGetRootPosition()
  4490. {
  4491. m_host.AddScriptLPS(1);
  4492. return new LSL_Types.Vector3(m_host.ParentGroup.AbsolutePosition.X, m_host.ParentGroup.AbsolutePosition.Y, m_host.ParentGroup.AbsolutePosition.Z);
  4493. }
  4494. public LSL_Types.Quaternion llGetRootRotation()
  4495. {
  4496. m_host.AddScriptLPS(1);
  4497. return new LSL_Types.Quaternion(m_host.ParentGroup.GroupRotation.X, m_host.ParentGroup.GroupRotation.Y, m_host.ParentGroup.GroupRotation.Z, m_host.ParentGroup.GroupRotation.W);
  4498. }
  4499. public string llGetObjectDesc()
  4500. {
  4501. return m_host.Description!=null?m_host.Description:String.Empty;
  4502. }
  4503. public void llSetObjectDesc(string desc)
  4504. {
  4505. m_host.AddScriptLPS(1);
  4506. m_host.Description = desc!=null?desc:String.Empty;
  4507. }
  4508. public string llGetCreator()
  4509. {
  4510. m_host.AddScriptLPS(1);
  4511. return m_host.ObjectCreator.ToString();
  4512. }
  4513. public string llGetTimestamp()
  4514. {
  4515. m_host.AddScriptLPS(1);
  4516. return DateTime.Now.ToUniversalTime().ToString("yyyy-MM-ddTHH:mm:ss.fffffffZ");
  4517. }
  4518. public void llSetLinkAlpha(int linknumber, double alpha, int face)
  4519. {
  4520. m_host.AddScriptLPS(1);
  4521. SceneObjectPart part = m_host.ParentGroup.GetLinkNumPart(linknumber);
  4522. if (linknumber > -1)
  4523. {
  4524. LLObject.TextureEntry tex = part.Shape.Textures;
  4525. LLColor texcolor;
  4526. if (face > -1)
  4527. {
  4528. texcolor = tex.CreateFace((uint)face).RGBA;
  4529. texcolor.A = (float)Math.Abs(alpha - 1);
  4530. tex.FaceTextures[face].RGBA = texcolor;
  4531. part.UpdateTexture(tex);
  4532. return;
  4533. }
  4534. else if (face == -1)
  4535. {
  4536. texcolor = tex.DefaultTexture.RGBA;
  4537. texcolor.A = (float)Math.Abs(alpha - 1);
  4538. tex.DefaultTexture.RGBA = texcolor;
  4539. for (uint i = 0; i < 32; i++)
  4540. {
  4541. if (tex.FaceTextures[i] != null)
  4542. {
  4543. texcolor = tex.FaceTextures[i].RGBA;
  4544. texcolor.A = (float)Math.Abs(alpha - 1);
  4545. tex.FaceTextures[i].RGBA = texcolor;
  4546. }
  4547. }
  4548. texcolor = tex.DefaultTexture.RGBA;
  4549. texcolor.A = (float)Math.Abs(alpha - 1);
  4550. tex.DefaultTexture.RGBA = texcolor;
  4551. part.UpdateTexture(tex);
  4552. return;
  4553. }
  4554. return;
  4555. }
  4556. else if (linknumber == -1)
  4557. {
  4558. int num = m_host.ParentGroup.PrimCount;
  4559. for (int w = 0; w < num; w++)
  4560. {
  4561. linknumber = w;
  4562. part = m_host.ParentGroup.GetLinkNumPart(linknumber);
  4563. LLObject.TextureEntry tex = part.Shape.Textures;
  4564. LLColor texcolor;
  4565. if (face > -1)
  4566. {
  4567. texcolor = tex.CreateFace((uint)face).RGBA;
  4568. texcolor.A = (float)Math.Abs(alpha - 1);
  4569. tex.FaceTextures[face].RGBA = texcolor;
  4570. part.UpdateTexture(tex);
  4571. }
  4572. else if (face == -1)
  4573. {
  4574. texcolor = tex.DefaultTexture.RGBA;
  4575. texcolor.A = (float)Math.Abs(alpha - 1);
  4576. tex.DefaultTexture.RGBA = texcolor;
  4577. for (uint i = 0; i < 32; i++)
  4578. {
  4579. if (tex.FaceTextures[i] != null)
  4580. {
  4581. texcolor = tex.FaceTextures[i].RGBA;
  4582. texcolor.A = (float)Math.Abs(alpha - 1);
  4583. tex.FaceTextures[i].RGBA = texcolor;
  4584. }
  4585. }
  4586. texcolor = tex.DefaultTexture.RGBA;
  4587. texcolor.A = (float)Math.Abs(alpha - 1);
  4588. tex.DefaultTexture.RGBA = texcolor;
  4589. part.UpdateTexture(tex);
  4590. }
  4591. }
  4592. return;
  4593. }
  4594. }
  4595. public LSL_Types.LSLInteger llGetNumberOfPrims()
  4596. {
  4597. m_host.AddScriptLPS(1);
  4598. return m_host.ParentGroup.PrimCount;
  4599. }
  4600. public LSL_Types.list llGetBoundingBox(string obj)
  4601. {
  4602. m_host.AddScriptLPS(1);
  4603. NotImplemented("llGetBoundingBox");
  4604. return new LSL_Types.list();
  4605. }
  4606. public LSL_Types.Vector3 llGetGeometricCenter()
  4607. {
  4608. return new LSL_Types.Vector3(m_host.GetGeometricCenter().X, m_host.GetGeometricCenter().Y, m_host.GetGeometricCenter().Z);
  4609. }
  4610. public LSL_Types.list llGetPrimitiveParams(LSL_Types.list rules)
  4611. {
  4612. m_host.AddScriptLPS(1);
  4613. LSL_Types.list res = new LSL_Types.list();
  4614. int idx=0;
  4615. while (idx < rules.Length)
  4616. {
  4617. int code=Convert.ToInt32(rules.Data[idx++]);
  4618. int remain=rules.Length-idx;
  4619. switch (code)
  4620. {
  4621. case (int)ScriptBaseClass.PRIM_MATERIAL:
  4622. res.Add(new LSL_Types.LSLInteger(m_host.Material));
  4623. break;
  4624. case (int)ScriptBaseClass.PRIM_PHYSICS:
  4625. if ((m_host.GetEffectiveObjectFlags() & (uint)LLObject.ObjectFlags.Physics) != 0)
  4626. res.Add(new LSL_Types.LSLInteger(1));
  4627. else
  4628. res.Add(new LSL_Types.LSLInteger(0));
  4629. break;
  4630. case (int)ScriptBaseClass.PRIM_TEMP_ON_REZ:
  4631. if ((m_host.GetEffectiveObjectFlags() & (uint)LLObject.ObjectFlags.TemporaryOnRez) != 0)
  4632. res.Add(new LSL_Types.LSLInteger(1));
  4633. else
  4634. res.Add(new LSL_Types.LSLInteger(0));
  4635. break;
  4636. case (int)ScriptBaseClass.PRIM_PHANTOM:
  4637. if ((m_host.GetEffectiveObjectFlags() & (uint)LLObject.ObjectFlags.Phantom) != 0)
  4638. res.Add(new LSL_Types.LSLInteger(1));
  4639. else
  4640. res.Add(new LSL_Types.LSLInteger(0));
  4641. break;
  4642. case (int)ScriptBaseClass.PRIM_POSITION:
  4643. res.Add(new LSL_Types.Vector3(m_host.AbsolutePosition.X,
  4644. m_host.AbsolutePosition.Y,
  4645. m_host.AbsolutePosition.Z));
  4646. break;
  4647. case (int)ScriptBaseClass.PRIM_SIZE:
  4648. res.Add(new LSL_Types.Vector3(m_host.Scale.X,
  4649. m_host.Scale.Y,
  4650. m_host.Scale.Z));
  4651. break;
  4652. case (int)ScriptBaseClass.PRIM_ROTATION:
  4653. res.Add(new LSL_Types.Quaternion(m_host.RotationOffset.X,
  4654. m_host.RotationOffset.Y,
  4655. m_host.RotationOffset.Z,
  4656. m_host.RotationOffset.W));
  4657. break;
  4658. case (int)ScriptBaseClass.PRIM_TYPE:
  4659. // TODO--------------
  4660. res.Add(new LSL_Types.LSLInteger(0));
  4661. break;
  4662. case (int)ScriptBaseClass.PRIM_TEXTURE:
  4663. if (remain < 1)
  4664. return res;
  4665. int face=Convert.ToInt32(rules.Data[idx++]);
  4666. if (face == -1)
  4667. face = 0;
  4668. LLObject.TextureEntry tex = m_host.Shape.Textures;
  4669. LLObject.TextureEntryFace texface = tex.GetFace((uint)face);
  4670. res.Add(new LSL_Types.LSLString(texface.TextureID.ToString()));
  4671. res.Add(new LSL_Types.Vector3(texface.RepeatU,
  4672. texface.RepeatV,
  4673. 0));
  4674. res.Add(new LSL_Types.Vector3(texface.OffsetU,
  4675. texface.OffsetV,
  4676. 0));
  4677. res.Add(new LSL_Types.LSLFloat(texface.Rotation));
  4678. break;
  4679. case (int)ScriptBaseClass.PRIM_COLOR:
  4680. if (remain < 1)
  4681. return res;
  4682. face=Convert.ToInt32(rules.Data[idx++]);
  4683. tex = m_host.Shape.Textures;
  4684. LLColor texcolor;
  4685. if (face == -1) // TMP: Until we can determine number of sides, ALL_SIDES (-1) will return default color
  4686. texcolor = tex.DefaultTexture.RGBA;
  4687. else
  4688. texcolor = tex.GetFace((uint)face).RGBA;
  4689. res.Add(new LSL_Types.Vector3((255 - (texcolor.R * 255)) / 255,
  4690. (255 - (texcolor.G * 255)) / 255,
  4691. (255 - (texcolor.B * 255)) / 255));
  4692. res.Add(new LSL_Types.LSLFloat((texcolor.A * 255) / 255));
  4693. break;
  4694. case (int)ScriptBaseClass.PRIM_BUMP_SHINY:
  4695. // TODO--------------
  4696. if (remain < 1)
  4697. return res;
  4698. face=Convert.ToInt32(rules.Data[idx++]);
  4699. res.Add(new LSL_Types.LSLInteger(0));
  4700. res.Add(new LSL_Types.LSLInteger(0));
  4701. break;
  4702. case (int)ScriptBaseClass.PRIM_FULLBRIGHT:
  4703. // TODO--------------
  4704. if (remain < 1)
  4705. return res;
  4706. face=Convert.ToInt32(rules.Data[idx++]);
  4707. res.Add(new LSL_Types.LSLInteger(0));
  4708. break;
  4709. case (int)ScriptBaseClass.PRIM_FLEXIBLE:
  4710. PrimitiveBaseShape shape = m_host.Shape;
  4711. if (shape.FlexiEntry)
  4712. res.Add(new LSL_Types.LSLInteger(1)); // active
  4713. else
  4714. res.Add(new LSL_Types.LSLInteger(0));
  4715. res.Add(new LSL_Types.LSLInteger(shape.FlexiSoftness));// softness
  4716. res.Add(new LSL_Types.LSLFloat(shape.FlexiGravity)); // gravity
  4717. res.Add(new LSL_Types.LSLFloat(shape.FlexiDrag)); // friction
  4718. res.Add(new LSL_Types.LSLFloat(shape.FlexiWind)); // wind
  4719. res.Add(new LSL_Types.LSLFloat(shape.FlexiTension)); // tension
  4720. res.Add(new LSL_Types.Vector3(shape.FlexiForceX, // force
  4721. shape.FlexiForceY,
  4722. shape.FlexiForceZ));
  4723. break;
  4724. case (int)ScriptBaseClass.PRIM_TEXGEN:
  4725. // TODO--------------
  4726. // (PRIM_TEXGEN_DEFAULT, PRIM_TEXGEN_PLANAR)
  4727. if (remain < 1)
  4728. return res;
  4729. face=Convert.ToInt32(rules.Data[idx++]);
  4730. res.Add(new LSL_Types.LSLInteger(0));
  4731. break;
  4732. case (int)ScriptBaseClass.PRIM_POINT_LIGHT:
  4733. shape = m_host.Shape;
  4734. if (shape.LightEntry)
  4735. res.Add(new LSL_Types.LSLInteger(1)); // active
  4736. else
  4737. res.Add(new LSL_Types.LSLInteger(0));
  4738. res.Add(new LSL_Types.Vector3(shape.LightColorR, // color
  4739. shape.LightColorG,
  4740. shape.LightColorB));
  4741. res.Add(new LSL_Types.LSLFloat(shape.LightIntensity)); // intensity
  4742. res.Add(new LSL_Types.LSLFloat(shape.LightRadius)); // radius
  4743. res.Add(new LSL_Types.LSLFloat(shape.LightFalloff)); // falloff
  4744. break;
  4745. case (int)ScriptBaseClass.PRIM_GLOW:
  4746. // TODO--------------
  4747. if (remain < 1)
  4748. return res;
  4749. face=Convert.ToInt32(rules.Data[idx++]);
  4750. res.Add(new LSL_Types.LSLFloat(0));
  4751. break;
  4752. }
  4753. }
  4754. return res;
  4755. }
  4756. // <remarks>
  4757. // <para>
  4758. // The .NET definition of base 64 is:
  4759. // <list>
  4760. // <item>
  4761. // Significant: A-Z a-z 0-9 + -
  4762. // </item>
  4763. // <item>
  4764. // Whitespace: \t \n \r ' '
  4765. // </item>
  4766. // <item>
  4767. // Valueless: =
  4768. // </item>
  4769. // <item>
  4770. // End-of-string: \0 or '=='
  4771. // </item>
  4772. // </list>
  4773. // </para>
  4774. // <para>
  4775. // Each point in a base-64 string represents
  4776. // a 6 bit value. A 32-bit integer can be
  4777. // represented using 6 characters (with some
  4778. // redundancy).
  4779. // </para>
  4780. // <para>
  4781. // LSL requires a base64 string to be 8
  4782. // characters in length. LSL also uses '/'
  4783. // rather than '-' (MIME compliant).
  4784. // </para>
  4785. // <para>
  4786. // RFC 1341 used as a reference (as specified
  4787. // by the SecondLife Wiki).
  4788. // </para>
  4789. // <para>
  4790. // SL do not record any kind of exception for
  4791. // these functions, so the string to integer
  4792. // conversion returns '0' if an invalid
  4793. // character is encountered during conversion.
  4794. // </para>
  4795. // <para>
  4796. // References
  4797. // <list>
  4798. // <item>
  4799. // http://lslwiki.net/lslwiki/wakka.php?wakka=Base64
  4800. // </item>
  4801. // <item>
  4802. // </item>
  4803. // </list>
  4804. // </para>
  4805. // </remarks>
  4806. // <summary>
  4807. // Table for converting 6-bit integers into
  4808. // base-64 characters
  4809. // </summary>
  4810. private static readonly char[] i2ctable =
  4811. {
  4812. 'A','B','C','D','E','F','G','H',
  4813. 'I','J','K','L','M','N','O','P',
  4814. 'Q','R','S','T','U','V','W','X',
  4815. 'Y','Z',
  4816. 'a','b','c','d','e','f','g','h',
  4817. 'i','j','k','l','m','n','o','p',
  4818. 'q','r','s','t','u','v','w','x',
  4819. 'y','z',
  4820. '0','1','2','3','4','5','6','7',
  4821. '8','9',
  4822. '+','/'
  4823. };
  4824. // <summary>
  4825. // Table for converting base-64 characters
  4826. // into 6-bit integers.
  4827. // </summary>
  4828. private static readonly int[] c2itable =
  4829. {
  4830. -1,-1,-1,-1,-1,-1,-1,-1, // 0x
  4831. -1,-1,-1,-1,-1,-1,-1,-1,
  4832. -1,-1,-1,-1,-1,-1,-1,-1, // 1x
  4833. -1,-1,-1,-1,-1,-1,-1,-1,
  4834. -1,-1,-1,-1,-1,-1,-1,-1, // 2x
  4835. -1,-1,-1,63,-1,-1,-1,64,
  4836. 53,54,55,56,57,58,59,60, // 3x
  4837. 61,62,-1,-1,-1,0,-1,-1,
  4838. -1,1,2,3,4,5,6,7, // 4x
  4839. 8,9,10,11,12,13,14,15,
  4840. 16,17,18,19,20,21,22,23, // 5x
  4841. 24,25,26,-1,-1,-1,-1,-1,
  4842. -1,27,28,29,30,31,32,33, // 6x
  4843. 34,35,36,37,38,39,40,41,
  4844. 42,43,44,45,46,47,48,49, // 7x
  4845. 50,51,52,-1,-1,-1,-1,-1,
  4846. -1,-1,-1,-1,-1,-1,-1,-1, // 8x
  4847. -1,-1,-1,-1,-1,-1,-1,-1,
  4848. -1,-1,-1,-1,-1,-1,-1,-1, // 9x
  4849. -1,-1,-1,-1,-1,-1,-1,-1,
  4850. -1,-1,-1,-1,-1,-1,-1,-1, // Ax
  4851. -1,-1,-1,-1,-1,-1,-1,-1,
  4852. -1,-1,-1,-1,-1,-1,-1,-1, // Bx
  4853. -1,-1,-1,-1,-1,-1,-1,-1,
  4854. -1,-1,-1,-1,-1,-1,-1,-1, // Cx
  4855. -1,-1,-1,-1,-1,-1,-1,-1,
  4856. -1,-1,-1,-1,-1,-1,-1,-1, // Dx
  4857. -1,-1,-1,-1,-1,-1,-1,-1,
  4858. -1,-1,-1,-1,-1,-1,-1,-1, // Ex
  4859. -1,-1,-1,-1,-1,-1,-1,-1,
  4860. -1,-1,-1,-1,-1,-1,-1,-1, // Fx
  4861. -1,-1,-1,-1,-1,-1,-1,-1
  4862. };
  4863. // <summary>
  4864. // Converts a 32-bit integer into a Base64
  4865. // character string. Base64 character strings
  4866. // are always 8 characters long. All iinteger
  4867. // values are acceptable.
  4868. // </summary>
  4869. // <param name="number">
  4870. // 32-bit integer to be converted.
  4871. // </param>
  4872. // <returns>
  4873. // 8 character string. The 1st six characters
  4874. // contain the encoded number, the last two
  4875. // characters are padded with "=".
  4876. // </returns>
  4877. public string llIntegerToBase64(int number)
  4878. {
  4879. // uninitialized string
  4880. char[] imdt = new char[8];
  4881. m_host.AddScriptLPS(1);
  4882. // Manually unroll the loop
  4883. imdt[7] = '=';
  4884. imdt[6] = '=';
  4885. imdt[5] = i2ctable[number<<4 & 0x3F];
  4886. imdt[4] = i2ctable[number>>2 & 0x3F];
  4887. imdt[3] = i2ctable[number>>8 & 0x3F];
  4888. imdt[2] = i2ctable[number>>14 & 0x3F];
  4889. imdt[1] = i2ctable[number>>20 & 0x3F];
  4890. imdt[0] = i2ctable[number>>26 & 0x3F];
  4891. return new string(imdt);
  4892. }
  4893. // <summary>
  4894. // Converts an eight character base-64 string
  4895. // into a 32-bit integer.
  4896. // </summary>
  4897. // <param name="str">
  4898. // 8 characters string to be converted. Other
  4899. // length strings return zero.
  4900. // </param>
  4901. // <returns>
  4902. // Returns an integer representing the
  4903. // encoded value providedint he 1st 6
  4904. // characters of the string.
  4905. // </returns>
  4906. // <remarks>
  4907. // This is coded to behave like LSL's
  4908. // implementation (I think), based upon the
  4909. // information available at the Wiki.
  4910. // If more than 8 characters are supplied,
  4911. // zero is returned.
  4912. // If a NULL string is supplied, zero will
  4913. // be returned.
  4914. // If fewer than 6 characters are supplied, then
  4915. // the answer will reflect a partial
  4916. // accumulation.
  4917. // <para>
  4918. // The 6-bit segments are
  4919. // extracted left-to-right in big-endian mode,
  4920. // which means that segment 6 only contains the
  4921. // two low-order bits of the 32 bit integer as
  4922. // its high order 2 bits. A short string therefore
  4923. // means loss of low-order information. E.g.
  4924. //
  4925. // |<---------------------- 32-bit integer ----------------------->|<-Pad->|
  4926. // |<--Byte 0----->|<--Byte 1----->|<--Byte 2----->|<--Byte 3----->|<-Pad->|
  4927. // |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|
  4928. // |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|
  4929. // | str[0] | str[1] | str[2] | str[3] | str[4] | str[6] |
  4930. //
  4931. // </para>
  4932. // </remarks>
  4933. public LSL_Types.LSLInteger llBase64ToInteger(string str)
  4934. {
  4935. int number = 0;
  4936. int digit;
  4937. m_host.AddScriptLPS(1);
  4938. // Require a well-fromed base64 string
  4939. if (str.Length > 8)
  4940. return 0;
  4941. // The loop is unrolled in the interests
  4942. // of performance and simple necessity.
  4943. //
  4944. // MUST find 6 digits to be well formed
  4945. // -1 == invalid
  4946. // 0 == padding
  4947. if ((digit=c2itable[str[0]])<=0)
  4948. {
  4949. return digit<0?(int)0:number;
  4950. }
  4951. number += --digit<<26;
  4952. if ((digit=c2itable[str[1]])<=0)
  4953. {
  4954. return digit<0?(int)0:number;
  4955. }
  4956. number += --digit<<20;
  4957. if ((digit=c2itable[str[2]])<=0)
  4958. {
  4959. return digit<0?(int)0:number;
  4960. }
  4961. number += --digit<<14;
  4962. if ((digit=c2itable[str[3]])<=0)
  4963. {
  4964. return digit<0?(int)0:number;
  4965. }
  4966. number += --digit<<8;
  4967. if ((digit=c2itable[str[4]])<=0)
  4968. {
  4969. return digit<0?(int)0:number;
  4970. }
  4971. number += --digit<<2;
  4972. if ((digit=c2itable[str[5]])<=0)
  4973. {
  4974. return digit<0?(int)0:number;
  4975. }
  4976. number += --digit>>4;
  4977. // ignore trailing padding
  4978. return number;
  4979. }
  4980. public double llGetGMTclock()
  4981. {
  4982. m_host.AddScriptLPS(1);
  4983. return DateTime.UtcNow.TimeOfDay.TotalSeconds;
  4984. }
  4985. public string llGetSimulatorHostname()
  4986. {
  4987. m_host.AddScriptLPS(1);
  4988. return System.Environment.MachineName;
  4989. }
  4990. public void llSetLocalRot(LSL_Types.Quaternion rot)
  4991. {
  4992. m_host.AddScriptLPS(1);
  4993. m_host.RotationOffset = new LLQuaternion((float)rot.x, (float)rot.y, (float)rot.z, (float)rot.s);
  4994. }
  4995. // <summary>
  4996. // Scan the string supplied in 'src' and
  4997. // tokenize it based upon two sets of
  4998. // tokenizers provided in two lists,
  4999. // separators and spacers.
  5000. // </summary>
  5001. //
  5002. // <remarks>
  5003. // Separators demarcate tokens and are
  5004. // elided as they are encountered. Spacers
  5005. // also demarcate tokens, but are themselves
  5006. // retained as tokens.
  5007. //
  5008. // Both separators and spacers may be arbitrarily
  5009. // long strings. i.e. ":::".
  5010. //
  5011. // The function returns an ordered list
  5012. // representing the tokens found in the supplied
  5013. // sources string. If two successive tokenizers
  5014. // are encountered, then a NULL entry is added
  5015. // to the list.
  5016. //
  5017. // It is a precondition that the source and
  5018. // toekizer lisst are non-null. If they are null,
  5019. // then a null pointer exception will be thrown
  5020. // while their lengths are being determined.
  5021. //
  5022. // A small amount of working memoryis required
  5023. // of approximately 8*#tokenizers.
  5024. //
  5025. // There are many ways in which this function
  5026. // can be implemented, this implementation is
  5027. // fairly naive and assumes that when the
  5028. // function is invooked with a short source
  5029. // string and/or short lists of tokenizers, then
  5030. // performance will not be an issue.
  5031. //
  5032. // In order to minimize the perofrmance
  5033. // effects of long strings, or large numbers
  5034. // of tokeizers, the function skips as far as
  5035. // possible whenever a toekenizer is found,
  5036. // and eliminates redundant tokenizers as soon
  5037. // as is possible.
  5038. //
  5039. // The implementation tries to avoid any copying
  5040. // of arrays or other objects.
  5041. // </remarks>
  5042. public LSL_Types.list llParseStringKeepNulls(string src, LSL_Types.list separators, LSL_Types.list spacers)
  5043. {
  5044. int beginning = 0;
  5045. int srclen = src.Length;
  5046. int seplen = separators.Length;
  5047. object[] separray = separators.Data;
  5048. int spclen = spacers.Length;
  5049. object[] spcarray = spacers.Data;
  5050. int mlen = seplen+spclen;
  5051. int[] offset = new int[mlen+1];
  5052. bool[] active = new bool[mlen];
  5053. int best;
  5054. int j;
  5055. // Initial capacity reduces resize cost
  5056. LSL_Types.list tokens = new LSL_Types.list();
  5057. m_host.AddScriptLPS(1);
  5058. // All entries are initially valid
  5059. for (int i = 0; i < mlen; i++)
  5060. active[i] = true;
  5061. offset[mlen] = srclen;
  5062. while (beginning < srclen)
  5063. {
  5064. best = mlen; // as bad as it gets
  5065. // Scan for separators
  5066. for (j = 0; j < seplen; j++)
  5067. {
  5068. if (active[j])
  5069. {
  5070. // scan all of the markers
  5071. if ((offset[j] = src.IndexOf((string)separray[j],beginning)) == -1)
  5072. {
  5073. // not present at all
  5074. active[j] = false;
  5075. }
  5076. else
  5077. {
  5078. // present and correct
  5079. if (offset[j] < offset[best])
  5080. {
  5081. // closest so far
  5082. best = j;
  5083. if (offset[best] == beginning)
  5084. break;
  5085. }
  5086. }
  5087. }
  5088. }
  5089. // Scan for spacers
  5090. if (offset[best] != beginning)
  5091. {
  5092. for (j = seplen; (j < mlen) && (offset[best] > beginning); j++)
  5093. {
  5094. if (active[j])
  5095. {
  5096. // scan all of the markers
  5097. if ((offset[j] = src.IndexOf((string)spcarray[j-seplen], beginning)) == -1)
  5098. {
  5099. // not present at all
  5100. active[j] = false;
  5101. }
  5102. else
  5103. {
  5104. // present and correct
  5105. if (offset[j] < offset[best])
  5106. {
  5107. // closest so far
  5108. best = j;
  5109. }
  5110. }
  5111. }
  5112. }
  5113. }
  5114. // This is the normal exit from the scanning loop
  5115. if (best == mlen)
  5116. {
  5117. // no markers were found on this pass
  5118. // so we're pretty much done
  5119. tokens.Add(src.Substring(beginning, srclen - beginning));
  5120. break;
  5121. }
  5122. // Otherwise we just add the newly delimited token
  5123. // and recalculate where the search should continue.
  5124. tokens.Add(src.Substring(beginning,offset[best]-beginning));
  5125. if (best < seplen)
  5126. {
  5127. beginning = offset[best] + ((string)separray[best]).Length;
  5128. }
  5129. else
  5130. {
  5131. beginning = offset[best] + ((string)spcarray[best - seplen]).Length;
  5132. tokens.Add(spcarray[best - seplen]);
  5133. }
  5134. }
  5135. // This an awkward an not very intuitive boundary case. If the
  5136. // last substring is a tokenizer, then there is an implied trailing
  5137. // null list entry. Hopefully the single comparison will not be too
  5138. // arduous. Alternatively the 'break' could be replced with a return
  5139. // but that's shabby programming.
  5140. if (beginning == srclen)
  5141. {
  5142. if (srclen != 0)
  5143. tokens.Add("");
  5144. }
  5145. return tokens;
  5146. }
  5147. public void llRezAtRoot(string inventory, LSL_Types.Vector3 position, LSL_Types.Vector3 velocity,
  5148. LSL_Types.Quaternion rot, int param)
  5149. {
  5150. m_host.AddScriptLPS(1);
  5151. NotImplemented("llRezAtRoot");
  5152. }
  5153. public LSL_Types.LSLInteger llGetObjectPermMask(int mask)
  5154. {
  5155. m_host.AddScriptLPS(1);
  5156. int permmask = 0;
  5157. if (mask == ScriptBaseClass.MASK_BASE)//0
  5158. {
  5159. permmask = (int)m_host.BaseMask;
  5160. }
  5161. else if (mask == ScriptBaseClass.MASK_OWNER)//1
  5162. {
  5163. permmask = (int)m_host.OwnerMask;
  5164. }
  5165. else if (mask == ScriptBaseClass.MASK_GROUP)//2
  5166. {
  5167. permmask = (int)m_host.GroupMask;
  5168. }
  5169. else if (mask == ScriptBaseClass.MASK_EVERYONE)//3
  5170. {
  5171. permmask = (int)m_host.EveryoneMask;
  5172. }
  5173. else if (mask == ScriptBaseClass.MASK_NEXT)//4
  5174. {
  5175. permmask = (int)m_host.NextOwnerMask;
  5176. }
  5177. return permmask;
  5178. }
  5179. public void llSetObjectPermMask(int mask, int value)
  5180. {
  5181. m_host.AddScriptLPS(1);
  5182. IConfigSource config = new IniConfigSource(Application.iniFilePath);
  5183. if (config.Configs["XEngine"] == null)
  5184. config.AddConfig("XEngine");
  5185. if (config.Configs["XEngine"].GetBoolean("AllowGodFunctions", false))
  5186. {
  5187. if (World.ExternalChecks.ExternalChecksCanRunConsoleCommand(m_host.OwnerID))
  5188. {
  5189. if (mask == ScriptBaseClass.MASK_BASE)//0
  5190. {
  5191. m_host.BaseMask = (uint)value;
  5192. }
  5193. else if (mask == ScriptBaseClass.MASK_OWNER)//1
  5194. {
  5195. m_host.OwnerMask = (uint)value;
  5196. }
  5197. else if (mask == ScriptBaseClass.MASK_GROUP)//2
  5198. {
  5199. m_host.GroupMask = (uint)value;
  5200. }
  5201. else if (mask == ScriptBaseClass.MASK_EVERYONE)//3
  5202. {
  5203. m_host.EveryoneMask = (uint)value;
  5204. }
  5205. else if (mask == ScriptBaseClass.MASK_NEXT)//4
  5206. {
  5207. m_host.NextOwnerMask = (uint)value;
  5208. }
  5209. }
  5210. }
  5211. }
  5212. public LSL_Types.LSLInteger llGetInventoryPermMask(string item, int mask)
  5213. {
  5214. m_host.AddScriptLPS(1);
  5215. foreach (KeyValuePair<LLUUID, TaskInventoryItem> inv in m_host.TaskInventory)
  5216. {
  5217. if (inv.Value.Name == item)
  5218. {
  5219. switch (mask)
  5220. {
  5221. case 0:
  5222. return (int)inv.Value.BaseMask;
  5223. case 1:
  5224. return (int)inv.Value.OwnerMask;
  5225. case 2:
  5226. return (int)inv.Value.GroupMask;
  5227. case 3:
  5228. return (int)inv.Value.EveryoneMask;
  5229. case 4:
  5230. return (int)inv.Value.NextOwnerMask;
  5231. }
  5232. }
  5233. }
  5234. return -1;
  5235. }
  5236. public void llSetInventoryPermMask(string item, int mask, int value)
  5237. {
  5238. m_host.AddScriptLPS(1);
  5239. NotImplemented("llSetInventoryPermMask");
  5240. }
  5241. public string llGetInventoryCreator(string item)
  5242. {
  5243. m_host.AddScriptLPS(1);
  5244. foreach (KeyValuePair<LLUUID, TaskInventoryItem> inv in m_host.TaskInventory)
  5245. {
  5246. if (inv.Value.Name == item)
  5247. {
  5248. return inv.Value.CreatorID.ToString();
  5249. }
  5250. }
  5251. llSay(0, "No item name '" + item + "'");
  5252. return String.Empty;
  5253. }
  5254. public void llOwnerSay(string msg)
  5255. {
  5256. m_host.AddScriptLPS(1);
  5257. World.SimChatBroadcast(Helpers.StringToField(msg), ChatTypeEnum.Owner, 0, m_host.AbsolutePosition, m_host.Name, m_host.UUID, false);
  5258. // IWorldComm wComm = m_ScriptEngine.World.RequestModuleInterface<IWorldComm>();
  5259. // wComm.DeliverMessage(ChatTypeEnum.Owner, 0, m_host.Name, m_host.UUID, msg);
  5260. }
  5261. public string llRequestSimulatorData(string simulator, int data)
  5262. {
  5263. try
  5264. {
  5265. m_host.AddScriptLPS(1);
  5266. string reply = String.Empty;
  5267. RegionInfo info = m_ScriptEngine.World.RequestClosestRegion(simulator);
  5268. switch (data)
  5269. {
  5270. case 5: // DATA_SIM_POS
  5271. if (info == null)
  5272. return LLUUID.Zero.ToString();
  5273. reply = new LSL_Types.Vector3(
  5274. info.RegionLocX * Constants.RegionSize,
  5275. info.RegionLocY * Constants.RegionSize,
  5276. 0).ToString();
  5277. break;
  5278. case 6: // DATA_SIM_STATUS
  5279. if (info != null)
  5280. reply = "up"; // Duh!
  5281. else
  5282. reply = "unknown";
  5283. break;
  5284. case 7: // DATA_SIM_RATING
  5285. if (info == null)
  5286. return LLUUID.Zero.ToString();
  5287. int access = (int)info.EstateSettings.simAccess;
  5288. if (access == 21)
  5289. reply = "MATURE";
  5290. else if (access == 13)
  5291. reply = "MATURE";
  5292. else
  5293. reply = "UNKNOWN";
  5294. break;
  5295. default:
  5296. return LLUUID.Zero.ToString(); // Raise no event
  5297. }
  5298. LLUUID rq = LLUUID.Random();
  5299. LLUUID tid = AsyncCommands.
  5300. DataserverPlugin.RegisterRequest(m_localID,
  5301. m_itemID, rq.ToString());
  5302. AsyncCommands.
  5303. DataserverPlugin.DataserverReply(rq.ToString(), reply);
  5304. return tid.ToString();
  5305. }
  5306. catch(Exception e)
  5307. {
  5308. Console.WriteLine(e.ToString());
  5309. return LLUUID.Zero.ToString();
  5310. }
  5311. }
  5312. public void llForceMouselook(int mouselook)
  5313. {
  5314. m_host.AddScriptLPS(1);
  5315. NotImplemented("llForceMouselook");
  5316. }
  5317. public double llGetObjectMass(string id)
  5318. {
  5319. m_host.AddScriptLPS(1);
  5320. LLUUID key = new LLUUID();
  5321. if (LLUUID.TryParse(id,out key))
  5322. {
  5323. return (double) World.GetSceneObjectPart(World.Entities[key].LocalId).GetMass();
  5324. }
  5325. return 0;
  5326. }
  5327. /// <summary>
  5328. /// illListReplaceList removes the sub-list defined by the inclusive indices
  5329. /// start and end and inserts the src list in its place. The inclusive
  5330. /// nature of the indices means that at least one element must be deleted
  5331. /// if the indices are within the bounds of the existing list. I.e. 2,2
  5332. /// will remove the element at index 2 and replace it with the source
  5333. /// list. Both indices may be negative, with the usual interpretation. An
  5334. /// interesting case is where end is lower than start. As these indices
  5335. /// bound the list to be removed, then 0->end, and start->lim are removed
  5336. /// and the source list is added as a suffix.
  5337. /// </summary>
  5338. public LSL_Types.list llListReplaceList(LSL_Types.list dest, LSL_Types.list src, int start, int end)
  5339. {
  5340. LSL_Types.list pref = null;
  5341. m_host.AddScriptLPS(1);
  5342. // Note that although we have normalized, both
  5343. // indices could still be negative.
  5344. if (start < 0)
  5345. {
  5346. start = start+dest.Length;
  5347. }
  5348. if (end < 0)
  5349. {
  5350. end = end+dest.Length;
  5351. }
  5352. // The comventional case, remove a sequence starting with
  5353. // start and ending with end. And then insert the source
  5354. // list.
  5355. if (start <= end)
  5356. {
  5357. // If greater than zero, then there is going to be a
  5358. // surviving prefix. Otherwise the inclusive nature
  5359. // of the indices mean that we're going to add the
  5360. // source list as a prefix.
  5361. if (start > 0)
  5362. {
  5363. pref = dest.GetSublist(0,start-1);
  5364. // Only add a suffix if there is something
  5365. // beyond the end index (it's inclusive too).
  5366. if (end + 1 < dest.Length)
  5367. {
  5368. return pref + src + dest.GetSublist(end + 1, -1);
  5369. }
  5370. else
  5371. {
  5372. return pref + src;
  5373. }
  5374. }
  5375. // If start is less than or equal to zero, then
  5376. // the new list is simply a prefix. We still need to
  5377. // figure out any necessary surgery to the destination
  5378. // based upon end. Note that if end exceeds the upper
  5379. // bound in this case, the entire destination list
  5380. // is removed.
  5381. else
  5382. {
  5383. if (end + 1 < dest.Length)
  5384. {
  5385. return src + dest.GetSublist(end + 1, -1);
  5386. }
  5387. else
  5388. {
  5389. return src;
  5390. }
  5391. }
  5392. }
  5393. // Finally, if start > end, we strip away a prefix and
  5394. // a suffix, to leave the list that sits <between> ens
  5395. // and start, and then tag on the src list. AT least
  5396. // that's my interpretation. We can get sublist to do
  5397. // this for us. Note that one, or both of the indices
  5398. // might have been negative.
  5399. else
  5400. {
  5401. return dest.GetSublist(end + 1, start - 1) + src;
  5402. }
  5403. }
  5404. public void llLoadURL(string avatar_id, string message, string url)
  5405. {
  5406. m_host.AddScriptLPS(1);
  5407. LLUUID avatarId = new LLUUID(avatar_id);
  5408. m_ScriptEngine.World.SendUrlToUser(avatarId, m_host.Name, m_host.UUID, m_host.ObjectOwner, false, message,
  5409. url);
  5410. }
  5411. public void llParcelMediaCommandList(LSL_Types.list commandList)
  5412. {
  5413. m_host.AddScriptLPS(1);
  5414. NotImplemented("llParcelMediaCommandList");
  5415. }
  5416. public void llParcelMediaQuery()
  5417. {
  5418. m_host.AddScriptLPS(1);
  5419. NotImplemented("llParcelMediaQuery");
  5420. }
  5421. public LSL_Types.LSLInteger llModPow(int a, int b, int c)
  5422. {
  5423. m_host.AddScriptLPS(1);
  5424. Int64 tmp = 0;
  5425. Math.DivRem(Convert.ToInt64(Math.Pow(a, b)), c, out tmp);
  5426. return Convert.ToInt32(tmp);
  5427. }
  5428. public LSL_Types.LSLInteger llGetInventoryType(string name)
  5429. {
  5430. m_host.AddScriptLPS(1);
  5431. foreach (KeyValuePair<LLUUID, TaskInventoryItem> inv in m_host.TaskInventory)
  5432. {
  5433. if (inv.Value.Name == name)
  5434. {
  5435. return inv.Value.InvType;
  5436. }
  5437. }
  5438. return -1;
  5439. }
  5440. public void llSetPayPrice(int price, LSL_Types.list quick_pay_buttons)
  5441. {
  5442. m_host.AddScriptLPS(1);
  5443. if (quick_pay_buttons.Data.Length != 4)
  5444. {
  5445. LSLError("List must have 4 elements");
  5446. return;
  5447. }
  5448. m_host.ParentGroup.RootPart.PayPrice[0]=price;
  5449. m_host.ParentGroup.RootPart.PayPrice[1]=(int)quick_pay_buttons.Data[0];
  5450. m_host.ParentGroup.RootPart.PayPrice[2]=(int)quick_pay_buttons.Data[1];
  5451. m_host.ParentGroup.RootPart.PayPrice[3]=(int)quick_pay_buttons.Data[2];
  5452. m_host.ParentGroup.RootPart.PayPrice[4]=(int)quick_pay_buttons.Data[3];
  5453. }
  5454. public LSL_Types.Vector3 llGetCameraPos()
  5455. {
  5456. m_host.AddScriptLPS(1);
  5457. LLUUID invItemID=InventorySelf();
  5458. if (invItemID == LLUUID.Zero)
  5459. return new LSL_Types.Vector3();
  5460. if (m_host.TaskInventory[invItemID].PermsGranter == LLUUID.Zero)
  5461. return new LSL_Types.Vector3();
  5462. if ((m_host.TaskInventory[invItemID].PermsMask & ScriptBaseClass.PERMISSION_TRACK_CAMERA) == 0)
  5463. {
  5464. ShoutError("No permissions to track the camera");
  5465. return new LSL_Types.Vector3();
  5466. }
  5467. ScenePresence presence = World.GetScenePresence(m_host.OwnerID);
  5468. LSL_Types.Vector3 pos = new LSL_Types.Vector3(presence.CameraPosition.x,presence.CameraPosition.y,presence.CameraPosition.z);
  5469. return pos;
  5470. }
  5471. public LSL_Types.Quaternion llGetCameraRot()
  5472. {
  5473. m_host.AddScriptLPS(1);
  5474. NotImplemented("llGetCameraRot");
  5475. return new LSL_Types.Quaternion();
  5476. }
  5477. public void llSetPrimURL()
  5478. {
  5479. m_host.AddScriptLPS(1);
  5480. NotImplemented("llSetPrimURL");
  5481. }
  5482. public void llRefreshPrimURL()
  5483. {
  5484. m_host.AddScriptLPS(1);
  5485. NotImplemented("llRefreshPrimURL");
  5486. }
  5487. public string llEscapeURL(string url)
  5488. {
  5489. m_host.AddScriptLPS(1);
  5490. try
  5491. {
  5492. return Uri.EscapeUriString(url);
  5493. }
  5494. catch (Exception ex)
  5495. {
  5496. return "llEscapeURL: " + ex.ToString();
  5497. }
  5498. }
  5499. public string llUnescapeURL(string url)
  5500. {
  5501. m_host.AddScriptLPS(1);
  5502. try
  5503. {
  5504. return Uri.UnescapeDataString(url);
  5505. }
  5506. catch (Exception ex)
  5507. {
  5508. return "llUnescapeURL: " + ex.ToString();
  5509. }
  5510. }
  5511. public void llMapDestination(string simname, LSL_Types.Vector3 pos, LSL_Types.Vector3 look_at)
  5512. {
  5513. m_host.AddScriptLPS(1);
  5514. NotImplemented("llMapDestination");
  5515. }
  5516. public void llAddToLandBanList(string avatar, double hours)
  5517. {
  5518. m_host.AddScriptLPS(1);
  5519. LLUUID key;
  5520. LandData land = World.LandChannel.GetLandObject(m_host.AbsolutePosition.X, m_host.AbsolutePosition.Y).landData;
  5521. if (land.ownerID == m_host.OwnerID)
  5522. {
  5523. ParcelManager.ParcelAccessEntry entry = new ParcelManager.ParcelAccessEntry();
  5524. if (LLUUID.TryParse(avatar, out key))
  5525. {
  5526. entry.AgentID = key;
  5527. entry.Flags = ParcelManager.AccessList.Ban;
  5528. entry.Time = DateTime.Now.AddHours(hours);
  5529. land.parcelAccessList.Add(entry);
  5530. }
  5531. }
  5532. }
  5533. public void llRemoveFromLandPassList(string avatar)
  5534. {
  5535. m_host.AddScriptLPS(1);
  5536. LLUUID key;
  5537. LandData land = World.LandChannel.GetLandObject(m_host.AbsolutePosition.X, m_host.AbsolutePosition.Y).landData;
  5538. if (land.ownerID == m_host.OwnerID)
  5539. {
  5540. if (LLUUID.TryParse(avatar, out key))
  5541. {
  5542. foreach (ParcelManager.ParcelAccessEntry entry in land.parcelAccessList)
  5543. {
  5544. if (entry.AgentID == key && entry.Flags == ParcelManager.AccessList.Access)
  5545. {
  5546. land.parcelAccessList.Remove(entry);
  5547. break;
  5548. }
  5549. }
  5550. }
  5551. }
  5552. }
  5553. public void llRemoveFromLandBanList(string avatar)
  5554. {
  5555. m_host.AddScriptLPS(1);
  5556. LLUUID key;
  5557. LandData land = World.LandChannel.GetLandObject(m_host.AbsolutePosition.X, m_host.AbsolutePosition.Y).landData;
  5558. if (land.ownerID == m_host.OwnerID)
  5559. {
  5560. if (LLUUID.TryParse(avatar, out key))
  5561. {
  5562. foreach (ParcelManager.ParcelAccessEntry entry in land.parcelAccessList)
  5563. {
  5564. if (entry.AgentID == key && entry.Flags == ParcelManager.AccessList.Ban)
  5565. {
  5566. land.parcelAccessList.Remove(entry);
  5567. break;
  5568. }
  5569. }
  5570. }
  5571. }
  5572. }
  5573. public void llSetCameraParams(LSL_Types.list rules)
  5574. {
  5575. m_host.AddScriptLPS(1);
  5576. NotImplemented("llSetCameraParams");
  5577. }
  5578. public void llClearCameraParams()
  5579. {
  5580. m_host.AddScriptLPS(1);
  5581. NotImplemented("llClearCameraParams");
  5582. }
  5583. public double llListStatistics(int operation, LSL_Types.list src)
  5584. {
  5585. m_host.AddScriptLPS(1);
  5586. LSL_Types.list nums = LSL_Types.list.ToDoubleList(src);
  5587. switch (operation)
  5588. {
  5589. case ScriptBaseClass.LIST_STAT_RANGE:
  5590. return nums.Range();
  5591. case ScriptBaseClass.LIST_STAT_MIN:
  5592. return nums.Min();
  5593. case ScriptBaseClass.LIST_STAT_MAX:
  5594. return nums.Max();
  5595. case ScriptBaseClass.LIST_STAT_MEAN:
  5596. return nums.Mean();
  5597. case ScriptBaseClass.LIST_STAT_MEDIAN:
  5598. return nums.Median();
  5599. case ScriptBaseClass.LIST_STAT_NUM_COUNT:
  5600. return nums.NumericLength();
  5601. case ScriptBaseClass.LIST_STAT_STD_DEV:
  5602. return nums.StdDev();
  5603. case ScriptBaseClass.LIST_STAT_SUM:
  5604. return nums.Sum();
  5605. case ScriptBaseClass.LIST_STAT_SUM_SQUARES:
  5606. return nums.SumSqrs();
  5607. case ScriptBaseClass.LIST_STAT_GEOMETRIC_MEAN:
  5608. return nums.GeometricMean();
  5609. case ScriptBaseClass.LIST_STAT_HARMONIC_MEAN:
  5610. return nums.HarmonicMean();
  5611. default:
  5612. return 0.0;
  5613. }
  5614. }
  5615. public LSL_Types.LSLInteger llGetUnixTime()
  5616. {
  5617. m_host.AddScriptLPS(1);
  5618. return Util.UnixTimeSinceEpoch();
  5619. }
  5620. public LSL_Types.LSLInteger llGetParcelFlags(LSL_Types.Vector3 pos)
  5621. {
  5622. m_host.AddScriptLPS(1);
  5623. return (int)World.LandChannel.GetLandObject((float)pos.x, (float)pos.y).landData.landFlags;
  5624. }
  5625. public LSL_Types.LSLInteger llGetRegionFlags()
  5626. {
  5627. m_host.AddScriptLPS(1);
  5628. return (int)World.RegionInfo.EstateSettings.regionFlags;
  5629. }
  5630. public string llXorBase64StringsCorrect(string str1, string str2)
  5631. {
  5632. m_host.AddScriptLPS(1);
  5633. string ret = String.Empty;
  5634. string src1 = llBase64ToString(str1);
  5635. string src2 = llBase64ToString(str2);
  5636. int c = 0;
  5637. for (int i = 0; i < src1.Length; i++)
  5638. {
  5639. ret += src1[i] ^ src2[c];
  5640. c++;
  5641. if (c > src2.Length)
  5642. c = 0;
  5643. }
  5644. return llStringToBase64(ret);
  5645. }
  5646. public string llHTTPRequest(string url, LSL_Types.list parameters, string body)
  5647. {
  5648. // Partial implementation: support for parameter flags needed
  5649. // see http://wiki.secondlife.com/wiki/LlHTTPRequest
  5650. // parameter flags support are implemented in ScriptsHttpRequests.cs
  5651. // in StartHttpRequest
  5652. m_host.AddScriptLPS(1);
  5653. IHttpRequests httpScriptMod =
  5654. m_ScriptEngine.World.RequestModuleInterface<IHttpRequests>();
  5655. List<string> param = new List<string>();
  5656. foreach (object o in parameters.Data)
  5657. {
  5658. param.Add(o.ToString());
  5659. }
  5660. LLUUID reqID = httpScriptMod.
  5661. StartHttpRequest(m_localID, m_itemID, url, param, body);
  5662. if (reqID != LLUUID.Zero)
  5663. return reqID.ToString();
  5664. else
  5665. return null;
  5666. }
  5667. public void llResetLandBanList()
  5668. {
  5669. m_host.AddScriptLPS(1);
  5670. LandData land = World.LandChannel.GetLandObject(m_host.AbsolutePosition.X, m_host.AbsolutePosition.Y).landData;
  5671. if (land.ownerID == m_host.OwnerID)
  5672. {
  5673. foreach (ParcelManager.ParcelAccessEntry entry in land.parcelAccessList)
  5674. {
  5675. if (entry.Flags == ParcelManager.AccessList.Ban)
  5676. {
  5677. land.parcelAccessList.Remove(entry);
  5678. }
  5679. }
  5680. }
  5681. }
  5682. public void llResetLandPassList()
  5683. {
  5684. m_host.AddScriptLPS(1);
  5685. LandData land = World.LandChannel.GetLandObject(m_host.AbsolutePosition.X, m_host.AbsolutePosition.Y).landData;
  5686. if (land.ownerID == m_host.OwnerID)
  5687. {
  5688. foreach (ParcelManager.ParcelAccessEntry entry in land.parcelAccessList)
  5689. {
  5690. if (entry.Flags == ParcelManager.AccessList.Access)
  5691. {
  5692. land.parcelAccessList.Remove(entry);
  5693. }
  5694. }
  5695. }
  5696. }
  5697. public LSL_Types.LSLInteger llGetParcelPrimCount(LSL_Types.Vector3 pos, int category, int sim_wide)
  5698. {
  5699. m_host.AddScriptLPS(1);
  5700. LandData land = World.GetLandData((float)pos.x, (float)pos.y);
  5701. if (land == null)
  5702. {
  5703. return 0;
  5704. }
  5705. else
  5706. {
  5707. if (sim_wide == 1)
  5708. {
  5709. if (category == 0)
  5710. {
  5711. return land.simwidePrims;
  5712. }
  5713. else
  5714. {
  5715. //public int simwideArea = 0;
  5716. return 0;
  5717. }
  5718. }
  5719. else
  5720. {
  5721. if (category == 0)//Total Prims
  5722. {
  5723. return 0;//land.
  5724. }
  5725. else if (category == 1)//Owner Prims
  5726. {
  5727. return land.ownerPrims;
  5728. }
  5729. else if (category == 2)//Group Prims
  5730. {
  5731. return land.groupPrims;
  5732. }
  5733. else if (category == 3)//Other Prims
  5734. {
  5735. return land.otherPrims;
  5736. }
  5737. else if (category == 4)//Selected
  5738. {
  5739. return land.selectedPrims;
  5740. }
  5741. else if (category == 5)//Temp
  5742. {
  5743. return 0;//land.
  5744. }
  5745. }
  5746. }
  5747. return 0;
  5748. }
  5749. public LSL_Types.list llGetParcelPrimOwners(LSL_Types.Vector3 pos)
  5750. {
  5751. m_host.AddScriptLPS(1);
  5752. LandObject land = (LandObject)World.LandChannel.GetLandObject((float)pos.x, (float)pos.y);
  5753. LSL_Types.list ret = new LSL_Types.list();
  5754. if (land != null)
  5755. {
  5756. foreach (KeyValuePair<LLUUID, int> d in land.getLandObjectOwners())
  5757. {
  5758. ret.Add(d.Key.ToString());
  5759. ret.Add(d.Value);
  5760. }
  5761. }
  5762. return ret;
  5763. }
  5764. public LSL_Types.LSLInteger llGetObjectPrimCount(string object_id)
  5765. {
  5766. m_host.AddScriptLPS(1);
  5767. SceneObjectPart part = World.GetSceneObjectPart(new LLUUID(object_id));
  5768. if (part == null)
  5769. {
  5770. return 0;
  5771. }
  5772. else
  5773. {
  5774. return part.ParentGroup.Children.Count;
  5775. }
  5776. }
  5777. public LSL_Types.LSLInteger llGetParcelMaxPrims(LSL_Types.Vector3 pos, int sim_wide)
  5778. {
  5779. m_host.AddScriptLPS(1);
  5780. // Alondria: This currently just is utilizing the normal grid's 0.22 prims/m2 calculation
  5781. // Which probably will be irrelevent in OpenSim....
  5782. LandData land = World.GetLandData((float)pos.x, (float)pos.y);
  5783. float bonusfactor = World.RegionInfo.EstateSettings.objectBonusFactor;
  5784. if (land == null)
  5785. {
  5786. return 0;
  5787. }
  5788. if (sim_wide == 1)
  5789. {
  5790. decimal v = land.simwideArea * (decimal)(0.22) * (decimal)bonusfactor;
  5791. return (int)v;
  5792. }
  5793. else
  5794. {
  5795. decimal v = land.area * (decimal)(0.22) * (decimal)bonusfactor;
  5796. return (int)v;
  5797. }
  5798. }
  5799. public LSL_Types.list llGetParcelDetails(LSL_Types.Vector3 pos, LSL_Types.list param)
  5800. {
  5801. m_host.AddScriptLPS(1);
  5802. LandData land = World.GetLandData((float)pos.x, (float)pos.y);
  5803. if (land == null)
  5804. {
  5805. return new LSL_Types.list(0);
  5806. }
  5807. LSL_Types.list ret = new LSL_Types.list();
  5808. foreach (object o in param.Data)
  5809. {
  5810. switch (o.ToString())
  5811. {
  5812. case "0":
  5813. ret = ret + new LSL_Types.list(land.landName);
  5814. break;
  5815. case "1":
  5816. ret = ret + new LSL_Types.list(land.landDesc);
  5817. break;
  5818. case "2":
  5819. ret = ret + new LSL_Types.list(land.ownerID.ToString());
  5820. break;
  5821. case "3":
  5822. ret = ret + new LSL_Types.list(land.groupID.ToString());
  5823. break;
  5824. case "4":
  5825. ret = ret + new LSL_Types.list(land.area);
  5826. break;
  5827. default:
  5828. ret = ret + new LSL_Types.list(0);
  5829. break;
  5830. }
  5831. }
  5832. return ret;
  5833. }
  5834. public void llSetLinkTexture(int linknumber, string texture, int face)
  5835. {
  5836. m_host.AddScriptLPS(1);
  5837. NotImplemented("llSetLinkTexture");
  5838. }
  5839. public string llStringTrim(string src, int type)
  5840. {
  5841. m_host.AddScriptLPS(1);
  5842. if (type == (int)ScriptBaseClass.STRING_TRIM_HEAD) { return src.TrimStart(); }
  5843. if (type == (int)ScriptBaseClass.STRING_TRIM_TAIL) { return src.TrimEnd(); }
  5844. if (type == (int)ScriptBaseClass.STRING_TRIM) { return src.Trim(); }
  5845. return src;
  5846. }
  5847. public LSL_Types.list llGetObjectDetails(string id, LSL_Types.list args)
  5848. {
  5849. m_host.AddScriptLPS(1);
  5850. LSL_Types.list ret = new LSL_Types.list();
  5851. LLUUID key = new LLUUID();
  5852. if (LLUUID.TryParse(id, out key))
  5853. {
  5854. ScenePresence av = World.GetScenePresence(key);
  5855. if (av != null)
  5856. {
  5857. foreach (object o in args.Data)
  5858. {
  5859. switch (o.ToString())
  5860. {
  5861. case "1":
  5862. ret.Add(av.Firstname + " " + av.Lastname);
  5863. break;
  5864. case "2":
  5865. ret.Add("");
  5866. break;
  5867. case "3":
  5868. ret.Add(new LSL_Types.Vector3((double)av.AbsolutePosition.X, (double)av.AbsolutePosition.Y, (double)av.AbsolutePosition.Z));
  5869. break;
  5870. case "4":
  5871. ret.Add(new LSL_Types.Quaternion((double)av.Rotation.x, (double)av.Rotation.y, (double)av.Rotation.z, (double)av.Rotation.w));
  5872. break;
  5873. case "5":
  5874. ret.Add(new LSL_Types.Vector3(av.Velocity.X,av.Velocity.Y,av.Velocity.Z));
  5875. break;
  5876. case "6":
  5877. ret.Add(id);
  5878. break;
  5879. case "7":
  5880. ret.Add(LLUUID.Zero.ToString());
  5881. break;
  5882. case "8":
  5883. ret.Add(LLUUID.Zero.ToString());
  5884. break;
  5885. }
  5886. }
  5887. return ret;
  5888. }
  5889. SceneObjectPart obj = World.GetSceneObjectPart(key);
  5890. if (obj != null)
  5891. {
  5892. foreach (object o in args.Data)
  5893. {
  5894. switch (o.ToString())
  5895. {
  5896. case "1":
  5897. ret.Add(obj.Name);
  5898. break;
  5899. case "2":
  5900. ret.Add(obj.Description);
  5901. break;
  5902. case "3":
  5903. ret.Add(new LSL_Types.Vector3(obj.AbsolutePosition.X,obj.AbsolutePosition.Y,obj.AbsolutePosition.Z));
  5904. break;
  5905. case "4":
  5906. ret.Add(new LSL_Types.Quaternion(obj.RotationOffset.X, obj.RotationOffset.Y, obj.RotationOffset.Z, obj.RotationOffset.W));
  5907. break;
  5908. case "5":
  5909. ret.Add(new LSL_Types.Vector3(obj.Velocity.X, obj.Velocity.Y, obj.Velocity.Z));
  5910. break;
  5911. case "6":
  5912. ret.Add(obj.OwnerID.ToString());
  5913. break;
  5914. case "7":
  5915. ret.Add(obj.GroupID.ToString());
  5916. break;
  5917. case "8":
  5918. ret.Add(obj.CreatorID.ToString());
  5919. break;
  5920. }
  5921. }
  5922. return ret;
  5923. }
  5924. }
  5925. return new LSL_Types.list();
  5926. }
  5927. internal LLUUID ScriptByName(string name)
  5928. {
  5929. foreach (TaskInventoryItem item in m_host.TaskInventory.Values)
  5930. {
  5931. if (item.Type == 10 && item.Name == name)
  5932. return item.ItemID;
  5933. }
  5934. return LLUUID.Zero;
  5935. }
  5936. internal void ShoutError(string msg)
  5937. {
  5938. llShout(ScriptBaseClass.DEBUG_CHANNEL, msg);
  5939. }
  5940. internal void NotImplemented(string command)
  5941. {
  5942. if (throwErrorOnNotImplemented)
  5943. throw new NotImplementedException("Command not implemented: " + command);
  5944. }
  5945. internal void Deprecated(string command)
  5946. {
  5947. throw new Exception("Command deprecated: " + command);
  5948. }
  5949. internal void LSLError(string msg)
  5950. {
  5951. throw new Exception("LSL Runtime Error: " + msg);
  5952. }
  5953. public delegate void AssetRequestCallback(LLUUID assetID, AssetBase asset);
  5954. private void WithNotecard(LLUUID assetID, AssetRequestCallback cb)
  5955. {
  5956. World.AssetCache.GetAsset(assetID, delegate(LLUUID i, AssetBase a) { cb(i, a); }, false);
  5957. }
  5958. public string llGetNumberOfNotecardLines(string name)
  5959. {
  5960. m_host.AddScriptLPS(1);
  5961. foreach (TaskInventoryItem item in m_host.TaskInventory.Values)
  5962. {
  5963. if (item.Type == 7 && item.Name == name)
  5964. {
  5965. LLUUID tid = AsyncCommands.
  5966. DataserverPlugin.RegisterRequest(m_localID,
  5967. m_itemID, item.AssetID.ToString());
  5968. if (NotecardCache.IsCached(item.AssetID))
  5969. {
  5970. AsyncCommands.
  5971. DataserverPlugin.DataserverReply(item.AssetID.ToString(),
  5972. NotecardCache.GetLines(item.AssetID).ToString());
  5973. return tid.ToString();
  5974. }
  5975. WithNotecard(item.AssetID, delegate (LLUUID id, AssetBase a)
  5976. {
  5977. System.Text.ASCIIEncoding enc =
  5978. new System.Text.ASCIIEncoding();
  5979. string data = enc.GetString(a.Data);
  5980. //Console.WriteLine(data);
  5981. NotecardCache.Cache(id, data);
  5982. AsyncCommands.
  5983. DataserverPlugin.DataserverReply(id.ToString(),
  5984. NotecardCache.GetLines(id).ToString());
  5985. });
  5986. return tid.ToString();
  5987. }
  5988. }
  5989. return LLUUID.Zero.ToString();
  5990. }
  5991. public string llGetNotecardLine(string name, int line)
  5992. {
  5993. m_host.AddScriptLPS(1);
  5994. foreach (TaskInventoryItem item in m_host.TaskInventory.Values)
  5995. {
  5996. if (item.Type == 7 && item.Name == name)
  5997. {
  5998. LLUUID tid = AsyncCommands.
  5999. DataserverPlugin.RegisterRequest(m_localID,
  6000. m_itemID, item.AssetID.ToString());
  6001. if (NotecardCache.IsCached(item.AssetID))
  6002. {
  6003. AsyncCommands.
  6004. DataserverPlugin.DataserverReply(item.AssetID.ToString(),
  6005. NotecardCache.GetLine(item.AssetID, line));
  6006. return tid.ToString();
  6007. }
  6008. WithNotecard(item.AssetID, delegate (LLUUID id, AssetBase a)
  6009. {
  6010. System.Text.ASCIIEncoding enc =
  6011. new System.Text.ASCIIEncoding();
  6012. string data = enc.GetString(a.Data);
  6013. //Console.WriteLine(data);
  6014. NotecardCache.Cache(id, data);
  6015. AsyncCommands.
  6016. DataserverPlugin.DataserverReply(id.ToString(),
  6017. NotecardCache.GetLine(id, line));
  6018. });
  6019. return tid.ToString();
  6020. }
  6021. }
  6022. return String.Empty;
  6023. }
  6024. }
  6025. public class NotecardCache
  6026. {
  6027. private class Notecard
  6028. {
  6029. public string[] text;
  6030. public DateTime lastRef;
  6031. }
  6032. private static Dictionary<LLUUID, Notecard> m_Notecards =
  6033. new Dictionary<LLUUID, Notecard>();
  6034. public static void Cache(LLUUID assetID, string text)
  6035. {
  6036. CacheCheck();
  6037. lock (m_Notecards)
  6038. {
  6039. if (m_Notecards.ContainsKey(assetID))
  6040. return;
  6041. Notecard nc = new Notecard();
  6042. nc.lastRef = DateTime.Now;
  6043. nc.text = ParseText(text.Replace("\r", "").Split('\n'));
  6044. m_Notecards[assetID] = nc;
  6045. }
  6046. }
  6047. private static string[] ParseText(string[] input)
  6048. {
  6049. int idx = 0;
  6050. int level = 0;
  6051. List<string> output = new List<string>();
  6052. string[] words;
  6053. while (idx < input.Length)
  6054. {
  6055. if (input[idx] == "{")
  6056. {
  6057. level++;
  6058. idx++;
  6059. continue;
  6060. }
  6061. if (input[idx]== "}")
  6062. {
  6063. level--;
  6064. idx++;
  6065. continue;
  6066. }
  6067. switch (level)
  6068. {
  6069. case 0:
  6070. words = input[idx].Split(' '); // Linden text ver
  6071. int version = int.Parse(words[3]);
  6072. if (version != 2)
  6073. return new String[0];
  6074. break;
  6075. case 1:
  6076. words = input[idx].Split(' ');
  6077. if (words[0] == "LLEmbeddedItems")
  6078. break;
  6079. if (words[0] == "Text")
  6080. {
  6081. int len = int.Parse(words[2]);
  6082. idx++;
  6083. int count = -1;
  6084. while (count < len)
  6085. {
  6086. // int l = input[idx].Length;
  6087. string ln = input[idx];
  6088. int need = len-count-1;
  6089. if (ln.Length > need)
  6090. ln = ln.Substring(0, need);
  6091. output.Add(ln);
  6092. count += ln.Length + 1;
  6093. idx++;
  6094. }
  6095. return output.ToArray();
  6096. }
  6097. break;
  6098. case 2:
  6099. words = input[idx].Split(' '); // count
  6100. if (words[0] == "count")
  6101. {
  6102. int c = int.Parse(words[1]);
  6103. if (c > 0)
  6104. return new String[0];
  6105. break;
  6106. }
  6107. break;
  6108. }
  6109. idx++;
  6110. }
  6111. return output.ToArray();
  6112. }
  6113. public static bool IsCached(LLUUID assetID)
  6114. {
  6115. lock (m_Notecards)
  6116. {
  6117. return m_Notecards.ContainsKey(assetID);
  6118. }
  6119. }
  6120. public static int GetLines(LLUUID assetID)
  6121. {
  6122. if (!IsCached(assetID))
  6123. return -1;
  6124. lock (m_Notecards)
  6125. {
  6126. m_Notecards[assetID].lastRef = DateTime.Now;
  6127. return m_Notecards[assetID].text.Length;
  6128. }
  6129. }
  6130. public static string GetLine(LLUUID assetID, int line)
  6131. {
  6132. if (line < 0)
  6133. return "";
  6134. string data;
  6135. if (!IsCached(assetID))
  6136. return "";
  6137. lock (m_Notecards)
  6138. {
  6139. m_Notecards[assetID].lastRef = DateTime.Now;
  6140. if (line >= m_Notecards[assetID].text.Length)
  6141. return "\n\n\n";
  6142. data = m_Notecards[assetID].text[line];
  6143. if (data.Length > 255)
  6144. data = data.Substring(0, 255);
  6145. return data;
  6146. }
  6147. }
  6148. public static void CacheCheck()
  6149. {
  6150. foreach (LLUUID key in new List<LLUUID>(m_Notecards.Keys))
  6151. {
  6152. Notecard nc = m_Notecards[key];
  6153. if (nc.lastRef.AddSeconds(30) < DateTime.Now)
  6154. m_Notecards.Remove(key);
  6155. }
  6156. }
  6157. }
  6158. }