LSL_Api.cs 458 KB

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