LSL_Api.cs 325 KB

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