LSL_Api.cs 459 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617961896199620962196229623962496259626962796289629963096319632963396349635963696379638963996409641964296439644964596469647964896499650965196529653965496559656965796589659966096619662966396649665966696679668966996709671967296739674967596769677967896799680968196829683968496859686968796889689969096919692969396949695969696979698969997009701970297039704970597069707970897099710971197129713971497159716971797189719972097219722972397249725972697279728972997309731973297339734973597369737973897399740974197429743974497459746974797489749975097519752975397549755975697579758975997609761976297639764976597669767976897699770977197729773977497759776977797789779978097819782978397849785978697879788978997909791979297939794979597969797979897999800980198029803980498059806980798089809981098119812981398149815981698179818981998209821982298239824982598269827982898299830983198329833983498359836983798389839984098419842984398449845984698479848984998509851985298539854985598569857985898599860986198629863986498659866986798689869987098719872987398749875987698779878987998809881988298839884988598869887988898899890989198929893989498959896989798989899990099019902990399049905990699079908990999109911991299139914991599169917991899199920992199229923992499259926992799289929993099319932993399349935993699379938993999409941994299439944994599469947994899499950995199529953995499559956995799589959996099619962996399649965996699679968996999709971997299739974997599769977997899799980998199829983998499859986998799889989999099919992999399949995999699979998999910000100011000210003100041000510006100071000810009100101001110012100131001410015100161001710018100191002010021100221002310024100251002610027100281002910030100311003210033100341003510036100371003810039100401004110042100431004410045100461004710048100491005010051100521005310054100551005610057100581005910060100611006210063100641006510066100671006810069100701007110072100731007410075100761007710078100791008010081100821008310084100851008610087100881008910090100911009210093100941009510096100971009810099101001010110102101031010410105101061010710108101091011010111101121011310114101151011610117101181011910120101211012210123101241012510126101271012810129101301013110132101331013410135101361013710138101391014010141101421014310144101451014610147101481014910150101511015210153101541015510156101571015810159101601016110162101631016410165101661016710168101691017010171101721017310174101751017610177101781017910180101811018210183101841018510186101871018810189101901019110192101931019410195101961019710198101991020010201102021020310204102051020610207102081020910210102111021210213102141021510216102171021810219102201022110222102231022410225102261022710228102291023010231102321023310234102351023610237102381023910240102411024210243102441024510246102471024810249102501025110252102531025410255102561025710258102591026010261102621026310264102651026610267102681026910270102711027210273102741027510276102771027810279102801028110282102831028410285102861028710288102891029010291102921029310294102951029610297102981029910300103011030210303103041030510306103071030810309103101031110312103131031410315103161031710318103191032010321103221032310324103251032610327103281032910330103311033210333103341033510336103371033810339103401034110342103431034410345103461034710348103491035010351103521035310354103551035610357103581035910360103611036210363103641036510366103671036810369103701037110372103731037410375103761037710378103791038010381103821038310384103851038610387103881038910390103911039210393103941039510396103971039810399104001040110402104031040410405104061040710408104091041010411104121041310414104151041610417104181041910420104211042210423104241042510426104271042810429104301043110432104331043410435104361043710438104391044010441104421044310444104451044610447104481044910450104511045210453104541045510456104571045810459104601046110462104631046410465104661046710468104691047010471104721047310474104751047610477104781047910480104811048210483104841048510486104871048810489104901049110492104931049410495104961049710498104991050010501105021050310504105051050610507105081050910510105111051210513105141051510516105171051810519105201052110522105231052410525105261052710528105291053010531105321053310534105351053610537105381053910540105411054210543105441054510546105471054810549105501055110552105531055410555105561055710558105591056010561105621056310564105651056610567105681056910570105711057210573105741057510576105771057810579105801058110582105831058410585105861058710588105891059010591105921059310594105951059610597105981059910600106011060210603106041060510606106071060810609106101061110612106131061410615106161061710618106191062010621106221062310624106251062610627106281062910630106311063210633106341063510636106371063810639106401064110642106431064410645106461064710648106491065010651106521065310654106551065610657106581065910660106611066210663106641066510666106671066810669106701067110672106731067410675106761067710678106791068010681106821068310684106851068610687106881068910690106911069210693106941069510696106971069810699107001070110702107031070410705107061070710708107091071010711107121071310714107151071610717107181071910720107211072210723107241072510726107271072810729107301073110732107331073410735107361073710738107391074010741107421074310744107451074610747107481074910750107511075210753107541075510756107571075810759107601076110762107631076410765107661076710768107691077010771107721077310774107751077610777107781077910780107811078210783107841078510786107871078810789107901079110792107931079410795107961079710798107991080010801108021080310804108051080610807108081080910810108111081210813108141081510816108171081810819108201082110822108231082410825108261082710828108291083010831108321083310834108351083610837108381083910840108411084210843108441084510846108471084810849108501085110852108531085410855108561085710858108591086010861108621086310864108651086610867108681086910870108711087210873108741087510876108771087810879108801088110882108831088410885108861088710888108891089010891108921089310894108951089610897108981089910900109011090210903109041090510906109071090810909109101091110912109131091410915109161091710918109191092010921109221092310924109251092610927109281092910930109311093210933109341093510936109371093810939109401094110942109431094410945109461094710948109491095010951109521095310954109551095610957109581095910960109611096210963109641096510966109671096810969109701097110972109731097410975109761097710978109791098010981109821098310984109851098610987109881098910990109911099210993109941099510996109971099810999110001100111002110031100411005110061100711008110091101011011110121101311014110151101611017110181101911020110211102211023110241102511026110271102811029110301103111032110331103411035110361103711038110391104011041110421104311044110451104611047110481104911050110511105211053110541105511056110571105811059110601106111062110631106411065110661106711068110691107011071110721107311074110751107611077110781107911080110811108211083110841108511086110871108811089110901109111092110931109411095110961109711098110991110011101111021110311104111051110611107111081110911110111111111211113111141111511116111171111811119111201112111122111231112411125111261112711128111291113011131111321113311134111351113611137111381113911140111411114211143111441114511146111471114811149111501115111152111531115411155111561115711158111591116011161111621116311164111651116611167111681116911170111711117211173111741117511176111771117811179111801118111182111831118411185111861118711188111891119011191111921119311194111951119611197111981119911200112011120211203112041120511206112071120811209112101121111212112131121411215112161121711218112191122011221112221122311224112251122611227112281122911230112311123211233112341123511236112371123811239112401124111242112431124411245112461124711248112491125011251112521125311254112551125611257112581125911260112611126211263112641126511266112671126811269112701127111272112731127411275112761127711278112791128011281112821128311284112851128611287112881128911290112911129211293112941129511296112971129811299113001130111302113031130411305113061130711308113091131011311113121131311314113151131611317113181131911320113211132211323113241132511326113271132811329113301133111332113331133411335113361133711338113391134011341113421134311344113451134611347113481134911350113511135211353113541135511356113571135811359113601136111362113631136411365113661136711368113691137011371113721137311374113751137611377113781137911380113811138211383113841138511386113871138811389113901139111392113931139411395113961139711398113991140011401114021140311404114051140611407114081140911410114111141211413114141141511416114171141811419114201142111422114231142411425114261142711428114291143011431114321143311434114351143611437114381143911440114411144211443114441144511446114471144811449114501145111452114531145411455114561145711458114591146011461114621146311464114651146611467114681146911470114711147211473114741147511476114771147811479114801148111482114831148411485114861148711488114891149011491114921149311494114951149611497114981149911500115011150211503115041150511506115071150811509115101151111512115131151411515115161151711518115191152011521115221152311524115251152611527115281152911530115311153211533115341153511536115371153811539115401154111542115431154411545115461154711548115491155011551115521155311554115551155611557115581155911560115611156211563115641156511566115671156811569115701157111572115731157411575115761157711578115791158011581115821158311584115851158611587115881158911590115911159211593115941159511596115971159811599116001160111602116031160411605116061160711608116091161011611116121161311614116151161611617116181161911620116211162211623116241162511626116271162811629116301163111632116331163411635116361163711638116391164011641116421164311644116451164611647116481164911650116511165211653116541165511656116571165811659116601166111662116631166411665116661166711668116691167011671116721167311674116751167611677116781167911680116811168211683116841168511686116871168811689116901169111692116931169411695116961169711698116991170011701117021170311704117051170611707117081170911710117111171211713117141171511716117171171811719117201172111722117231172411725117261172711728117291173011731117321173311734117351173611737117381173911740117411174211743117441174511746117471174811749117501175111752117531175411755117561175711758117591176011761117621176311764117651176611767117681176911770117711177211773117741177511776117771177811779117801178111782117831178411785117861178711788117891179011791117921179311794117951179611797117981179911800118011180211803118041180511806118071180811809118101181111812118131181411815118161181711818118191182011821118221182311824118251182611827118281182911830118311183211833118341183511836118371183811839118401184111842118431184411845118461184711848118491185011851118521185311854118551185611857118581185911860118611186211863118641186511866118671186811869118701187111872118731187411875118761187711878118791188011881118821188311884118851188611887118881188911890118911189211893118941189511896118971189811899119001190111902119031190411905119061190711908119091191011911119121191311914119151191611917119181191911920119211192211923119241192511926119271192811929119301193111932119331193411935119361193711938119391194011941119421194311944119451194611947119481194911950119511195211953119541195511956119571195811959119601196111962119631196411965119661196711968119691197011971119721197311974119751197611977119781197911980119811198211983119841198511986119871198811989119901199111992119931199411995119961199711998119991200012001120021200312004120051200612007120081200912010120111201212013120141201512016120171201812019120201202112022120231202412025120261202712028120291203012031120321203312034120351203612037120381203912040120411204212043120441204512046120471204812049120501205112052120531205412055120561205712058120591206012061120621206312064120651206612067120681206912070120711207212073120741207512076120771207812079120801208112082120831208412085120861208712088120891209012091120921209312094120951209612097120981209912100121011210212103121041210512106121071210812109121101211112112121131211412115121161211712118121191212012121121221212312124121251212612127121281212912130121311213212133121341213512136121371213812139121401214112142121431214412145121461214712148121491215012151121521215312154121551215612157121581215912160121611216212163121641216512166121671216812169121701217112172121731217412175121761217712178121791218012181121821218312184121851218612187121881218912190121911219212193121941219512196121971219812199122001220112202122031220412205122061220712208122091221012211122121221312214122151221612217122181221912220122211222212223122241222512226122271222812229122301223112232122331223412235122361223712238122391224012241122421224312244122451224612247122481224912250122511225212253122541225512256122571225812259122601226112262122631226412265122661226712268122691227012271122721227312274122751227612277122781227912280122811228212283122841228512286122871228812289122901229112292122931229412295122961229712298122991230012301123021230312304123051230612307123081230912310
  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 = false;
  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. Error("llResetOtherScript", "Can't find script '" + name + "'");
  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. Error("llGetScriptState", "Can't find script '" + name + "'");
  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. Error("llSetScriptState", "Can't find script '" + name + "'");
  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. Error("llRegionSay", "Cannot use 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. Deprecated("llSound", "Use llPlaySound instead");
  2213. }
  2214. // Xantor 20080528 PlaySound updated so it accepts an objectinventory name -or- a key to a sound
  2215. // 20080530 Updated to remove code duplication
  2216. public void llPlaySound(string sound, double volume)
  2217. {
  2218. m_host.AddScriptLPS(1);
  2219. // send the sound, once, to all clients in range
  2220. if (m_SoundModule != null)
  2221. {
  2222. m_SoundModule.SendSound(
  2223. m_host.UUID,
  2224. ScriptUtils.GetAssetIdFromKeyOrItemName(m_host, sound, AssetType.Sound),
  2225. volume, false, m_host.SoundQueueing ? (byte)SoundFlags.Queue : (byte)SoundFlags.None,
  2226. 0, false, false);
  2227. }
  2228. }
  2229. public void llLoopSound(string sound, double volume)
  2230. {
  2231. m_host.AddScriptLPS(1);
  2232. if (m_SoundModule != null)
  2233. {
  2234. m_SoundModule.LoopSound(m_host.UUID, ScriptUtils.GetAssetIdFromKeyOrItemName(m_host, sound),
  2235. volume, 20, false);
  2236. }
  2237. }
  2238. public void llLoopSoundMaster(string sound, double volume)
  2239. {
  2240. m_host.AddScriptLPS(1);
  2241. if (m_SoundModule != null)
  2242. {
  2243. m_SoundModule.LoopSound(m_host.UUID, ScriptUtils.GetAssetIdFromKeyOrItemName(m_host, sound),
  2244. volume, 20, true);
  2245. }
  2246. }
  2247. public void llLoopSoundSlave(string sound, double volume)
  2248. {
  2249. m_host.AddScriptLPS(1);
  2250. lock (m_host.ParentGroup.LoopSoundSlavePrims)
  2251. {
  2252. m_host.ParentGroup.LoopSoundSlavePrims.Add(m_host);
  2253. }
  2254. }
  2255. public void llPlaySoundSlave(string sound, double volume)
  2256. {
  2257. m_host.AddScriptLPS(1);
  2258. // send the sound, once, to all clients in range
  2259. if (m_SoundModule != null)
  2260. {
  2261. m_SoundModule.SendSound(m_host.UUID,
  2262. ScriptUtils.GetAssetIdFromKeyOrItemName(m_host, sound, AssetType.Sound), volume, false, 0,
  2263. 0, true, false);
  2264. }
  2265. }
  2266. public void llTriggerSound(string sound, double volume)
  2267. {
  2268. m_host.AddScriptLPS(1);
  2269. // send the sound, once, to all clients in rangeTrigger or play an attached sound in this part's inventory.
  2270. if (m_SoundModule != null)
  2271. {
  2272. m_SoundModule.SendSound(m_host.UUID,
  2273. ScriptUtils.GetAssetIdFromKeyOrItemName(m_host, sound, AssetType.Sound), volume, true, 0, 0,
  2274. false, false);
  2275. }
  2276. }
  2277. public void llStopSound()
  2278. {
  2279. m_host.AddScriptLPS(1);
  2280. if (m_SoundModule != null)
  2281. m_SoundModule.StopSound(m_host.UUID);
  2282. }
  2283. public void llPreloadSound(string sound)
  2284. {
  2285. m_host.AddScriptLPS(1);
  2286. if (m_SoundModule != null)
  2287. m_SoundModule.PreloadSound(m_host.UUID, ScriptUtils.GetAssetIdFromKeyOrItemName(m_host, sound), 0);
  2288. ScriptSleep(1000);
  2289. }
  2290. /// <summary>
  2291. /// Return a portion of the designated string bounded by
  2292. /// inclusive indices (start and end). As usual, the negative
  2293. /// indices, and the tolerance for out-of-bound values, makes
  2294. /// this more complicated than it might otherwise seem.
  2295. /// </summary>
  2296. public LSL_String llGetSubString(string src, int start, int end)
  2297. {
  2298. m_host.AddScriptLPS(1);
  2299. // Normalize indices (if negative).
  2300. // After normlaization they may still be
  2301. // negative, but that is now relative to
  2302. // the start, rather than the end, of the
  2303. // sequence.
  2304. if (start < 0)
  2305. {
  2306. start = src.Length+start;
  2307. }
  2308. if (end < 0)
  2309. {
  2310. end = src.Length+end;
  2311. }
  2312. // Conventional substring
  2313. if (start <= end)
  2314. {
  2315. // Implies both bounds are out-of-range.
  2316. if (end < 0 || start >= src.Length)
  2317. {
  2318. return String.Empty;
  2319. }
  2320. // If end is positive, then it directly
  2321. // corresponds to the lengt of the substring
  2322. // needed (plus one of course). BUT, it
  2323. // must be within bounds.
  2324. if (end >= src.Length)
  2325. {
  2326. end = src.Length-1;
  2327. }
  2328. if (start < 0)
  2329. {
  2330. return src.Substring(0,end+1);
  2331. }
  2332. // Both indices are positive
  2333. return src.Substring(start, (end+1) - start);
  2334. }
  2335. // Inverted substring (end < start)
  2336. else
  2337. {
  2338. // Implies both indices are below the
  2339. // lower bound. In the inverted case, that
  2340. // means the entire string will be returned
  2341. // unchanged.
  2342. if (start < 0)
  2343. {
  2344. return src;
  2345. }
  2346. // If both indices are greater than the upper
  2347. // bound the result may seem initially counter
  2348. // intuitive.
  2349. if (end >= src.Length)
  2350. {
  2351. return src;
  2352. }
  2353. if (end < 0)
  2354. {
  2355. if (start < src.Length)
  2356. {
  2357. return src.Substring(start);
  2358. }
  2359. else
  2360. {
  2361. return String.Empty;
  2362. }
  2363. }
  2364. else
  2365. {
  2366. if (start < src.Length)
  2367. {
  2368. return src.Substring(0,end+1) + src.Substring(start);
  2369. }
  2370. else
  2371. {
  2372. return src.Substring(0,end+1);
  2373. }
  2374. }
  2375. }
  2376. }
  2377. /// <summary>
  2378. /// Delete substring removes the specified substring bounded
  2379. /// by the inclusive indices start and end. Indices may be
  2380. /// negative (indicating end-relative) and may be inverted,
  2381. /// i.e. end < start.
  2382. /// </summary>
  2383. public LSL_String llDeleteSubString(string src, int start, int end)
  2384. {
  2385. m_host.AddScriptLPS(1);
  2386. // Normalize indices (if negative).
  2387. // After normlaization they may still be
  2388. // negative, but that is now relative to
  2389. // the start, rather than the end, of the
  2390. // sequence.
  2391. if (start < 0)
  2392. {
  2393. start = src.Length+start;
  2394. }
  2395. if (end < 0)
  2396. {
  2397. end = src.Length+end;
  2398. }
  2399. // Conventionally delimited substring
  2400. if (start <= end)
  2401. {
  2402. // If both bounds are outside of the existing
  2403. // string, then return unchanges.
  2404. if (end < 0 || start >= src.Length)
  2405. {
  2406. return src;
  2407. }
  2408. // At least one bound is in-range, so we
  2409. // need to clip the out-of-bound argument.
  2410. if (start < 0)
  2411. {
  2412. start = 0;
  2413. }
  2414. if (end >= src.Length)
  2415. {
  2416. end = src.Length-1;
  2417. }
  2418. return src.Remove(start,end-start+1);
  2419. }
  2420. // Inverted substring
  2421. else
  2422. {
  2423. // In this case, out of bounds means that
  2424. // the existing string is part of the cut.
  2425. if (start < 0 || end >= src.Length)
  2426. {
  2427. return String.Empty;
  2428. }
  2429. if (end > 0)
  2430. {
  2431. if (start < src.Length)
  2432. {
  2433. return src.Remove(start).Remove(0,end+1);
  2434. }
  2435. else
  2436. {
  2437. return src.Remove(0,end+1);
  2438. }
  2439. }
  2440. else
  2441. {
  2442. if (start < src.Length)
  2443. {
  2444. return src.Remove(start);
  2445. }
  2446. else
  2447. {
  2448. return src;
  2449. }
  2450. }
  2451. }
  2452. }
  2453. /// <summary>
  2454. /// Insert string inserts the specified string identified by src
  2455. /// at the index indicated by index. Index may be negative, in
  2456. /// which case it is end-relative. The index may exceed either
  2457. /// string bound, with the result being a concatenation.
  2458. /// </summary>
  2459. public LSL_String llInsertString(string dest, int index, string src)
  2460. {
  2461. m_host.AddScriptLPS(1);
  2462. // Normalize indices (if negative).
  2463. // After normlaization they may still be
  2464. // negative, but that is now relative to
  2465. // the start, rather than the end, of the
  2466. // sequence.
  2467. if (index < 0)
  2468. {
  2469. index = dest.Length+index;
  2470. // Negative now means it is less than the lower
  2471. // bound of the string.
  2472. if (index < 0)
  2473. {
  2474. return src+dest;
  2475. }
  2476. }
  2477. if (index >= dest.Length)
  2478. {
  2479. return dest+src;
  2480. }
  2481. // The index is in bounds.
  2482. // In this case the index refers to the index that will
  2483. // be assigned to the first character of the inserted string.
  2484. // So unlike the other string operations, we do not add one
  2485. // to get the correct string length.
  2486. return dest.Substring(0,index)+src+dest.Substring(index);
  2487. }
  2488. public LSL_String llToUpper(string src)
  2489. {
  2490. m_host.AddScriptLPS(1);
  2491. return src.ToUpper();
  2492. }
  2493. public LSL_String llToLower(string src)
  2494. {
  2495. m_host.AddScriptLPS(1);
  2496. return src.ToLower();
  2497. }
  2498. public void llGiveMoney(string destination, int amount)
  2499. {
  2500. Util.FireAndForget(x =>
  2501. {
  2502. m_host.AddScriptLPS(1);
  2503. if (m_item.PermsGranter == UUID.Zero)
  2504. return;
  2505. if ((m_item.PermsMask & ScriptBaseClass.PERMISSION_DEBIT) == 0)
  2506. {
  2507. Error("llGiveMoney", "No permissions to give money");
  2508. return;
  2509. }
  2510. UUID toID = new UUID();
  2511. if (!UUID.TryParse(destination, out toID))
  2512. {
  2513. Error("llGiveMoney", "Bad key in llGiveMoney");
  2514. return;
  2515. }
  2516. IMoneyModule money = World.RequestModuleInterface<IMoneyModule>();
  2517. if (money == null)
  2518. {
  2519. NotImplemented("llGiveMoney");
  2520. return;
  2521. }
  2522. money.ObjectGiveMoney(
  2523. m_host.ParentGroup.RootPart.UUID, m_host.ParentGroup.RootPart.OwnerID, toID, amount);
  2524. });
  2525. }
  2526. public void llMakeExplosion(int particles, double scale, double vel, double lifetime, double arc, string texture, LSL_Vector offset)
  2527. {
  2528. m_host.AddScriptLPS(1);
  2529. Deprecated("llMakeExplosion", "Use llParticleSystem instead");
  2530. ScriptSleep(100);
  2531. }
  2532. public void llMakeFountain(int particles, double scale, double vel, double lifetime, double arc, int bounce, string texture, LSL_Vector offset, double bounce_offset)
  2533. {
  2534. m_host.AddScriptLPS(1);
  2535. Deprecated("llMakeFountain", "Use llParticleSystem instead");
  2536. ScriptSleep(100);
  2537. }
  2538. public void llMakeSmoke(int particles, double scale, double vel, double lifetime, double arc, string texture, LSL_Vector offset)
  2539. {
  2540. m_host.AddScriptLPS(1);
  2541. Deprecated("llMakeSmoke", "Use llParticleSystem instead");
  2542. ScriptSleep(100);
  2543. }
  2544. public void llMakeFire(int particles, double scale, double vel, double lifetime, double arc, string texture, LSL_Vector offset)
  2545. {
  2546. m_host.AddScriptLPS(1);
  2547. Deprecated("llMakeFire", "Use llParticleSystem instead");
  2548. ScriptSleep(100);
  2549. }
  2550. public void llRezAtRoot(string inventory, LSL_Vector pos, LSL_Vector vel, LSL_Rotation rot, int param)
  2551. {
  2552. m_host.AddScriptLPS(1);
  2553. Util.FireAndForget(x =>
  2554. {
  2555. if (Double.IsNaN(rot.x) || Double.IsNaN(rot.y) || Double.IsNaN(rot.z) || Double.IsNaN(rot.s))
  2556. return;
  2557. float dist = (float)llVecDist(llGetPos(), pos);
  2558. if (dist > m_ScriptDistanceFactor * 10.0f)
  2559. return;
  2560. TaskInventoryItem item = m_host.Inventory.GetInventoryItem(inventory);
  2561. if (item == null)
  2562. {
  2563. Error("llRezAtRoot", "Can't find object '" + inventory + "'");
  2564. return;
  2565. }
  2566. if (item.InvType != (int)InventoryType.Object)
  2567. {
  2568. Error("llRezAtRoot", "Can't create requested object; object is missing from database");
  2569. return;
  2570. }
  2571. // need the magnitude later
  2572. // float velmag = (float)Util.GetMagnitude(llvel);
  2573. List<SceneObjectGroup> new_groups = World.RezObject(m_host, item, pos, rot, vel, param);
  2574. // If either of these are null, then there was an unknown error.
  2575. if (new_groups == null)
  2576. return;
  2577. foreach (SceneObjectGroup group in new_groups)
  2578. {
  2579. // objects rezzed with this method are die_at_edge by default.
  2580. group.RootPart.SetDieAtEdge(true);
  2581. group.ResumeScripts();
  2582. m_ScriptEngine.PostObjectEvent(m_host.LocalId, new EventParams(
  2583. "object_rez", new Object[] {
  2584. new LSL_String(
  2585. group.RootPart.UUID.ToString()) },
  2586. new DetectParams[0]));
  2587. float groupmass = group.GetMass();
  2588. PhysicsActor pa = group.RootPart.PhysActor;
  2589. //Recoil.
  2590. if (pa != null && pa.IsPhysical && (Vector3)vel != Vector3.Zero)
  2591. {
  2592. Vector3 recoil = -vel * groupmass * m_recoilScaleFactor;
  2593. if (recoil != Vector3.Zero)
  2594. {
  2595. llApplyImpulse(recoil, 0);
  2596. }
  2597. }
  2598. // Variable script delay? (see (http://wiki.secondlife.com/wiki/LSL_Delay)
  2599. }
  2600. });
  2601. //ScriptSleep((int)((groupmass * velmag) / 10));
  2602. ScriptSleep(100);
  2603. }
  2604. public void llRezObject(string inventory, LSL_Vector pos, LSL_Vector vel, LSL_Rotation rot, int param)
  2605. {
  2606. llRezAtRoot(inventory, pos, vel, rot, param);
  2607. }
  2608. public void llLookAt(LSL_Vector target, double strength, double damping)
  2609. {
  2610. m_host.AddScriptLPS(1);
  2611. // Determine where we are looking from
  2612. LSL_Vector from = llGetPos();
  2613. // Work out the normalised vector from the source to the target
  2614. LSL_Vector delta = llVecNorm(target - from);
  2615. LSL_Vector angle = new LSL_Vector(0,0,0);
  2616. // Calculate the yaw
  2617. // subtracting PI_BY_TWO is required to compensate for the odd SL co-ordinate system
  2618. angle.x = llAtan2(delta.z, delta.y) - ScriptBaseClass.PI_BY_TWO;
  2619. // Calculate pitch
  2620. angle.y = llAtan2(delta.x, llSqrt((delta.y * delta.y) + (delta.z * delta.z)));
  2621. // we need to convert from a vector describing
  2622. // the angles of rotation in radians into rotation value
  2623. LSL_Rotation rot = llEuler2Rot(angle);
  2624. // Per discussion with Melanie, for non-physical objects llLookAt appears to simply
  2625. // set the rotation of the object, copy that behavior
  2626. PhysicsActor pa = m_host.PhysActor;
  2627. if (strength == 0 || pa == null || !pa.IsPhysical)
  2628. {
  2629. llSetRot(rot);
  2630. }
  2631. else
  2632. {
  2633. m_host.StartLookAt(rot, (float)strength, (float)damping);
  2634. }
  2635. }
  2636. public void llStopLookAt()
  2637. {
  2638. m_host.AddScriptLPS(1);
  2639. m_host.StopLookAt();
  2640. }
  2641. public void llSetTimerEvent(double sec)
  2642. {
  2643. if (sec != 0.0 && sec < m_MinTimerInterval)
  2644. sec = m_MinTimerInterval;
  2645. m_host.AddScriptLPS(1);
  2646. // Setting timer repeat
  2647. AsyncCommands.TimerPlugin.SetTimerEvent(m_host.LocalId, m_item.ItemID, sec);
  2648. }
  2649. public virtual void llSleep(double sec)
  2650. {
  2651. // m_log.Info("llSleep snoozing " + sec + "s.");
  2652. m_host.AddScriptLPS(1);
  2653. Sleep((int)(sec * 1000));
  2654. }
  2655. public LSL_Float llGetMass()
  2656. {
  2657. m_host.AddScriptLPS(1);
  2658. if (m_host.ParentGroup.IsAttachment)
  2659. {
  2660. ScenePresence attachedAvatar = World.GetScenePresence(m_host.ParentGroup.AttachedAvatar);
  2661. if (attachedAvatar != null)
  2662. {
  2663. return attachedAvatar.GetMass();
  2664. }
  2665. else
  2666. {
  2667. return 0;
  2668. }
  2669. }
  2670. else
  2671. {
  2672. if (m_host.IsRoot)
  2673. {
  2674. return m_host.ParentGroup.GetMass();
  2675. }
  2676. else
  2677. {
  2678. return m_host.GetMass();
  2679. }
  2680. }
  2681. }
  2682. public void llCollisionFilter(string name, string id, int accept)
  2683. {
  2684. m_host.AddScriptLPS(1);
  2685. m_host.CollisionFilter.Clear();
  2686. UUID objectID;
  2687. if (!UUID.TryParse(id, out objectID))
  2688. objectID = UUID.Zero;
  2689. if (objectID == UUID.Zero && name == "")
  2690. return;
  2691. m_host.CollisionFilter.Add(accept,objectID.ToString() + name);
  2692. }
  2693. public void llTakeControls(int controls, int accept, int pass_on)
  2694. {
  2695. if (m_item.PermsGranter != UUID.Zero)
  2696. {
  2697. ScenePresence presence = World.GetScenePresence(m_item.PermsGranter);
  2698. if (presence != null)
  2699. {
  2700. if ((m_item.PermsMask & ScriptBaseClass.PERMISSION_TAKE_CONTROLS) != 0)
  2701. {
  2702. presence.RegisterControlEventsToScript(controls, accept, pass_on, m_host.LocalId, m_item.ItemID);
  2703. }
  2704. }
  2705. }
  2706. m_host.AddScriptLPS(1);
  2707. }
  2708. public void llReleaseControls()
  2709. {
  2710. m_host.AddScriptLPS(1);
  2711. if (m_item.PermsGranter != UUID.Zero)
  2712. {
  2713. ScenePresence presence = World.GetScenePresence(m_item.PermsGranter);
  2714. if (presence != null)
  2715. {
  2716. if ((m_item.PermsMask & ScriptBaseClass.PERMISSION_TAKE_CONTROLS) != 0)
  2717. {
  2718. // Unregister controls from Presence
  2719. presence.UnRegisterControlEventsToScript(m_host.LocalId, m_item.ItemID);
  2720. // Remove Take Control permission.
  2721. m_item.PermsMask &= ~ScriptBaseClass.PERMISSION_TAKE_CONTROLS;
  2722. }
  2723. }
  2724. }
  2725. }
  2726. public void llReleaseURL(string url)
  2727. {
  2728. m_host.AddScriptLPS(1);
  2729. if (m_UrlModule != null)
  2730. m_UrlModule.ReleaseURL(url);
  2731. }
  2732. /// <summary>
  2733. /// Attach the object containing this script to the avatar that owns it.
  2734. /// </summary>
  2735. /// <param name='attachmentPoint'>
  2736. /// The attachment point (e.g. <see cref="OpenSim.Region.ScriptEngine.Shared.ScriptBase.ScriptBaseClass.ATTACH_CHEST">ATTACH_CHEST</see>)
  2737. /// </param>
  2738. /// <returns>true if the attach suceeded, false if it did not</returns>
  2739. public bool AttachToAvatar(int attachmentPoint)
  2740. {
  2741. SceneObjectGroup grp = m_host.ParentGroup;
  2742. ScenePresence presence = World.GetScenePresence(m_host.OwnerID);
  2743. IAttachmentsModule attachmentsModule = m_ScriptEngine.World.AttachmentsModule;
  2744. if (attachmentsModule != null)
  2745. return attachmentsModule.AttachObject(presence, grp, (uint)attachmentPoint, false, true, true);
  2746. else
  2747. return false;
  2748. }
  2749. /// <summary>
  2750. /// Detach the object containing this script from the avatar it is attached to.
  2751. /// </summary>
  2752. /// <remarks>
  2753. /// Nothing happens if the object is not attached.
  2754. /// </remarks>
  2755. public void DetachFromAvatar()
  2756. {
  2757. Util.FireAndForget(DetachWrapper, m_host);
  2758. }
  2759. private void DetachWrapper(object o)
  2760. {
  2761. if (World.AttachmentsModule != null)
  2762. {
  2763. SceneObjectPart host = (SceneObjectPart)o;
  2764. ScenePresence presence = World.GetScenePresence(host.OwnerID);
  2765. World.AttachmentsModule.DetachSingleAttachmentToInv(presence, host.ParentGroup);
  2766. }
  2767. }
  2768. public void llAttachToAvatar(int attachmentPoint)
  2769. {
  2770. m_host.AddScriptLPS(1);
  2771. // if (m_host.ParentGroup.RootPart.AttachmentPoint == 0)
  2772. // return;
  2773. if (m_item.PermsGranter != m_host.OwnerID)
  2774. return;
  2775. if ((m_item.PermsMask & ScriptBaseClass.PERMISSION_ATTACH) != 0)
  2776. AttachToAvatar(attachmentPoint);
  2777. }
  2778. public void llDetachFromAvatar()
  2779. {
  2780. m_host.AddScriptLPS(1);
  2781. if (m_host.ParentGroup.AttachmentPoint == 0)
  2782. return;
  2783. if (m_item.PermsGranter != m_host.OwnerID)
  2784. return;
  2785. if ((m_item.PermsMask & ScriptBaseClass.PERMISSION_ATTACH) != 0)
  2786. DetachFromAvatar();
  2787. }
  2788. public void llTakeCamera(string avatar)
  2789. {
  2790. m_host.AddScriptLPS(1);
  2791. Deprecated("llTakeCamera", "Use llSetCameraParams instead");
  2792. }
  2793. public void llReleaseCamera(string avatar)
  2794. {
  2795. m_host.AddScriptLPS(1);
  2796. Deprecated("llReleaseCamera", "Use llClearCameraParams instead");
  2797. }
  2798. public LSL_String llGetOwner()
  2799. {
  2800. m_host.AddScriptLPS(1);
  2801. return m_host.OwnerID.ToString();
  2802. }
  2803. public void llInstantMessage(string user, string message)
  2804. {
  2805. m_host.AddScriptLPS(1);
  2806. // We may be able to use ClientView.SendInstantMessage here, but we need a client instance.
  2807. // InstantMessageModule.OnInstantMessage searches through a list of scenes for a client matching the toAgent,
  2808. // but I don't think we have a list of scenes available from here.
  2809. // (We also don't want to duplicate the code in OnInstantMessage if we can avoid it.)
  2810. // user is a UUID
  2811. // TODO: figure out values for client, fromSession, and imSessionID
  2812. // client.SendInstantMessage(m_host.UUID, fromSession, message, user, imSessionID, m_host.Name, AgentManager.InstantMessageDialog.MessageFromAgent, (uint)Util.UnixTimeSinceEpoch());
  2813. UUID friendTransactionID = UUID.Random();
  2814. //m_pendingFriendRequests.Add(friendTransactionID, fromAgentID);
  2815. GridInstantMessage msg = new GridInstantMessage();
  2816. msg.fromAgentID = new Guid(m_host.UUID.ToString()); // fromAgentID.Guid;
  2817. msg.toAgentID = new Guid(user); // toAgentID.Guid;
  2818. msg.imSessionID = new Guid(friendTransactionID.ToString()); // This is the item we're mucking with here
  2819. // m_log.Debug("[Scripting IM]: From:" + msg.fromAgentID.ToString() + " To: " + msg.toAgentID.ToString() + " Session:" + msg.imSessionID.ToString() + " Message:" + message);
  2820. // m_log.Debug("[Scripting IM]: Filling Session: " + msg.imSessionID.ToString());
  2821. msg.timestamp = (uint)Util.UnixTimeSinceEpoch();// timestamp;
  2822. //if (client != null)
  2823. //{
  2824. msg.fromAgentName = m_host.Name;//client.FirstName + " " + client.LastName;// fromAgentName;
  2825. //}
  2826. //else
  2827. //{
  2828. // msg.fromAgentName = "(hippos)";// Added for posterity. This means that we can't figure out who sent it
  2829. //}
  2830. // Cap the message length at 1024.
  2831. if (message != null && message.Length > 1024)
  2832. msg.message = message.Substring(0, 1024);
  2833. else
  2834. msg.message = message;
  2835. msg.dialog = (byte)19; // messgage from script ??? // dialog;
  2836. msg.fromGroup = false;// fromGroup;
  2837. msg.offline = (byte)0; //offline;
  2838. msg.ParentEstateID = 0; //ParentEstateID;
  2839. msg.Position = new Vector3(m_host.AbsolutePosition);
  2840. msg.RegionID = World.RegionInfo.RegionID.Guid;//RegionID.Guid;
  2841. Vector3 pos = m_host.AbsolutePosition;
  2842. msg.binaryBucket
  2843. = Util.StringToBytes256(
  2844. "{0}/{1}/{2}/{3}",
  2845. World.RegionInfo.RegionName,
  2846. (int)Math.Floor(pos.X),
  2847. (int)Math.Floor(pos.Y),
  2848. (int)Math.Floor(pos.Z));
  2849. if (m_TransferModule != null)
  2850. {
  2851. m_TransferModule.SendInstantMessage(msg, delegate(bool success) {});
  2852. }
  2853. ScriptSleep(2000);
  2854. }
  2855. public void llEmail(string address, string subject, string message)
  2856. {
  2857. m_host.AddScriptLPS(1);
  2858. IEmailModule emailModule = m_ScriptEngine.World.RequestModuleInterface<IEmailModule>();
  2859. if (emailModule == null)
  2860. {
  2861. Error("llEmail", "Email module not configured");
  2862. return;
  2863. }
  2864. emailModule.SendEmail(m_host.UUID, address, subject, message);
  2865. ScriptSleep(EMAIL_PAUSE_TIME * 1000);
  2866. }
  2867. public void llGetNextEmail(string address, string subject)
  2868. {
  2869. m_host.AddScriptLPS(1);
  2870. IEmailModule emailModule = m_ScriptEngine.World.RequestModuleInterface<IEmailModule>();
  2871. if (emailModule == null)
  2872. {
  2873. Error("llGetNextEmail", "Email module not configured");
  2874. return;
  2875. }
  2876. Email email;
  2877. email = emailModule.GetNextEmail(m_host.UUID, address, subject);
  2878. if (email == null)
  2879. return;
  2880. m_ScriptEngine.PostObjectEvent(m_host.LocalId,
  2881. new EventParams("email",
  2882. new Object[] {
  2883. new LSL_String(email.time),
  2884. new LSL_String(email.sender),
  2885. new LSL_String(email.subject),
  2886. new LSL_String(email.message),
  2887. new LSL_Integer(email.numLeft)},
  2888. new DetectParams[0]));
  2889. }
  2890. public LSL_String llGetKey()
  2891. {
  2892. m_host.AddScriptLPS(1);
  2893. return m_host.UUID.ToString();
  2894. }
  2895. public LSL_Key llGenerateKey()
  2896. {
  2897. m_host.AddScriptLPS(1);
  2898. return UUID.Random().ToString();
  2899. }
  2900. public void llSetBuoyancy(double buoyancy)
  2901. {
  2902. m_host.AddScriptLPS(1);
  2903. if (!m_host.ParentGroup.IsDeleted)
  2904. {
  2905. m_host.ParentGroup.RootPart.SetBuoyancy((float)buoyancy);
  2906. }
  2907. }
  2908. /// <summary>
  2909. /// Attempt to clamp the object on the Z axis at the given height over tau seconds.
  2910. /// </summary>
  2911. /// <param name="height">Height to hover. Height of zero disables hover.</param>
  2912. /// <param name="water">False if height is calculated just from ground, otherwise uses ground or water depending on whichever is higher</param>
  2913. /// <param name="tau">Number of seconds over which to reach target</param>
  2914. public void llSetHoverHeight(double height, int water, double tau)
  2915. {
  2916. m_host.AddScriptLPS(1);
  2917. if (m_host.PhysActor != null)
  2918. {
  2919. PIDHoverType hoverType = PIDHoverType.Ground;
  2920. if (water != 0)
  2921. {
  2922. hoverType = PIDHoverType.GroundAndWater;
  2923. }
  2924. m_host.SetHoverHeight((float)height, hoverType, (float)tau);
  2925. }
  2926. }
  2927. public void llStopHover()
  2928. {
  2929. m_host.AddScriptLPS(1);
  2930. if (m_host.PhysActor != null)
  2931. {
  2932. m_host.SetHoverHeight(0f, PIDHoverType.Ground, 0f);
  2933. }
  2934. }
  2935. public void llMinEventDelay(double delay)
  2936. {
  2937. m_host.AddScriptLPS(1);
  2938. try
  2939. {
  2940. m_ScriptEngine.SetMinEventDelay(m_item.ItemID, delay);
  2941. }
  2942. catch (NotImplementedException)
  2943. {
  2944. // Currently not implemented in DotNetEngine only XEngine
  2945. NotImplemented("llMinEventDelay", "In DotNetEngine");
  2946. }
  2947. }
  2948. public void llSoundPreload(string sound)
  2949. {
  2950. m_host.AddScriptLPS(1);
  2951. Deprecated("llSoundPreload", "Use llPreloadSound instead");
  2952. }
  2953. public void llRotLookAt(LSL_Rotation target, double strength, double damping)
  2954. {
  2955. m_host.AddScriptLPS(1);
  2956. // Per discussion with Melanie, for non-physical objects llLookAt appears to simply
  2957. // set the rotation of the object, copy that behavior
  2958. PhysicsActor pa = m_host.PhysActor;
  2959. if (strength == 0 || pa == null || !pa.IsPhysical)
  2960. {
  2961. llSetLocalRot(target);
  2962. }
  2963. else
  2964. {
  2965. m_host.RotLookAt(target, (float)strength, (float)damping);
  2966. }
  2967. }
  2968. public LSL_Integer llStringLength(string str)
  2969. {
  2970. m_host.AddScriptLPS(1);
  2971. if (str.Length > 0)
  2972. {
  2973. return str.Length;
  2974. }
  2975. else
  2976. {
  2977. return 0;
  2978. }
  2979. }
  2980. public void llStartAnimation(string anim)
  2981. {
  2982. m_host.AddScriptLPS(1);
  2983. if (m_item.PermsGranter == UUID.Zero)
  2984. return;
  2985. if ((m_item.PermsMask & ScriptBaseClass.PERMISSION_TRIGGER_ANIMATION) != 0)
  2986. {
  2987. ScenePresence presence = World.GetScenePresence(m_item.PermsGranter);
  2988. if (presence != null)
  2989. {
  2990. // Do NOT try to parse UUID, animations cannot be triggered by ID
  2991. UUID animID = ScriptUtils.GetAssetIdFromItemName(m_host, anim, (int)AssetType.Animation);
  2992. if (animID == UUID.Zero)
  2993. presence.Animator.AddAnimation(anim, m_host.UUID);
  2994. else
  2995. presence.Animator.AddAnimation(animID, m_host.UUID);
  2996. }
  2997. }
  2998. }
  2999. public void llStopAnimation(string anim)
  3000. {
  3001. m_host.AddScriptLPS(1);
  3002. if (m_item.PermsGranter == UUID.Zero)
  3003. return;
  3004. if ((m_item.PermsMask & ScriptBaseClass.PERMISSION_TRIGGER_ANIMATION) != 0)
  3005. {
  3006. ScenePresence presence = World.GetScenePresence(m_item.PermsGranter);
  3007. if (presence != null)
  3008. {
  3009. UUID animID = ScriptUtils.GetAssetIdFromKeyOrItemName(m_host, anim);
  3010. if (animID == UUID.Zero)
  3011. presence.Animator.RemoveAnimation(anim);
  3012. else
  3013. presence.Animator.RemoveAnimation(animID, true);
  3014. }
  3015. }
  3016. }
  3017. public void llPointAt(LSL_Vector pos)
  3018. {
  3019. m_host.AddScriptLPS(1);
  3020. }
  3021. public void llStopPointAt()
  3022. {
  3023. m_host.AddScriptLPS(1);
  3024. }
  3025. public void llTargetOmega(LSL_Vector axis, double spinrate, double gain)
  3026. {
  3027. m_host.AddScriptLPS(1);
  3028. TargetOmega(m_host, axis, spinrate, gain);
  3029. }
  3030. protected void TargetOmega(SceneObjectPart part, LSL_Vector axis, double spinrate, double gain)
  3031. {
  3032. part.UpdateAngularVelocity(axis * spinrate);
  3033. }
  3034. public LSL_Integer llGetStartParameter()
  3035. {
  3036. m_host.AddScriptLPS(1);
  3037. return m_ScriptEngine.GetStartParameter(m_item.ItemID);
  3038. }
  3039. public void llRequestPermissions(string agent, int perm)
  3040. {
  3041. UUID agentID;
  3042. if (!UUID.TryParse(agent, out agentID))
  3043. return;
  3044. if (agentID == UUID.Zero || perm == 0) // Releasing permissions
  3045. {
  3046. llReleaseControls();
  3047. m_item.PermsGranter = UUID.Zero;
  3048. m_item.PermsMask = 0;
  3049. m_ScriptEngine.PostScriptEvent(m_item.ItemID, new EventParams(
  3050. "run_time_permissions", new Object[] {
  3051. new LSL_Integer(0) },
  3052. new DetectParams[0]));
  3053. return;
  3054. }
  3055. if (m_item.PermsGranter != agentID || (perm & ScriptBaseClass.PERMISSION_TAKE_CONTROLS) == 0)
  3056. llReleaseControls();
  3057. m_host.AddScriptLPS(1);
  3058. int implicitPerms = 0;
  3059. if (m_host.ParentGroup.IsAttachment && (UUID)agent == m_host.ParentGroup.AttachedAvatar)
  3060. {
  3061. // When attached, certain permissions are implicit if requested from owner
  3062. implicitPerms = ScriptBaseClass.PERMISSION_TAKE_CONTROLS |
  3063. ScriptBaseClass.PERMISSION_TRIGGER_ANIMATION |
  3064. ScriptBaseClass.PERMISSION_CONTROL_CAMERA |
  3065. ScriptBaseClass.PERMISSION_ATTACH;
  3066. }
  3067. else
  3068. {
  3069. if (m_host.ParentGroup.GetSittingAvatars().Contains(agentID))
  3070. {
  3071. // When agent is sitting, certain permissions are implicit if requested from sitting agent
  3072. implicitPerms = ScriptBaseClass.PERMISSION_TRIGGER_ANIMATION |
  3073. ScriptBaseClass.PERMISSION_CONTROL_CAMERA |
  3074. ScriptBaseClass.PERMISSION_TRACK_CAMERA |
  3075. ScriptBaseClass.PERMISSION_TAKE_CONTROLS;
  3076. }
  3077. else
  3078. {
  3079. if (World.GetExtraSetting("auto_grant_attach_perms") == "true")
  3080. implicitPerms = ScriptBaseClass.PERMISSION_ATTACH;
  3081. }
  3082. }
  3083. if ((perm & (~implicitPerms)) == 0) // Requested only implicit perms
  3084. {
  3085. lock (m_host.TaskInventory)
  3086. {
  3087. m_host.TaskInventory[m_item.ItemID].PermsGranter = agentID;
  3088. m_host.TaskInventory[m_item.ItemID].PermsMask = perm;
  3089. }
  3090. m_ScriptEngine.PostScriptEvent(m_item.ItemID, new EventParams(
  3091. "run_time_permissions", new Object[] {
  3092. new LSL_Integer(perm) },
  3093. new DetectParams[0]));
  3094. return;
  3095. }
  3096. ScenePresence presence = World.GetScenePresence(agentID);
  3097. if (presence != null)
  3098. {
  3099. // If permissions are being requested from an NPC and were not implicitly granted above then
  3100. // auto grant all reuqested permissions if the script is owned by the NPC or the NPCs owner
  3101. INPCModule npcModule = World.RequestModuleInterface<INPCModule>();
  3102. if (npcModule != null && npcModule.IsNPC(agentID, World))
  3103. {
  3104. if (npcModule.CheckPermissions(agentID, m_host.OwnerID))
  3105. {
  3106. lock (m_host.TaskInventory)
  3107. {
  3108. m_host.TaskInventory[m_item.ItemID].PermsGranter = agentID;
  3109. m_host.TaskInventory[m_item.ItemID].PermsMask = perm;
  3110. }
  3111. m_ScriptEngine.PostScriptEvent(
  3112. m_item.ItemID,
  3113. new EventParams(
  3114. "run_time_permissions", new Object[] { new LSL_Integer(perm) }, new DetectParams[0]));
  3115. }
  3116. // it is an NPC, exit even if the permissions werent granted above, they are not going to answer
  3117. // the question!
  3118. return;
  3119. }
  3120. string ownerName = resolveName(m_host.ParentGroup.RootPart.OwnerID);
  3121. if (ownerName == String.Empty)
  3122. ownerName = "(hippos)";
  3123. if (!m_waitingForScriptAnswer)
  3124. {
  3125. lock (m_host.TaskInventory)
  3126. {
  3127. m_host.TaskInventory[m_item.ItemID].PermsGranter = agentID;
  3128. m_host.TaskInventory[m_item.ItemID].PermsMask = 0;
  3129. }
  3130. presence.ControllingClient.OnScriptAnswer += handleScriptAnswer;
  3131. m_waitingForScriptAnswer=true;
  3132. }
  3133. presence.ControllingClient.SendScriptQuestion(
  3134. m_host.UUID, m_host.ParentGroup.RootPart.Name, ownerName, m_item.ItemID, perm);
  3135. return;
  3136. }
  3137. // Requested agent is not in range, refuse perms
  3138. m_ScriptEngine.PostScriptEvent(
  3139. m_item.ItemID,
  3140. new EventParams("run_time_permissions", new Object[] { new LSL_Integer(0) }, new DetectParams[0]));
  3141. }
  3142. void handleScriptAnswer(IClientAPI client, UUID taskID, UUID itemID, int answer)
  3143. {
  3144. if (taskID != m_host.UUID)
  3145. return;
  3146. client.OnScriptAnswer -= handleScriptAnswer;
  3147. m_waitingForScriptAnswer = false;
  3148. if ((answer & ScriptBaseClass.PERMISSION_TAKE_CONTROLS) == 0)
  3149. llReleaseControls();
  3150. lock (m_host.TaskInventory)
  3151. {
  3152. m_host.TaskInventory[m_item.ItemID].PermsMask = answer;
  3153. }
  3154. m_ScriptEngine.PostScriptEvent(
  3155. m_item.ItemID,
  3156. new EventParams("run_time_permissions", new Object[] { new LSL_Integer(answer) }, new DetectParams[0]));
  3157. }
  3158. public LSL_String llGetPermissionsKey()
  3159. {
  3160. m_host.AddScriptLPS(1);
  3161. return m_item.PermsGranter.ToString();
  3162. }
  3163. public LSL_Integer llGetPermissions()
  3164. {
  3165. m_host.AddScriptLPS(1);
  3166. int perms = m_item.PermsMask;
  3167. if (m_automaticLinkPermission)
  3168. perms |= ScriptBaseClass.PERMISSION_CHANGE_LINKS;
  3169. return perms;
  3170. }
  3171. public LSL_Integer llGetLinkNumber()
  3172. {
  3173. m_host.AddScriptLPS(1);
  3174. if (m_host.ParentGroup.PrimCount > 1)
  3175. {
  3176. return m_host.LinkNum;
  3177. }
  3178. else
  3179. {
  3180. return 0;
  3181. }
  3182. }
  3183. public void llSetLinkColor(int linknumber, LSL_Vector color, int face)
  3184. {
  3185. List<SceneObjectPart> parts = GetLinkParts(linknumber);
  3186. foreach (SceneObjectPart part in parts)
  3187. part.SetFaceColorAlpha(face, color, null);
  3188. }
  3189. public void llCreateLink(string target, int parent)
  3190. {
  3191. m_host.AddScriptLPS(1);
  3192. UUID targetID;
  3193. if (!UUID.TryParse(target, out targetID))
  3194. return;
  3195. if ((m_item.PermsMask & ScriptBaseClass.PERMISSION_CHANGE_LINKS) == 0
  3196. && !m_automaticLinkPermission)
  3197. {
  3198. Error("llCreateLink", "PERMISSION_CHANGE_LINKS permission not set");
  3199. return;
  3200. }
  3201. IClientAPI client = null;
  3202. ScenePresence sp = World.GetScenePresence(m_item.PermsGranter);
  3203. if (sp != null)
  3204. client = sp.ControllingClient;
  3205. SceneObjectPart targetPart = World.GetSceneObjectPart((UUID)targetID);
  3206. if (targetPart.ParentGroup.AttachmentPoint != 0)
  3207. return; // Fail silently if attached
  3208. if (targetPart.ParentGroup.RootPart.OwnerID != m_host.ParentGroup.RootPart.OwnerID)
  3209. return;
  3210. SceneObjectGroup parentPrim = null, childPrim = null;
  3211. if (targetPart != null)
  3212. {
  3213. if (parent != 0)
  3214. {
  3215. parentPrim = m_host.ParentGroup;
  3216. childPrim = targetPart.ParentGroup;
  3217. }
  3218. else
  3219. {
  3220. parentPrim = targetPart.ParentGroup;
  3221. childPrim = m_host.ParentGroup;
  3222. }
  3223. // Required for linking
  3224. childPrim.RootPart.ClearUpdateSchedule();
  3225. parentPrim.LinkToGroup(childPrim, true);
  3226. }
  3227. parentPrim.TriggerScriptChangedEvent(Changed.LINK);
  3228. parentPrim.RootPart.CreateSelected = true;
  3229. parentPrim.HasGroupChanged = true;
  3230. parentPrim.ScheduleGroupForFullUpdate();
  3231. if (client != null)
  3232. parentPrim.SendPropertiesToClient(client);
  3233. ScriptSleep(1000);
  3234. }
  3235. public void llBreakLink(int linknum)
  3236. {
  3237. m_host.AddScriptLPS(1);
  3238. if ((m_item.PermsMask & ScriptBaseClass.PERMISSION_CHANGE_LINKS) == 0
  3239. && !m_automaticLinkPermission)
  3240. {
  3241. Error("llBreakLink", "PERMISSION_CHANGE_LINKS permission not set");
  3242. return;
  3243. }
  3244. if (linknum < ScriptBaseClass.LINK_THIS)
  3245. return;
  3246. SceneObjectGroup parentPrim = m_host.ParentGroup;
  3247. if (parentPrim.AttachmentPoint != 0)
  3248. return; // Fail silently if attached
  3249. SceneObjectPart childPrim = null;
  3250. switch (linknum)
  3251. {
  3252. case ScriptBaseClass.LINK_ROOT:
  3253. break;
  3254. case ScriptBaseClass.LINK_SET:
  3255. case ScriptBaseClass.LINK_ALL_OTHERS:
  3256. case ScriptBaseClass.LINK_ALL_CHILDREN:
  3257. case ScriptBaseClass.LINK_THIS:
  3258. foreach (SceneObjectPart part in parentPrim.Parts)
  3259. {
  3260. if (part.UUID != m_host.UUID)
  3261. {
  3262. childPrim = part;
  3263. break;
  3264. }
  3265. }
  3266. break;
  3267. default:
  3268. childPrim = parentPrim.GetLinkNumPart(linknum);
  3269. if (childPrim.UUID == m_host.UUID)
  3270. childPrim = null;
  3271. break;
  3272. }
  3273. if (linknum == ScriptBaseClass.LINK_ROOT)
  3274. {
  3275. // Restructuring Multiple Prims.
  3276. List<SceneObjectPart> parts = new List<SceneObjectPart>(parentPrim.Parts);
  3277. parts.Remove(parentPrim.RootPart);
  3278. foreach (SceneObjectPart part in parts)
  3279. {
  3280. parentPrim.DelinkFromGroup(part.LocalId, true);
  3281. }
  3282. parentPrim.HasGroupChanged = true;
  3283. parentPrim.ScheduleGroupForFullUpdate();
  3284. parentPrim.TriggerScriptChangedEvent(Changed.LINK);
  3285. if (parts.Count > 0)
  3286. {
  3287. SceneObjectPart newRoot = parts[0];
  3288. parts.Remove(newRoot);
  3289. foreach (SceneObjectPart part in parts)
  3290. {
  3291. // Required for linking
  3292. part.ClearUpdateSchedule();
  3293. newRoot.ParentGroup.LinkToGroup(part.ParentGroup);
  3294. }
  3295. newRoot.ParentGroup.HasGroupChanged = true;
  3296. newRoot.ParentGroup.ScheduleGroupForFullUpdate();
  3297. }
  3298. }
  3299. else
  3300. {
  3301. if (childPrim == null)
  3302. return;
  3303. parentPrim.DelinkFromGroup(childPrim.LocalId, true);
  3304. parentPrim.HasGroupChanged = true;
  3305. parentPrim.ScheduleGroupForFullUpdate();
  3306. parentPrim.TriggerScriptChangedEvent(Changed.LINK);
  3307. }
  3308. }
  3309. public void llBreakAllLinks()
  3310. {
  3311. m_host.AddScriptLPS(1);
  3312. SceneObjectGroup parentPrim = m_host.ParentGroup;
  3313. if (parentPrim.AttachmentPoint != 0)
  3314. return; // Fail silently if attached
  3315. List<SceneObjectPart> parts = new List<SceneObjectPart>(parentPrim.Parts);
  3316. parts.Remove(parentPrim.RootPart);
  3317. foreach (SceneObjectPart part in parts)
  3318. {
  3319. parentPrim.DelinkFromGroup(part.LocalId, true);
  3320. parentPrim.TriggerScriptChangedEvent(Changed.LINK);
  3321. }
  3322. parentPrim.HasGroupChanged = true;
  3323. parentPrim.ScheduleGroupForFullUpdate();
  3324. }
  3325. public LSL_String llGetLinkKey(int linknum)
  3326. {
  3327. m_host.AddScriptLPS(1);
  3328. ISceneEntity entity = GetLinkEntity(linknum);
  3329. if (entity != null)
  3330. return entity.UUID.ToString();
  3331. else
  3332. return ScriptBaseClass.NULL_KEY;
  3333. }
  3334. /// <summary>
  3335. /// Returns the name of the child prim or seated avatar matching the
  3336. /// specified link number.
  3337. /// </summary>
  3338. /// <param name="linknum">
  3339. /// The number of a link in the linkset or a link-related constant.
  3340. /// </param>
  3341. /// <returns>
  3342. /// The name determined to match the specified link number.
  3343. /// </returns>
  3344. /// <remarks>
  3345. /// The rules governing the returned name are not simple. The only
  3346. /// time a blank name is returned is if the target prim has a blank
  3347. /// name. If no prim with the given link number can be found then
  3348. /// usually NULL_KEY is returned but there are exceptions.
  3349. ///
  3350. /// In a single unlinked prim, A call with 0 returns the name, all
  3351. /// other values for link number return NULL_KEY
  3352. ///
  3353. /// In link sets it is more complicated.
  3354. ///
  3355. /// If the script is in the root prim:-
  3356. /// A zero link number returns NULL_KEY.
  3357. /// Positive link numbers return the name of the prim, or NULL_KEY
  3358. /// if a prim does not exist at that position.
  3359. /// Negative link numbers return the name of the first child prim.
  3360. ///
  3361. /// If the script is in a child prim:-
  3362. /// Link numbers 0 or 1 return the name of the root prim.
  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 numbers return the name of the root prim.
  3366. ///
  3367. /// References
  3368. /// http://lslwiki.net/lslwiki/wakka.php?wakka=llGetLinkName
  3369. /// Mentions NULL_KEY being returned
  3370. /// http://wiki.secondlife.com/wiki/LlGetLinkName
  3371. /// Mentions using the LINK_* constants, some of which are negative
  3372. /// </remarks>
  3373. public LSL_String llGetLinkName(int linknum)
  3374. {
  3375. m_host.AddScriptLPS(1);
  3376. ISceneEntity entity = GetLinkEntity(linknum);
  3377. if (entity != null)
  3378. return entity.Name;
  3379. else
  3380. return ScriptBaseClass.NULL_KEY;
  3381. }
  3382. public LSL_Integer llGetInventoryNumber(int type)
  3383. {
  3384. m_host.AddScriptLPS(1);
  3385. int count = 0;
  3386. lock (m_host.TaskInventory)
  3387. {
  3388. foreach (KeyValuePair<UUID, TaskInventoryItem> inv in m_host.TaskInventory)
  3389. {
  3390. if (inv.Value.Type == type || type == -1)
  3391. {
  3392. count = count + 1;
  3393. }
  3394. }
  3395. }
  3396. return count;
  3397. }
  3398. public LSL_String llGetInventoryName(int type, int number)
  3399. {
  3400. m_host.AddScriptLPS(1);
  3401. ArrayList keys = new ArrayList();
  3402. lock (m_host.TaskInventory)
  3403. {
  3404. foreach (KeyValuePair<UUID, TaskInventoryItem> inv in m_host.TaskInventory)
  3405. {
  3406. if (inv.Value.Type == type || type == -1)
  3407. {
  3408. keys.Add(inv.Value.Name);
  3409. }
  3410. }
  3411. }
  3412. if (keys.Count == 0)
  3413. {
  3414. return String.Empty;
  3415. }
  3416. keys.Sort();
  3417. if (keys.Count > number)
  3418. {
  3419. return (string)keys[number];
  3420. }
  3421. return String.Empty;
  3422. }
  3423. public LSL_Float llGetEnergy()
  3424. {
  3425. m_host.AddScriptLPS(1);
  3426. // TODO: figure out real energy value
  3427. return 1.0f;
  3428. }
  3429. public void llGiveInventory(string destination, string inventory)
  3430. {
  3431. m_host.AddScriptLPS(1);
  3432. UUID destId = UUID.Zero;
  3433. if (!UUID.TryParse(destination, out destId))
  3434. {
  3435. Error("llGiveInventory", "Can't parse destination key '" + destination + "'");
  3436. return;
  3437. }
  3438. TaskInventoryItem item = m_host.Inventory.GetInventoryItem(inventory);
  3439. if (item == null)
  3440. {
  3441. Error("llGiveInventory", "Can't find inventory object '" + inventory + "'");
  3442. }
  3443. UUID objId = item.ItemID;
  3444. // check if destination is an object
  3445. if (World.GetSceneObjectPart(destId) != null)
  3446. {
  3447. // destination is an object
  3448. World.MoveTaskInventoryItem(destId, m_host, objId);
  3449. }
  3450. else
  3451. {
  3452. ScenePresence presence = World.GetScenePresence(destId);
  3453. if (presence == null)
  3454. {
  3455. UserAccount account =
  3456. World.UserAccountService.GetUserAccount(
  3457. World.RegionInfo.ScopeID,
  3458. destId);
  3459. if (account == null)
  3460. {
  3461. Error("llGiveInventory", "Can't find destination '" + destId.ToString() + "'");
  3462. return;
  3463. }
  3464. }
  3465. // destination is an avatar
  3466. InventoryItemBase agentItem = World.MoveTaskInventoryItem(destId, UUID.Zero, m_host, objId);
  3467. if (agentItem == null)
  3468. return;
  3469. if (m_TransferModule != null)
  3470. {
  3471. byte[] bucket = new byte[1];
  3472. bucket[0] = (byte)item.Type;
  3473. GridInstantMessage msg = new GridInstantMessage(World,
  3474. m_host.OwnerID, m_host.Name, destId,
  3475. (byte)InstantMessageDialog.TaskInventoryOffered,
  3476. false, item.Name+". "+m_host.Name+" is located at "+
  3477. World.RegionInfo.RegionName+" "+
  3478. m_host.AbsolutePosition.ToString(),
  3479. agentItem.ID, true, m_host.AbsolutePosition,
  3480. bucket, true);
  3481. m_TransferModule.SendInstantMessage(msg, delegate(bool success) {});
  3482. }
  3483. ScriptSleep(3000);
  3484. }
  3485. }
  3486. public void llRemoveInventory(string name)
  3487. {
  3488. m_host.AddScriptLPS(1);
  3489. TaskInventoryItem item = m_host.Inventory.GetInventoryItem(name);
  3490. if (item == null)
  3491. return;
  3492. if (item.ItemID == m_item.ItemID)
  3493. throw new ScriptDeleteException();
  3494. else
  3495. m_host.Inventory.RemoveInventoryItem(item.ItemID);
  3496. }
  3497. public void llSetText(string text, LSL_Vector color, double alpha)
  3498. {
  3499. m_host.AddScriptLPS(1);
  3500. Vector3 av3 = Util.Clip(color, 0.0f, 1.0f);
  3501. if (text.Length > 254)
  3502. text = text.Remove(254);
  3503. byte[] data;
  3504. do
  3505. {
  3506. data = Util.UTF8.GetBytes(text);
  3507. if (data.Length > 254)
  3508. text = text.Substring(0, text.Length - 1);
  3509. } while (data.Length > 254);
  3510. m_host.SetText(text, av3, Util.Clip((float)alpha, 0.0f, 1.0f));
  3511. //m_host.ParentGroup.HasGroupChanged = true;
  3512. //m_host.ParentGroup.ScheduleGroupForFullUpdate();
  3513. }
  3514. public LSL_Float llWater(LSL_Vector offset)
  3515. {
  3516. m_host.AddScriptLPS(1);
  3517. return World.RegionInfo.RegionSettings.WaterHeight;
  3518. }
  3519. public void llPassTouches(int pass)
  3520. {
  3521. m_host.AddScriptLPS(1);
  3522. if (pass != 0)
  3523. m_host.PassTouches = true;
  3524. else
  3525. m_host.PassTouches = false;
  3526. }
  3527. public LSL_String llRequestAgentData(string id, int data)
  3528. {
  3529. m_host.AddScriptLPS(1);
  3530. UUID uuid = (UUID)id;
  3531. PresenceInfo pinfo = null;
  3532. UserAccount account;
  3533. UserInfoCacheEntry ce;
  3534. if (!m_userInfoCache.TryGetValue(uuid, out ce))
  3535. {
  3536. account = World.UserAccountService.GetUserAccount(World.RegionInfo.ScopeID, uuid);
  3537. if (account == null)
  3538. {
  3539. m_userInfoCache[uuid] = null; // Cache negative
  3540. return UUID.Zero.ToString();
  3541. }
  3542. PresenceInfo[] pinfos = World.PresenceService.GetAgents(new string[] { uuid.ToString() });
  3543. if (pinfos != null && pinfos.Length > 0)
  3544. {
  3545. foreach (PresenceInfo p in pinfos)
  3546. {
  3547. if (p.RegionID != UUID.Zero)
  3548. {
  3549. pinfo = p;
  3550. }
  3551. }
  3552. }
  3553. ce = new UserInfoCacheEntry();
  3554. ce.time = Util.EnvironmentTickCount();
  3555. ce.account = account;
  3556. ce.pinfo = pinfo;
  3557. }
  3558. else
  3559. {
  3560. if (ce == null)
  3561. return UUID.Zero.ToString();
  3562. account = ce.account;
  3563. pinfo = ce.pinfo;
  3564. }
  3565. if (Util.EnvironmentTickCount() < ce.time || (Util.EnvironmentTickCount() - ce.time) >= 20000)
  3566. {
  3567. PresenceInfo[] pinfos = World.PresenceService.GetAgents(new string[] { uuid.ToString() });
  3568. if (pinfos != null && pinfos.Length > 0)
  3569. {
  3570. foreach (PresenceInfo p in pinfos)
  3571. {
  3572. if (p.RegionID != UUID.Zero)
  3573. {
  3574. pinfo = p;
  3575. }
  3576. }
  3577. }
  3578. else
  3579. pinfo = null;
  3580. ce.time = Util.EnvironmentTickCount();
  3581. ce.pinfo = pinfo;
  3582. }
  3583. string reply = String.Empty;
  3584. switch (data)
  3585. {
  3586. case 1: // DATA_ONLINE (0|1)
  3587. if (pinfo != null && pinfo.RegionID != UUID.Zero)
  3588. reply = "1";
  3589. else
  3590. reply = "0";
  3591. break;
  3592. case 2: // DATA_NAME (First Last)
  3593. reply = account.FirstName + " " + account.LastName;
  3594. break;
  3595. case 3: // DATA_BORN (YYYY-MM-DD)
  3596. DateTime born = new DateTime(1970, 1, 1, 0, 0, 0, 0);
  3597. born = born.AddSeconds(account.Created);
  3598. reply = born.ToString("yyyy-MM-dd");
  3599. break;
  3600. case 4: // DATA_RATING (0,0,0,0,0,0)
  3601. reply = "0,0,0,0,0,0";
  3602. break;
  3603. case 7: // DATA_USERLEVEL (integer)
  3604. reply = account.UserLevel.ToString();
  3605. break;
  3606. case 8: // DATA_PAYINFO (0|1|2|3)
  3607. reply = "0";
  3608. break;
  3609. default:
  3610. return UUID.Zero.ToString(); // Raise no event
  3611. }
  3612. UUID rq = UUID.Random();
  3613. UUID tid = AsyncCommands.
  3614. DataserverPlugin.RegisterRequest(m_host.LocalId,
  3615. m_item.ItemID, rq.ToString());
  3616. AsyncCommands.
  3617. DataserverPlugin.DataserverReply(rq.ToString(), reply);
  3618. ScriptSleep(100);
  3619. return tid.ToString();
  3620. }
  3621. public LSL_String llRequestInventoryData(string name)
  3622. {
  3623. m_host.AddScriptLPS(1);
  3624. foreach (TaskInventoryItem item in m_host.Inventory.GetInventoryItems())
  3625. {
  3626. if (item.Type == 3 && item.Name == name)
  3627. {
  3628. UUID tid = AsyncCommands.
  3629. DataserverPlugin.RegisterRequest(m_host.LocalId,
  3630. m_item.ItemID, item.AssetID.ToString());
  3631. Vector3 region = new Vector3(World.RegionInfo.WorldLocX, World.RegionInfo.WorldLocY, 0);
  3632. World.AssetService.Get(item.AssetID.ToString(), this,
  3633. delegate(string i, object sender, AssetBase a)
  3634. {
  3635. AssetLandmark lm = new AssetLandmark(a);
  3636. float rx = (uint)(lm.RegionHandle >> 32);
  3637. float ry = (uint)lm.RegionHandle;
  3638. region = lm.Position + new Vector3(rx, ry, 0) - region;
  3639. string reply = region.ToString();
  3640. AsyncCommands.
  3641. DataserverPlugin.DataserverReply(i.ToString(),
  3642. reply);
  3643. });
  3644. ScriptSleep(1000);
  3645. return tid.ToString();
  3646. }
  3647. }
  3648. ScriptSleep(1000);
  3649. return String.Empty;
  3650. }
  3651. public void llSetDamage(double damage)
  3652. {
  3653. m_host.AddScriptLPS(1);
  3654. m_host.ParentGroup.Damage = (float)damage;
  3655. }
  3656. public void llTeleportAgentHome(string agent)
  3657. {
  3658. m_host.AddScriptLPS(1);
  3659. UUID agentId = new UUID();
  3660. if (UUID.TryParse(agent, out agentId))
  3661. {
  3662. ScenePresence presence = World.GetScenePresence(agentId);
  3663. if (presence != null)
  3664. {
  3665. // agent must be over the owners land
  3666. if (m_host.OwnerID == World.LandChannel.GetLandObject(presence.AbsolutePosition).LandData.OwnerID)
  3667. {
  3668. World.TeleportClientHome(agentId, presence.ControllingClient);
  3669. }
  3670. }
  3671. }
  3672. ScriptSleep(5000);
  3673. }
  3674. public void llTeleportAgent(string agent, string destination, LSL_Vector targetPos, LSL_Vector targetLookAt)
  3675. {
  3676. m_host.AddScriptLPS(1);
  3677. UUID agentId = new UUID();
  3678. if (UUID.TryParse(agent, out agentId))
  3679. {
  3680. ScenePresence presence = World.GetScenePresence(agentId);
  3681. if (presence != null && presence.PresenceType != PresenceType.Npc)
  3682. {
  3683. // agent must not be a god
  3684. if (presence.GodLevel >= 200) return;
  3685. if (destination == String.Empty)
  3686. destination = World.RegionInfo.RegionName;
  3687. // agent must be over the owners land
  3688. if (m_host.OwnerID == World.LandChannel.GetLandObject(presence.AbsolutePosition).LandData.OwnerID)
  3689. {
  3690. DoLLTeleport(presence, destination, targetPos, targetLookAt);
  3691. }
  3692. else // or must be wearing the prim
  3693. {
  3694. if (m_host.ParentGroup.AttachmentPoint != 0 && m_host.OwnerID == presence.UUID)
  3695. {
  3696. DoLLTeleport(presence, destination, targetPos, targetLookAt);
  3697. }
  3698. }
  3699. }
  3700. }
  3701. }
  3702. public void llTeleportAgentGlobalCoords(string agent, LSL_Vector global_coords, LSL_Vector targetPos, LSL_Vector targetLookAt)
  3703. {
  3704. m_host.AddScriptLPS(1);
  3705. UUID agentId = new UUID();
  3706. ulong regionHandle = Util.RegionWorldLocToHandle((uint)global_coords.x, (uint)global_coords.y);
  3707. if (UUID.TryParse(agent, out agentId))
  3708. {
  3709. ScenePresence presence = World.GetScenePresence(agentId);
  3710. if (presence != null && presence.PresenceType != PresenceType.Npc)
  3711. {
  3712. // agent must not be a god
  3713. if (presence.GodLevel >= 200) return;
  3714. // agent must be over the owners land
  3715. if (m_host.OwnerID == World.LandChannel.GetLandObject(presence.AbsolutePosition).LandData.OwnerID)
  3716. {
  3717. World.RequestTeleportLocation(presence.ControllingClient, regionHandle, targetPos, targetLookAt, (uint)TeleportFlags.ViaLocation);
  3718. }
  3719. else // or must be wearing the prim
  3720. {
  3721. if (m_host.ParentGroup.AttachmentPoint != 0 && m_host.OwnerID == presence.UUID)
  3722. {
  3723. World.RequestTeleportLocation(presence.ControllingClient, regionHandle, targetPos, targetLookAt, (uint)TeleportFlags.ViaLocation);
  3724. }
  3725. }
  3726. }
  3727. }
  3728. }
  3729. private void DoLLTeleport(ScenePresence sp, string destination, Vector3 targetPos, Vector3 targetLookAt)
  3730. {
  3731. UUID assetID = ScriptUtils.GetAssetIdFromKeyOrItemName(m_host, destination);
  3732. // The destinaion is not an asset ID and also doesn't name a landmark.
  3733. // Use it as a sim name
  3734. if (assetID == UUID.Zero)
  3735. {
  3736. World.RequestTeleportLocation(sp.ControllingClient, destination, targetPos, targetLookAt, (uint)TeleportFlags.ViaLocation);
  3737. return;
  3738. }
  3739. AssetBase lma = World.AssetService.Get(assetID.ToString());
  3740. if (lma == null)
  3741. return;
  3742. if (lma.Type != (sbyte)AssetType.Landmark)
  3743. return;
  3744. AssetLandmark lm = new AssetLandmark(lma);
  3745. World.RequestTeleportLocation(sp.ControllingClient, lm.RegionHandle, targetPos, targetLookAt, (uint)TeleportFlags.ViaLocation);
  3746. }
  3747. public void llTextBox(string agent, string message, int chatChannel)
  3748. {
  3749. IDialogModule dm = World.RequestModuleInterface<IDialogModule>();
  3750. if (dm == null)
  3751. return;
  3752. m_host.AddScriptLPS(1);
  3753. UUID av = new UUID();
  3754. if (!UUID.TryParse(agent,out av))
  3755. {
  3756. Error("llTextBox", "First parameter must be a key");
  3757. return;
  3758. }
  3759. if (message == string.Empty)
  3760. {
  3761. Error("llTextBox", "Empty message");
  3762. }
  3763. else if (message.Length > 512)
  3764. {
  3765. Error("llTextBox", "Message more than 512 characters");
  3766. }
  3767. else
  3768. {
  3769. dm.SendTextBoxToUser(av, message, chatChannel, m_host.Name, m_host.UUID, m_host.OwnerID);
  3770. ScriptSleep(1000);
  3771. }
  3772. }
  3773. public void llModifyLand(int action, int brush)
  3774. {
  3775. m_host.AddScriptLPS(1);
  3776. ITerrainModule tm = m_ScriptEngine.World.RequestModuleInterface<ITerrainModule>();
  3777. if (tm != null)
  3778. {
  3779. tm.ModifyTerrain(m_host.OwnerID, m_host.AbsolutePosition, (byte) brush, (byte) action, m_host.OwnerID);
  3780. }
  3781. }
  3782. public void llCollisionSound(string impact_sound, double impact_volume)
  3783. {
  3784. m_host.AddScriptLPS(1);
  3785. // TODO: Parameter check logic required.
  3786. m_host.CollisionSound = ScriptUtils.GetAssetIdFromKeyOrItemName(m_host, impact_sound, AssetType.Sound);
  3787. m_host.CollisionSoundVolume = (float)impact_volume;
  3788. }
  3789. public LSL_String llGetAnimation(string id)
  3790. {
  3791. // This should only return a value if the avatar is in the same region
  3792. m_host.AddScriptLPS(1);
  3793. UUID avatar = (UUID)id;
  3794. ScenePresence presence = World.GetScenePresence(avatar);
  3795. if (presence == null)
  3796. return "";
  3797. if (m_host.RegionHandle == presence.RegionHandle)
  3798. {
  3799. Dictionary<UUID, string> animationstateNames = DefaultAvatarAnimations.AnimStateNames;
  3800. if (presence != null)
  3801. {
  3802. AnimationSet currentAnims = presence.Animator.Animations;
  3803. string currentAnimationState = String.Empty;
  3804. if (animationstateNames.TryGetValue(currentAnims.ImplicitDefaultAnimation.AnimID, out currentAnimationState))
  3805. return currentAnimationState;
  3806. }
  3807. }
  3808. return String.Empty;
  3809. }
  3810. public void llMessageLinked(int linknumber, int num, string msg, string id)
  3811. {
  3812. m_host.AddScriptLPS(1);
  3813. List<SceneObjectPart> parts = GetLinkParts(linknumber);
  3814. UUID partItemID;
  3815. foreach (SceneObjectPart part in parts)
  3816. {
  3817. foreach (TaskInventoryItem item in part.Inventory.GetInventoryItems())
  3818. {
  3819. if (item.Type == ScriptBaseClass.INVENTORY_SCRIPT)
  3820. {
  3821. partItemID = item.ItemID;
  3822. int linkNumber = m_host.LinkNum;
  3823. if (m_host.ParentGroup.PrimCount == 1)
  3824. linkNumber = 0;
  3825. object[] resobj = new object[]
  3826. {
  3827. new LSL_Integer(linkNumber), new LSL_Integer(num), new LSL_String(msg), new LSL_String(id)
  3828. };
  3829. m_ScriptEngine.PostScriptEvent(partItemID,
  3830. new EventParams("link_message",
  3831. resobj, new DetectParams[0]));
  3832. }
  3833. }
  3834. }
  3835. }
  3836. public void llPushObject(string target, LSL_Vector impulse, LSL_Vector ang_impulse, int local)
  3837. {
  3838. m_host.AddScriptLPS(1);
  3839. bool pushrestricted = World.RegionInfo.RegionSettings.RestrictPushing;
  3840. bool pushAllowed = false;
  3841. bool pusheeIsAvatar = false;
  3842. UUID targetID = UUID.Zero;
  3843. if (!UUID.TryParse(target,out targetID))
  3844. return;
  3845. ScenePresence pusheeav = null;
  3846. Vector3 PusheePos = Vector3.Zero;
  3847. SceneObjectPart pusheeob = null;
  3848. ScenePresence avatar = World.GetScenePresence(targetID);
  3849. if (avatar != null)
  3850. {
  3851. pusheeIsAvatar = true;
  3852. // Pushee doesn't have a physics actor
  3853. if (avatar.PhysicsActor == null)
  3854. return;
  3855. // Pushee is in GodMode this pushing object isn't owned by them
  3856. if (avatar.GodLevel > 0 && m_host.OwnerID != targetID)
  3857. return;
  3858. pusheeav = avatar;
  3859. // Find pushee position
  3860. // Pushee Linked?
  3861. SceneObjectPart sitPart = pusheeav.ParentPart;
  3862. if (sitPart != null)
  3863. PusheePos = sitPart.AbsolutePosition;
  3864. else
  3865. PusheePos = pusheeav.AbsolutePosition;
  3866. }
  3867. if (!pusheeIsAvatar)
  3868. {
  3869. // not an avatar so push is not affected by parcel flags
  3870. pusheeob = World.GetSceneObjectPart((UUID)target);
  3871. // We can't find object
  3872. if (pusheeob == null)
  3873. return;
  3874. // Object not pushable. Not an attachment and has no physics component
  3875. if (!pusheeob.ParentGroup.IsAttachment && pusheeob.PhysActor == null)
  3876. return;
  3877. PusheePos = pusheeob.AbsolutePosition;
  3878. pushAllowed = true;
  3879. }
  3880. else
  3881. {
  3882. if (pushrestricted)
  3883. {
  3884. ILandObject targetlandObj = World.LandChannel.GetLandObject(PusheePos);
  3885. // We didn't find the parcel but region is push restricted so assume it is NOT ok
  3886. if (targetlandObj == null)
  3887. return;
  3888. // Need provisions for Group Owned here
  3889. if (m_host.OwnerID == targetlandObj.LandData.OwnerID ||
  3890. targetlandObj.LandData.IsGroupOwned || m_host.OwnerID == targetID)
  3891. {
  3892. pushAllowed = true;
  3893. }
  3894. }
  3895. else
  3896. {
  3897. ILandObject targetlandObj = World.LandChannel.GetLandObject(PusheePos);
  3898. if (targetlandObj == null)
  3899. {
  3900. // We didn't find the parcel but region isn't push restricted so assume it's ok
  3901. pushAllowed = true;
  3902. }
  3903. else
  3904. {
  3905. // Parcel push restriction
  3906. if ((targetlandObj.LandData.Flags & (uint)ParcelFlags.RestrictPushObject) == (uint)ParcelFlags.RestrictPushObject)
  3907. {
  3908. // Need provisions for Group Owned here
  3909. if (m_host.OwnerID == targetlandObj.LandData.OwnerID ||
  3910. targetlandObj.LandData.IsGroupOwned ||
  3911. m_host.OwnerID == targetID)
  3912. {
  3913. pushAllowed = true;
  3914. }
  3915. //ParcelFlags.RestrictPushObject
  3916. //pushAllowed = true;
  3917. }
  3918. else
  3919. {
  3920. // Parcel isn't push restricted
  3921. pushAllowed = true;
  3922. }
  3923. }
  3924. }
  3925. }
  3926. if (pushAllowed)
  3927. {
  3928. float distance = (PusheePos - m_host.AbsolutePosition).Length();
  3929. float distance_term = distance * distance * distance; // Script Energy
  3930. float pusher_mass = m_host.GetMass();
  3931. float PUSH_ATTENUATION_DISTANCE = 17f;
  3932. float PUSH_ATTENUATION_SCALE = 5f;
  3933. float distance_attenuation = 1f;
  3934. if (distance > PUSH_ATTENUATION_DISTANCE)
  3935. {
  3936. float normalized_units = 1f + (distance - PUSH_ATTENUATION_DISTANCE) / PUSH_ATTENUATION_SCALE;
  3937. distance_attenuation = 1f / normalized_units;
  3938. }
  3939. Vector3 applied_linear_impulse = impulse;
  3940. {
  3941. float impulse_length = applied_linear_impulse.Length();
  3942. float desired_energy = impulse_length * pusher_mass;
  3943. if (desired_energy > 0f)
  3944. desired_energy += distance_term;
  3945. float scaling_factor = 1f;
  3946. scaling_factor *= distance_attenuation;
  3947. applied_linear_impulse *= scaling_factor;
  3948. }
  3949. if (pusheeIsAvatar)
  3950. {
  3951. if (pusheeav != null)
  3952. {
  3953. PhysicsActor pa = pusheeav.PhysicsActor;
  3954. if (pa != null)
  3955. {
  3956. if (local != 0)
  3957. {
  3958. applied_linear_impulse *= m_host.GetWorldRotation();
  3959. }
  3960. pa.AddForce(applied_linear_impulse, true);
  3961. }
  3962. }
  3963. }
  3964. else
  3965. {
  3966. if (pusheeob != null)
  3967. {
  3968. if (pusheeob.PhysActor != null)
  3969. {
  3970. pusheeob.ApplyImpulse(applied_linear_impulse, local != 0);
  3971. }
  3972. }
  3973. }
  3974. }
  3975. }
  3976. public void llPassCollisions(int pass)
  3977. {
  3978. m_host.AddScriptLPS(1);
  3979. if (pass == 0)
  3980. {
  3981. m_host.PassCollisions = false;
  3982. }
  3983. else
  3984. {
  3985. m_host.PassCollisions = true;
  3986. }
  3987. }
  3988. public LSL_String llGetScriptName()
  3989. {
  3990. m_host.AddScriptLPS(1);
  3991. return m_item.Name != null ? m_item.Name : String.Empty;
  3992. }
  3993. public LSL_Integer llGetLinkNumberOfSides(int link)
  3994. {
  3995. m_host.AddScriptLPS(1);
  3996. SceneObjectPart linkedPart;
  3997. if (link == ScriptBaseClass.LINK_ROOT)
  3998. linkedPart = m_host.ParentGroup.RootPart;
  3999. else if (link == ScriptBaseClass.LINK_THIS)
  4000. linkedPart = m_host;
  4001. else
  4002. linkedPart = m_host.ParentGroup.GetLinkNumPart(link);
  4003. return GetNumberOfSides(linkedPart);
  4004. }
  4005. public LSL_Integer llGetNumberOfSides()
  4006. {
  4007. m_host.AddScriptLPS(1);
  4008. return GetNumberOfSides(m_host);
  4009. }
  4010. protected int GetNumberOfSides(SceneObjectPart part)
  4011. {
  4012. int sides = part.GetNumberOfSides();
  4013. if (part.GetPrimType() == PrimType.SPHERE && part.Shape.ProfileHollow > 0)
  4014. {
  4015. // Make up for a bug where LSL shows 4 sides rather than 2
  4016. sides += 2;
  4017. }
  4018. return sides;
  4019. }
  4020. /* The new / changed functions were tested with the following LSL script:
  4021. default
  4022. {
  4023. state_entry()
  4024. {
  4025. rotation rot = llEuler2Rot(<0,70,0> * DEG_TO_RAD);
  4026. llOwnerSay("to get here, we rotate over: "+ (string) llRot2Axis(rot));
  4027. llOwnerSay("and we rotate for: "+ (llRot2Angle(rot) * RAD_TO_DEG));
  4028. // convert back and forth between quaternion <-> vector and angle
  4029. rotation newrot = llAxisAngle2Rot(llRot2Axis(rot),llRot2Angle(rot));
  4030. llOwnerSay("Old rotation was: "+(string) rot);
  4031. llOwnerSay("re-converted rotation is: "+(string) newrot);
  4032. llSetRot(rot); // to check the parameters in the prim
  4033. }
  4034. }
  4035. */
  4036. // Xantor 29/apr/2008
  4037. // Returns rotation described by rotating angle radians about axis.
  4038. // q = cos(a/2) + i (x * sin(a/2)) + j (y * sin(a/2)) + k (z * sin(a/2))
  4039. public LSL_Rotation llAxisAngle2Rot(LSL_Vector axis, double angle)
  4040. {
  4041. m_host.AddScriptLPS(1);
  4042. double x, y, z, s, t;
  4043. s = Math.Cos(angle * 0.5);
  4044. t = Math.Sin(angle * 0.5); // temp value to avoid 2 more sin() calcs
  4045. axis = LSL_Vector.Norm(axis);
  4046. x = axis.x * t;
  4047. y = axis.y * t;
  4048. z = axis.z * t;
  4049. return new LSL_Rotation(x,y,z,s);
  4050. }
  4051. /// <summary>
  4052. /// Returns the axis of rotation for a quaternion
  4053. /// </summary>
  4054. /// <returns></returns>
  4055. /// <param name='rot'></param>
  4056. public LSL_Vector llRot2Axis(LSL_Rotation rot)
  4057. {
  4058. m_host.AddScriptLPS(1);
  4059. if (Math.Abs(rot.s) > 1) // normalization needed
  4060. rot.Normalize();
  4061. double s = Math.Sqrt(1 - rot.s * rot.s);
  4062. if (s < 0.001)
  4063. {
  4064. return new LSL_Vector(1, 0, 0);
  4065. }
  4066. else
  4067. {
  4068. double invS = 1.0 / s;
  4069. if (rot.s < 0) invS = -invS;
  4070. return new LSL_Vector(rot.x * invS, rot.y * invS, rot.z * invS);
  4071. }
  4072. }
  4073. // Returns the angle of a quaternion (see llRot2Axis for the axis)
  4074. public LSL_Float llRot2Angle(LSL_Rotation rot)
  4075. {
  4076. m_host.AddScriptLPS(1);
  4077. if (Math.Abs(rot.s) > 1) // normalization needed
  4078. rot.Normalize();
  4079. double angle = 2 * Math.Acos(rot.s);
  4080. if (angle > Math.PI)
  4081. angle = 2 * Math.PI - angle;
  4082. return angle;
  4083. }
  4084. public LSL_Float llAcos(double val)
  4085. {
  4086. m_host.AddScriptLPS(1);
  4087. return (double)Math.Acos(val);
  4088. }
  4089. public LSL_Float llAsin(double val)
  4090. {
  4091. m_host.AddScriptLPS(1);
  4092. return (double)Math.Asin(val);
  4093. }
  4094. // jcochran 5/jan/2012
  4095. public LSL_Float llAngleBetween(LSL_Rotation a, LSL_Rotation b)
  4096. {
  4097. m_host.AddScriptLPS(1);
  4098. double aa = (a.x * a.x + a.y * a.y + a.z * a.z + a.s * a.s);
  4099. double bb = (b.x * b.x + b.y * b.y + b.z * b.z + b.s * b.s);
  4100. double aa_bb = aa * bb;
  4101. if (aa_bb == 0) return 0.0;
  4102. double ab = (a.x * b.x + a.y * b.y + a.z * b.z + a.s * b.s);
  4103. double quotient = (ab * ab) / aa_bb;
  4104. if (quotient >= 1.0) return 0.0;
  4105. return Math.Acos(2 * quotient - 1);
  4106. }
  4107. public LSL_String llGetInventoryKey(string name)
  4108. {
  4109. m_host.AddScriptLPS(1);
  4110. TaskInventoryItem item = m_host.Inventory.GetInventoryItem(name);
  4111. if (item == null)
  4112. return UUID.Zero.ToString();
  4113. if ((item.CurrentPermissions
  4114. & (uint)(PermissionMask.Copy | PermissionMask.Transfer | PermissionMask.Modify))
  4115. == (uint)(PermissionMask.Copy | PermissionMask.Transfer | PermissionMask.Modify))
  4116. {
  4117. return item.AssetID.ToString();
  4118. }
  4119. return UUID.Zero.ToString();
  4120. }
  4121. public void llAllowInventoryDrop(int add)
  4122. {
  4123. m_host.AddScriptLPS(1);
  4124. if (add != 0)
  4125. m_host.ParentGroup.RootPart.AllowedDrop = true;
  4126. else
  4127. m_host.ParentGroup.RootPart.AllowedDrop = false;
  4128. // Update the object flags
  4129. m_host.ParentGroup.RootPart.aggregateScriptEvents();
  4130. }
  4131. public LSL_Vector llGetSunDirection()
  4132. {
  4133. m_host.AddScriptLPS(1);
  4134. LSL_Vector SunDoubleVector3;
  4135. Vector3 SunFloatVector3;
  4136. // sunPosition estate setting is set in OpenSim.Region.CoreModules.SunModule
  4137. // have to convert from Vector3 (float) to LSL_Vector (double)
  4138. SunFloatVector3 = World.RegionInfo.RegionSettings.SunVector;
  4139. SunDoubleVector3.x = (double)SunFloatVector3.X;
  4140. SunDoubleVector3.y = (double)SunFloatVector3.Y;
  4141. SunDoubleVector3.z = (double)SunFloatVector3.Z;
  4142. return SunDoubleVector3;
  4143. }
  4144. public LSL_Vector llGetTextureOffset(int face)
  4145. {
  4146. m_host.AddScriptLPS(1);
  4147. return GetTextureOffset(m_host, face);
  4148. }
  4149. protected LSL_Vector GetTextureOffset(SceneObjectPart part, int face)
  4150. {
  4151. Primitive.TextureEntry tex = part.Shape.Textures;
  4152. LSL_Vector offset = new LSL_Vector();
  4153. if (face == ScriptBaseClass.ALL_SIDES)
  4154. {
  4155. face = 0;
  4156. }
  4157. if (face >= 0 && face < GetNumberOfSides(part))
  4158. {
  4159. offset.x = tex.GetFace((uint)face).OffsetU;
  4160. offset.y = tex.GetFace((uint)face).OffsetV;
  4161. offset.z = 0.0;
  4162. return offset;
  4163. }
  4164. else
  4165. {
  4166. return offset;
  4167. }
  4168. }
  4169. public LSL_Vector llGetTextureScale(int side)
  4170. {
  4171. m_host.AddScriptLPS(1);
  4172. Primitive.TextureEntry tex = m_host.Shape.Textures;
  4173. LSL_Vector scale;
  4174. if (side == -1)
  4175. {
  4176. side = 0;
  4177. }
  4178. scale.x = tex.GetFace((uint)side).RepeatU;
  4179. scale.y = tex.GetFace((uint)side).RepeatV;
  4180. scale.z = 0.0;
  4181. return scale;
  4182. }
  4183. public LSL_Float llGetTextureRot(int face)
  4184. {
  4185. m_host.AddScriptLPS(1);
  4186. return GetTextureRot(m_host, face);
  4187. }
  4188. protected LSL_Float GetTextureRot(SceneObjectPart part, int face)
  4189. {
  4190. Primitive.TextureEntry tex = part.Shape.Textures;
  4191. if (face == -1)
  4192. {
  4193. face = 0;
  4194. }
  4195. if (face >= 0 && face < GetNumberOfSides(part))
  4196. {
  4197. return tex.GetFace((uint)face).Rotation;
  4198. }
  4199. else
  4200. {
  4201. return 0.0;
  4202. }
  4203. }
  4204. public LSL_Integer llSubStringIndex(string source, string pattern)
  4205. {
  4206. m_host.AddScriptLPS(1);
  4207. return source.IndexOf(pattern);
  4208. }
  4209. public LSL_String llGetOwnerKey(string id)
  4210. {
  4211. m_host.AddScriptLPS(1);
  4212. UUID key = new UUID();
  4213. if (UUID.TryParse(id, out key))
  4214. {
  4215. try
  4216. {
  4217. SceneObjectPart obj = World.GetSceneObjectPart(key);
  4218. if (obj == null)
  4219. return id; // the key is for an agent so just return the key
  4220. else
  4221. return obj.OwnerID.ToString();
  4222. }
  4223. catch (KeyNotFoundException)
  4224. {
  4225. return id; // The Object/Agent not in the region so just return the key
  4226. }
  4227. }
  4228. else
  4229. {
  4230. return UUID.Zero.ToString();
  4231. }
  4232. }
  4233. public LSL_Vector llGetCenterOfMass()
  4234. {
  4235. m_host.AddScriptLPS(1);
  4236. return new LSL_Vector(m_host.GetCenterOfMass());
  4237. }
  4238. public LSL_List llListSort(LSL_List src, int stride, int ascending)
  4239. {
  4240. m_host.AddScriptLPS(1);
  4241. if (stride <= 0)
  4242. {
  4243. stride = 1;
  4244. }
  4245. return src.Sort(stride, ascending);
  4246. }
  4247. public LSL_Integer llGetListLength(LSL_List src)
  4248. {
  4249. m_host.AddScriptLPS(1);
  4250. if (src == null)
  4251. {
  4252. return 0;
  4253. }
  4254. else
  4255. {
  4256. return src.Length;
  4257. }
  4258. }
  4259. public LSL_Integer llList2Integer(LSL_List src, int index)
  4260. {
  4261. m_host.AddScriptLPS(1);
  4262. if (index < 0)
  4263. {
  4264. index = src.Length + index;
  4265. }
  4266. if (index >= src.Length || index < 0)
  4267. {
  4268. return 0;
  4269. }
  4270. // Vectors & Rotations always return zero in SL, but
  4271. // keys don't always return zero, it seems to be a bit complex.
  4272. else if (src.Data[index] is LSL_Vector ||
  4273. src.Data[index] is LSL_Rotation)
  4274. {
  4275. return 0;
  4276. }
  4277. try
  4278. {
  4279. if (src.Data[index] is LSL_Integer)
  4280. return (LSL_Integer)src.Data[index];
  4281. else if (src.Data[index] is LSL_Float)
  4282. return Convert.ToInt32(((LSL_Float)src.Data[index]).value);
  4283. return new LSL_Integer(src.Data[index].ToString());
  4284. }
  4285. catch (FormatException)
  4286. {
  4287. return 0;
  4288. }
  4289. }
  4290. public LSL_Float llList2Float(LSL_List src, int index)
  4291. {
  4292. m_host.AddScriptLPS(1);
  4293. if (index < 0)
  4294. {
  4295. index = src.Length + index;
  4296. }
  4297. if (index >= src.Length || index < 0)
  4298. {
  4299. return 0.0;
  4300. }
  4301. // Vectors & Rotations always return zero in SL
  4302. else if (src.Data[index] is LSL_Vector ||
  4303. src.Data[index] is LSL_Rotation)
  4304. {
  4305. return 0;
  4306. }
  4307. // valid keys seem to get parsed as integers then converted to floats
  4308. else
  4309. {
  4310. UUID uuidt;
  4311. if (src.Data[index] is LSL_Key && UUID.TryParse(src.Data[index].ToString(), out uuidt))
  4312. {
  4313. return Convert.ToDouble(new LSL_Integer(src.Data[index].ToString()).value);
  4314. }
  4315. }
  4316. try
  4317. {
  4318. if (src.Data[index] is LSL_Integer)
  4319. return Convert.ToDouble(((LSL_Integer)src.Data[index]).value);
  4320. else if (src.Data[index] is LSL_Float)
  4321. return Convert.ToDouble(((LSL_Float)src.Data[index]).value);
  4322. else if (src.Data[index] is LSL_String)
  4323. return Convert.ToDouble(((LSL_String)src.Data[index]).m_string);
  4324. return Convert.ToDouble(src.Data[index]);
  4325. }
  4326. catch (FormatException)
  4327. {
  4328. return 0.0;
  4329. }
  4330. }
  4331. public LSL_String llList2String(LSL_List src, int index)
  4332. {
  4333. m_host.AddScriptLPS(1);
  4334. if (index < 0)
  4335. {
  4336. index = src.Length + index;
  4337. }
  4338. if (index >= src.Length || index < 0)
  4339. {
  4340. return String.Empty;
  4341. }
  4342. return src.Data[index].ToString();
  4343. }
  4344. public LSL_Key llList2Key(LSL_List src, int index)
  4345. {
  4346. m_host.AddScriptLPS(1);
  4347. if (index < 0)
  4348. {
  4349. index = src.Length + index;
  4350. }
  4351. if (index >= src.Length || index < 0)
  4352. {
  4353. return "";
  4354. }
  4355. // SL spits out an empty string for types other than key & string
  4356. // At the time of patching, LSL_Key is currently LSL_String,
  4357. // so the OR check may be a little redundant, but it's being done
  4358. // for completion and should LSL_Key ever be implemented
  4359. // as it's own struct
  4360. else if (!(src.Data[index] is LSL_String ||
  4361. src.Data[index] is LSL_Key))
  4362. {
  4363. return "";
  4364. }
  4365. return src.Data[index].ToString();
  4366. }
  4367. public LSL_Vector llList2Vector(LSL_List src, int index)
  4368. {
  4369. m_host.AddScriptLPS(1);
  4370. if (index < 0)
  4371. {
  4372. index = src.Length + index;
  4373. }
  4374. if (index >= src.Length || index < 0)
  4375. {
  4376. return new LSL_Vector(0, 0, 0);
  4377. }
  4378. if (src.Data[index].GetType() == typeof(LSL_Vector))
  4379. {
  4380. return (LSL_Vector)src.Data[index];
  4381. }
  4382. // SL spits always out ZERO_VECTOR for anything other than
  4383. // strings or vectors. Although keys always return ZERO_VECTOR,
  4384. // it is currently difficult to make the distinction between
  4385. // a string, a key as string and a string that by coincidence
  4386. // is a string, so we're going to leave that up to the
  4387. // LSL_Vector constructor.
  4388. else if (!(src.Data[index] is LSL_String ||
  4389. src.Data[index] is LSL_Vector))
  4390. {
  4391. return new LSL_Vector(0, 0, 0);
  4392. }
  4393. else
  4394. {
  4395. return new LSL_Vector(src.Data[index].ToString());
  4396. }
  4397. }
  4398. public LSL_Rotation llList2Rot(LSL_List src, int index)
  4399. {
  4400. m_host.AddScriptLPS(1);
  4401. if (index < 0)
  4402. {
  4403. index = src.Length + index;
  4404. }
  4405. if (index >= src.Length || index < 0)
  4406. {
  4407. return new LSL_Rotation(0, 0, 0, 1);
  4408. }
  4409. // SL spits always out ZERO_ROTATION for anything other than
  4410. // strings or vectors. Although keys always return ZERO_ROTATION,
  4411. // it is currently difficult to make the distinction between
  4412. // a string, a key as string and a string that by coincidence
  4413. // is a string, so we're going to leave that up to the
  4414. // LSL_Rotation constructor.
  4415. else if (!(src.Data[index] is LSL_String ||
  4416. src.Data[index] is LSL_Rotation))
  4417. {
  4418. return new LSL_Rotation(0, 0, 0, 1);
  4419. }
  4420. else if (src.Data[index].GetType() == typeof(LSL_Rotation))
  4421. {
  4422. return (LSL_Rotation)src.Data[index];
  4423. }
  4424. else
  4425. {
  4426. return new LSL_Rotation(src.Data[index].ToString());
  4427. }
  4428. }
  4429. public LSL_List llList2List(LSL_List src, int start, int end)
  4430. {
  4431. m_host.AddScriptLPS(1);
  4432. return src.GetSublist(start, end);
  4433. }
  4434. public LSL_List llDeleteSubList(LSL_List src, int start, int end)
  4435. {
  4436. return src.DeleteSublist(start, end);
  4437. }
  4438. public LSL_Integer llGetListEntryType(LSL_List src, int index)
  4439. {
  4440. m_host.AddScriptLPS(1);
  4441. if (index < 0)
  4442. {
  4443. index = src.Length + index;
  4444. }
  4445. if (index >= src.Length)
  4446. {
  4447. return 0;
  4448. }
  4449. if (src.Data[index] is LSL_Integer || src.Data[index] is Int32)
  4450. return 1;
  4451. if (src.Data[index] is LSL_Float || src.Data[index] is Single || src.Data[index] is Double)
  4452. return 2;
  4453. if (src.Data[index] is LSL_String || src.Data[index] is String)
  4454. {
  4455. UUID tuuid;
  4456. if (UUID.TryParse(src.Data[index].ToString(), out tuuid))
  4457. {
  4458. return 4;
  4459. }
  4460. else
  4461. {
  4462. return 3;
  4463. }
  4464. }
  4465. if (src.Data[index] is LSL_Vector)
  4466. return 5;
  4467. if (src.Data[index] is LSL_Rotation)
  4468. return 6;
  4469. if (src.Data[index] is LSL_List)
  4470. return 7;
  4471. return 0;
  4472. }
  4473. /// <summary>
  4474. /// Process the supplied list and return the
  4475. /// content of the list formatted as a comma
  4476. /// separated list. There is a space after
  4477. /// each comma.
  4478. /// </summary>
  4479. public LSL_String llList2CSV(LSL_List src)
  4480. {
  4481. m_host.AddScriptLPS(1);
  4482. return string.Join(", ",
  4483. (new List<object>(src.Data)).ConvertAll<string>(o =>
  4484. {
  4485. return o.ToString();
  4486. }).ToArray());
  4487. }
  4488. /// <summary>
  4489. /// The supplied string is scanned for commas
  4490. /// and converted into a list. Commas are only
  4491. /// effective if they are encountered outside
  4492. /// of '<' '>' delimiters. Any whitespace
  4493. /// before or after an element is trimmed.
  4494. /// </summary>
  4495. public LSL_List llCSV2List(string src)
  4496. {
  4497. LSL_List result = new LSL_List();
  4498. int parens = 0;
  4499. int start = 0;
  4500. int length = 0;
  4501. m_host.AddScriptLPS(1);
  4502. for (int i = 0; i < src.Length; i++)
  4503. {
  4504. switch (src[i])
  4505. {
  4506. case '<':
  4507. parens++;
  4508. length++;
  4509. break;
  4510. case '>':
  4511. if (parens > 0)
  4512. parens--;
  4513. length++;
  4514. break;
  4515. case ',':
  4516. if (parens == 0)
  4517. {
  4518. result.Add(new LSL_String(src.Substring(start,length).Trim()));
  4519. start += length+1;
  4520. length = 0;
  4521. }
  4522. else
  4523. {
  4524. length++;
  4525. }
  4526. break;
  4527. default:
  4528. length++;
  4529. break;
  4530. }
  4531. }
  4532. result.Add(new LSL_String(src.Substring(start,length).Trim()));
  4533. return result;
  4534. }
  4535. /// <summary>
  4536. /// Randomizes the list, be arbitrarily reordering
  4537. /// sublists of stride elements. As the stride approaches
  4538. /// the size of the list, the options become very
  4539. /// limited.
  4540. /// </summary>
  4541. /// <remarks>
  4542. /// This could take a while for very large list
  4543. /// sizes.
  4544. /// </remarks>
  4545. public LSL_List llListRandomize(LSL_List src, int stride)
  4546. {
  4547. LSL_List result;
  4548. Random rand = new Random();
  4549. int chunkk;
  4550. int[] chunks;
  4551. m_host.AddScriptLPS(1);
  4552. if (stride <= 0)
  4553. {
  4554. stride = 1;
  4555. }
  4556. // Stride MUST be a factor of the list length
  4557. // If not, then return the src list. This also
  4558. // traps those cases where stride > length.
  4559. if (src.Length != stride && src.Length%stride == 0)
  4560. {
  4561. chunkk = src.Length/stride;
  4562. chunks = new int[chunkk];
  4563. for (int i = 0; i < chunkk; i++)
  4564. chunks[i] = i;
  4565. // Knuth shuffle the chunkk index
  4566. for (int i = chunkk - 1; i >= 1; i--)
  4567. {
  4568. // Elect an unrandomized chunk to swap
  4569. int index = rand.Next(i + 1);
  4570. int tmp;
  4571. // and swap position with first unrandomized chunk
  4572. tmp = chunks[i];
  4573. chunks[i] = chunks[index];
  4574. chunks[index] = tmp;
  4575. }
  4576. // Construct the randomized list
  4577. result = new LSL_List();
  4578. for (int i = 0; i < chunkk; i++)
  4579. {
  4580. for (int j = 0; j < stride; j++)
  4581. {
  4582. result.Add(src.Data[chunks[i]*stride+j]);
  4583. }
  4584. }
  4585. }
  4586. else {
  4587. object[] array = new object[src.Length];
  4588. Array.Copy(src.Data, 0, array, 0, src.Length);
  4589. result = new LSL_List(array);
  4590. }
  4591. return result;
  4592. }
  4593. /// <summary>
  4594. /// Elements in the source list starting with 0 and then
  4595. /// every i+stride. If the stride is negative then the scan
  4596. /// is backwards producing an inverted result.
  4597. /// Only those elements that are also in the specified
  4598. /// range are included in the result.
  4599. /// </summary>
  4600. public LSL_List llList2ListStrided(LSL_List src, int start, int end, int stride)
  4601. {
  4602. LSL_List result = new LSL_List();
  4603. int[] si = new int[2];
  4604. int[] ei = new int[2];
  4605. bool twopass = false;
  4606. m_host.AddScriptLPS(1);
  4607. // First step is always to deal with negative indices
  4608. if (start < 0)
  4609. start = src.Length+start;
  4610. if (end < 0)
  4611. end = src.Length+end;
  4612. // Out of bounds indices are OK, just trim them
  4613. // accordingly
  4614. if (start > src.Length)
  4615. start = src.Length;
  4616. if (end > src.Length)
  4617. end = src.Length;
  4618. if (stride == 0)
  4619. stride = 1;
  4620. // There may be one or two ranges to be considered
  4621. if (start != end)
  4622. {
  4623. if (start <= end)
  4624. {
  4625. si[0] = start;
  4626. ei[0] = end;
  4627. }
  4628. else
  4629. {
  4630. si[1] = start;
  4631. ei[1] = src.Length;
  4632. si[0] = 0;
  4633. ei[0] = end;
  4634. twopass = true;
  4635. }
  4636. // The scan always starts from the beginning of the
  4637. // source list, but members are only selected if they
  4638. // fall within the specified sub-range. The specified
  4639. // range values are inclusive.
  4640. // A negative stride reverses the direction of the
  4641. // scan producing an inverted list as a result.
  4642. if (stride > 0)
  4643. {
  4644. for (int i = 0; i < src.Length; i += stride)
  4645. {
  4646. if (i<=ei[0] && i>=si[0])
  4647. result.Add(src.Data[i]);
  4648. if (twopass && i>=si[1] && i<=ei[1])
  4649. result.Add(src.Data[i]);
  4650. }
  4651. }
  4652. else if (stride < 0)
  4653. {
  4654. for (int i = src.Length - 1; i >= 0; i += stride)
  4655. {
  4656. if (i <= ei[0] && i >= si[0])
  4657. result.Add(src.Data[i]);
  4658. if (twopass && i >= si[1] && i <= ei[1])
  4659. result.Add(src.Data[i]);
  4660. }
  4661. }
  4662. }
  4663. else
  4664. {
  4665. if (start%stride == 0)
  4666. {
  4667. result.Add(src.Data[start]);
  4668. }
  4669. }
  4670. return result;
  4671. }
  4672. public LSL_Integer llGetRegionAgentCount()
  4673. {
  4674. m_host.AddScriptLPS(1);
  4675. return new LSL_Integer(World.GetRootAgentCount());
  4676. }
  4677. public LSL_Vector llGetRegionCorner()
  4678. {
  4679. m_host.AddScriptLPS(1);
  4680. return new LSL_Vector(World.RegionInfo.WorldLocX, World.RegionInfo.WorldLocY, 0);
  4681. }
  4682. /// <summary>
  4683. /// Insert the list identified by <paramref name="src"/> into the
  4684. /// list designated by <paramref name="dest"/> such that the first
  4685. /// new element has the index specified by <paramref name="index"/>
  4686. /// </summary>
  4687. public LSL_List llListInsertList(LSL_List dest, LSL_List src, int index)
  4688. {
  4689. LSL_List pref = null;
  4690. LSL_List suff = null;
  4691. m_host.AddScriptLPS(1);
  4692. if (index < 0)
  4693. {
  4694. index = index+dest.Length;
  4695. if (index < 0)
  4696. {
  4697. index = 0;
  4698. }
  4699. }
  4700. if (index != 0)
  4701. {
  4702. pref = dest.GetSublist(0,index-1);
  4703. if (index < dest.Length)
  4704. {
  4705. suff = dest.GetSublist(index,-1);
  4706. return pref + src + suff;
  4707. }
  4708. else
  4709. {
  4710. return pref + src;
  4711. }
  4712. }
  4713. else
  4714. {
  4715. if (index < dest.Length)
  4716. {
  4717. suff = dest.GetSublist(index,-1);
  4718. return src + suff;
  4719. }
  4720. else
  4721. {
  4722. return src;
  4723. }
  4724. }
  4725. }
  4726. /// <summary>
  4727. /// Returns the index of the first occurrence of test
  4728. /// in src.
  4729. /// </summary>
  4730. /// <param name="src">Source list</param>
  4731. /// <param name="test">List to search for</param>
  4732. /// <returns>
  4733. /// The index number of the point in src where test was found if it was found.
  4734. /// Otherwise returns -1
  4735. /// </returns>
  4736. public LSL_Integer llListFindList(LSL_List src, LSL_List test)
  4737. {
  4738. int index = -1;
  4739. int length = src.Length - test.Length + 1;
  4740. m_host.AddScriptLPS(1);
  4741. // If either list is empty, do not match
  4742. if (src.Length != 0 && test.Length != 0)
  4743. {
  4744. for (int i = 0; i < length; i++)
  4745. {
  4746. // Why this piece of insanity? This is because most script constants are C# value types (e.g. int)
  4747. // rather than wrapped LSL types. Such a script constant does not have int.Equal(LSL_Integer) code
  4748. // and so the comparison fails even if the LSL_Integer conceptually has the same value.
  4749. // Therefore, here we test Equals on both the source and destination objects.
  4750. // However, a future better approach may be use LSL struct script constants (e.g. LSL_Integer(1)).
  4751. if (src.Data[i].Equals(test.Data[0]) || test.Data[0].Equals(src.Data[i]))
  4752. {
  4753. int j;
  4754. for (j = 1; j < test.Length; j++)
  4755. if (!(src.Data[i+j].Equals(test.Data[j]) || test.Data[j].Equals(src.Data[i+j])))
  4756. break;
  4757. if (j == test.Length)
  4758. {
  4759. index = i;
  4760. break;
  4761. }
  4762. }
  4763. }
  4764. }
  4765. return index;
  4766. }
  4767. public LSL_String llGetObjectName()
  4768. {
  4769. m_host.AddScriptLPS(1);
  4770. return m_host.Name !=null ? m_host.Name : String.Empty;
  4771. }
  4772. public void llSetObjectName(string name)
  4773. {
  4774. m_host.AddScriptLPS(1);
  4775. m_host.Name = name != null ? name : String.Empty;
  4776. }
  4777. public LSL_String llGetDate()
  4778. {
  4779. m_host.AddScriptLPS(1);
  4780. DateTime date = DateTime.Now.ToUniversalTime();
  4781. string result = date.ToString("yyyy-MM-dd");
  4782. return result;
  4783. }
  4784. public LSL_Integer llEdgeOfWorld(LSL_Vector pos, LSL_Vector dir)
  4785. {
  4786. m_host.AddScriptLPS(1);
  4787. // edge will be used to pass the Region Coordinates offset
  4788. // we want to check for a neighboring sim
  4789. LSL_Vector edge = new LSL_Vector(0, 0, 0);
  4790. if (dir.x == 0)
  4791. {
  4792. if (dir.y == 0)
  4793. {
  4794. // Direction vector is 0,0 so return
  4795. // false since we're staying in the sim
  4796. return 0;
  4797. }
  4798. else
  4799. {
  4800. // Y is the only valid direction
  4801. edge.y = dir.y / Math.Abs(dir.y);
  4802. }
  4803. }
  4804. else
  4805. {
  4806. LSL_Float mag;
  4807. if (dir.x > 0)
  4808. {
  4809. mag = (World.RegionInfo.RegionSizeX - pos.x) / dir.x;
  4810. }
  4811. else
  4812. {
  4813. mag = (pos.x/dir.x);
  4814. }
  4815. mag = Math.Abs(mag);
  4816. edge.y = pos.y + (dir.y * mag);
  4817. if (edge.y > World.RegionInfo.RegionSizeY || edge.y < 0)
  4818. {
  4819. // Y goes out of bounds first
  4820. edge.y = dir.y / Math.Abs(dir.y);
  4821. }
  4822. else
  4823. {
  4824. // X goes out of bounds first or its a corner exit
  4825. edge.y = 0;
  4826. edge.x = dir.x / Math.Abs(dir.x);
  4827. }
  4828. }
  4829. List<GridRegion> neighbors = World.GridService.GetNeighbours(World.RegionInfo.ScopeID, World.RegionInfo.RegionID);
  4830. uint neighborX = World.RegionInfo.RegionLocX + (uint)dir.x;
  4831. uint neighborY = World.RegionInfo.RegionLocY + (uint)dir.y;
  4832. foreach (GridRegion sri in neighbors)
  4833. {
  4834. if (sri.RegionCoordX == neighborX && sri.RegionCoordY == neighborY)
  4835. return 0;
  4836. }
  4837. return 1;
  4838. }
  4839. /// <summary>
  4840. /// Not fully implemented yet. Still to do:-
  4841. /// AGENT_BUSY
  4842. /// Remove as they are done
  4843. /// </summary>
  4844. public LSL_Integer llGetAgentInfo(string id)
  4845. {
  4846. m_host.AddScriptLPS(1);
  4847. UUID key = new UUID();
  4848. if (!UUID.TryParse(id, out key))
  4849. {
  4850. return 0;
  4851. }
  4852. int flags = 0;
  4853. ScenePresence agent = World.GetScenePresence(key);
  4854. if (agent == null)
  4855. {
  4856. return 0;
  4857. }
  4858. if (agent.IsChildAgent)
  4859. return 0; // Fail if they are not in the same region
  4860. // note: in OpenSim, sitting seems to cancel AGENT_ALWAYS_RUN, unlike SL
  4861. if (agent.SetAlwaysRun)
  4862. {
  4863. flags |= ScriptBaseClass.AGENT_ALWAYS_RUN;
  4864. }
  4865. if (agent.HasAttachments())
  4866. {
  4867. flags |= ScriptBaseClass.AGENT_ATTACHMENTS;
  4868. if (agent.HasScriptedAttachments())
  4869. flags |= ScriptBaseClass.AGENT_SCRIPTED;
  4870. }
  4871. if ((agent.AgentControlFlags & (uint)AgentManager.ControlFlags.AGENT_CONTROL_FLY) != 0)
  4872. {
  4873. flags |= ScriptBaseClass.AGENT_FLYING;
  4874. flags |= ScriptBaseClass.AGENT_IN_AIR; // flying always implies in-air, even if colliding with e.g. a wall
  4875. }
  4876. if ((agent.AgentControlFlags & (uint)AgentManager.ControlFlags.AGENT_CONTROL_AWAY) != 0)
  4877. {
  4878. flags |= ScriptBaseClass.AGENT_AWAY;
  4879. }
  4880. // seems to get unset, even if in mouselook, when avatar is sitting on a prim???
  4881. if ((agent.AgentControlFlags & (uint)AgentManager.ControlFlags.AGENT_CONTROL_MOUSELOOK) != 0)
  4882. {
  4883. flags |= ScriptBaseClass.AGENT_MOUSELOOK;
  4884. }
  4885. if ((agent.State & (byte)AgentState.Typing) != (byte)0)
  4886. {
  4887. flags |= ScriptBaseClass.AGENT_TYPING;
  4888. }
  4889. string agentMovementAnimation = agent.Animator.CurrentMovementAnimation;
  4890. if (agentMovementAnimation == "CROUCH")
  4891. {
  4892. flags |= ScriptBaseClass.AGENT_CROUCHING;
  4893. }
  4894. if (agentMovementAnimation == "WALK" || agentMovementAnimation == "CROUCHWALK")
  4895. {
  4896. flags |= ScriptBaseClass.AGENT_WALKING;
  4897. }
  4898. // not colliding implies in air. Note: flying also implies in-air, even if colliding (see above)
  4899. // note: AGENT_IN_AIR and AGENT_WALKING seem to be mutually exclusive states in SL.
  4900. // note: this may need some tweaking when walking downhill. you "fall down" for a brief instant
  4901. // and don't collide when walking downhill, which instantly registers as in-air, briefly. should
  4902. // there be some minimum non-collision threshold time before claiming the avatar is in-air?
  4903. if ((flags & ScriptBaseClass.AGENT_WALKING) == 0 && !agent.IsColliding )
  4904. {
  4905. flags |= ScriptBaseClass.AGENT_IN_AIR;
  4906. }
  4907. if (agent.ParentPart != null)
  4908. {
  4909. flags |= ScriptBaseClass.AGENT_ON_OBJECT;
  4910. flags |= ScriptBaseClass.AGENT_SITTING;
  4911. }
  4912. if (agent.Animator.Animations.ImplicitDefaultAnimation.AnimID
  4913. == DefaultAvatarAnimations.AnimsUUID["SIT_GROUND_CONSTRAINED"])
  4914. {
  4915. flags |= ScriptBaseClass.AGENT_SITTING;
  4916. }
  4917. return flags;
  4918. }
  4919. public LSL_String llGetAgentLanguage(string id)
  4920. {
  4921. // This should only return a value if the avatar is in the same region
  4922. //ckrinke 1-30-09 : This needs to parse the XMLRPC language field supplied
  4923. //by the client at login. Currently returning only en-us until our I18N
  4924. //effort gains momentum
  4925. m_host.AddScriptLPS(1);
  4926. return "en-us";
  4927. }
  4928. /// <summary>
  4929. /// http://wiki.secondlife.com/wiki/LlGetAgentList
  4930. /// The list of options is currently not used in SL
  4931. /// scope is one of:-
  4932. /// AGENT_LIST_REGION - all in the region
  4933. /// AGENT_LIST_PARCEL - all in the same parcel as the scripted object
  4934. /// AGENT_LIST_PARCEL_OWNER - all in any parcel owned by the owner of the
  4935. /// current parcel.
  4936. /// </summary>
  4937. public LSL_List llGetAgentList(LSL_Integer scope, LSL_List options)
  4938. {
  4939. m_host.AddScriptLPS(1);
  4940. // the constants are 1, 2 and 4 so bits are being set, but you
  4941. // get an error "INVALID_SCOPE" if it is anything but 1, 2 and 4
  4942. bool regionWide = scope == ScriptBaseClass.AGENT_LIST_REGION;
  4943. bool parcelOwned = scope == ScriptBaseClass.AGENT_LIST_PARCEL_OWNER;
  4944. bool parcel = scope == ScriptBaseClass.AGENT_LIST_PARCEL;
  4945. LSL_List result = new LSL_List();
  4946. if (!regionWide && !parcelOwned && !parcel)
  4947. {
  4948. result.Add("INVALID_SCOPE");
  4949. return result;
  4950. }
  4951. ILandObject land;
  4952. UUID id = UUID.Zero;
  4953. if (parcel || parcelOwned)
  4954. {
  4955. land = World.LandChannel.GetLandObject(m_host.ParentGroup.RootPart.GetWorldPosition());
  4956. if (land == null)
  4957. {
  4958. id = UUID.Zero;
  4959. }
  4960. else
  4961. {
  4962. if (parcelOwned)
  4963. {
  4964. id = land.LandData.OwnerID;
  4965. }
  4966. else
  4967. {
  4968. id = land.LandData.GlobalID;
  4969. }
  4970. }
  4971. }
  4972. World.ForEachRootScenePresence(
  4973. delegate (ScenePresence ssp)
  4974. {
  4975. // Gods are not listed in SL
  4976. if (!ssp.IsDeleted && ssp.GodLevel == 0.0 && !ssp.IsChildAgent)
  4977. {
  4978. if (!regionWide)
  4979. {
  4980. land = World.LandChannel.GetLandObject(ssp.AbsolutePosition);
  4981. if (land != null)
  4982. {
  4983. if (parcelOwned && land.LandData.OwnerID == id ||
  4984. parcel && land.LandData.GlobalID == id)
  4985. {
  4986. result.Add(new LSL_Key(ssp.UUID.ToString()));
  4987. }
  4988. }
  4989. }
  4990. else
  4991. {
  4992. result.Add(new LSL_Key(ssp.UUID.ToString()));
  4993. }
  4994. }
  4995. // Maximum of 100 results
  4996. if (result.Length > 99)
  4997. {
  4998. return;
  4999. }
  5000. }
  5001. );
  5002. return result;
  5003. }
  5004. public void llAdjustSoundVolume(double volume)
  5005. {
  5006. m_host.AddScriptLPS(1);
  5007. m_host.AdjustSoundGain(volume);
  5008. ScriptSleep(100);
  5009. }
  5010. public void llSetSoundRadius(double radius)
  5011. {
  5012. m_host.AddScriptLPS(1);
  5013. m_host.SoundRadius = radius;
  5014. }
  5015. public LSL_String llKey2Name(string id)
  5016. {
  5017. m_host.AddScriptLPS(1);
  5018. UUID key = new UUID();
  5019. if (UUID.TryParse(id,out key))
  5020. {
  5021. ScenePresence presence = World.GetScenePresence(key);
  5022. if (presence != null)
  5023. {
  5024. return presence.ControllingClient.Name;
  5025. //return presence.Name;
  5026. }
  5027. if (World.GetSceneObjectPart(key) != null)
  5028. {
  5029. return World.GetSceneObjectPart(key).Name;
  5030. }
  5031. }
  5032. return String.Empty;
  5033. }
  5034. public void llSetTextureAnim(int mode, int face, int sizex, int sizey, double start, double length, double rate)
  5035. {
  5036. m_host.AddScriptLPS(1);
  5037. SetTextureAnim(m_host, mode, face, sizex, sizey, start, length, rate);
  5038. }
  5039. public void llSetLinkTextureAnim(int linknumber, int mode, int face, int sizex, int sizey, double start, double length, double rate)
  5040. {
  5041. m_host.AddScriptLPS(1);
  5042. List<SceneObjectPart> parts = GetLinkParts(linknumber);
  5043. foreach (SceneObjectPart part in parts)
  5044. {
  5045. SetTextureAnim(part, mode, face, sizex, sizey, start, length, rate);
  5046. }
  5047. }
  5048. private void SetTextureAnim(SceneObjectPart part, int mode, int face, int sizex, int sizey, double start, double length, double rate)
  5049. {
  5050. Primitive.TextureAnimation pTexAnim = new Primitive.TextureAnimation();
  5051. pTexAnim.Flags = (Primitive.TextureAnimMode)mode;
  5052. //ALL_SIDES
  5053. if (face == ScriptBaseClass.ALL_SIDES)
  5054. face = 255;
  5055. pTexAnim.Face = (uint)face;
  5056. pTexAnim.Length = (float)length;
  5057. pTexAnim.Rate = (float)rate;
  5058. pTexAnim.SizeX = (uint)sizex;
  5059. pTexAnim.SizeY = (uint)sizey;
  5060. pTexAnim.Start = (float)start;
  5061. part.AddTextureAnimation(pTexAnim);
  5062. part.SendFullUpdateToAllClients();
  5063. part.ParentGroup.HasGroupChanged = true;
  5064. }
  5065. public void llTriggerSoundLimited(string sound, double volume, LSL_Vector top_north_east,
  5066. LSL_Vector bottom_south_west)
  5067. {
  5068. m_host.AddScriptLPS(1);
  5069. if (m_SoundModule != null)
  5070. {
  5071. m_SoundModule.TriggerSoundLimited(m_host.UUID,
  5072. ScriptUtils.GetAssetIdFromKeyOrItemName(m_host, sound, AssetType.Sound), volume,
  5073. bottom_south_west, top_north_east);
  5074. }
  5075. }
  5076. public void llEjectFromLand(string pest)
  5077. {
  5078. m_host.AddScriptLPS(1);
  5079. UUID agentID = new UUID();
  5080. if (UUID.TryParse(pest, out agentID))
  5081. {
  5082. ScenePresence presence = World.GetScenePresence(agentID);
  5083. if (presence != null)
  5084. {
  5085. // agent must be over the owners land
  5086. ILandObject land = World.LandChannel.GetLandObject(presence.AbsolutePosition);
  5087. if (land == null)
  5088. return;
  5089. if (m_host.OwnerID == land.LandData.OwnerID)
  5090. {
  5091. World.TeleportClientHome(agentID, presence.ControllingClient);
  5092. }
  5093. }
  5094. }
  5095. ScriptSleep(5000);
  5096. }
  5097. public LSL_Integer llOverMyLand(string id)
  5098. {
  5099. m_host.AddScriptLPS(1);
  5100. UUID key = new UUID();
  5101. if (UUID.TryParse(id, out key))
  5102. {
  5103. ScenePresence presence = World.GetScenePresence(key);
  5104. if (presence != null) // object is an avatar
  5105. {
  5106. if (m_host.OwnerID == World.LandChannel.GetLandObject(presence.AbsolutePosition).LandData.OwnerID)
  5107. return 1;
  5108. }
  5109. else // object is not an avatar
  5110. {
  5111. SceneObjectPart obj = World.GetSceneObjectPart(key);
  5112. if (obj != null)
  5113. {
  5114. if (m_host.OwnerID == World.LandChannel.GetLandObject(obj.AbsolutePosition).LandData.OwnerID)
  5115. return 1;
  5116. }
  5117. }
  5118. }
  5119. return 0;
  5120. }
  5121. public LSL_String llGetLandOwnerAt(LSL_Vector pos)
  5122. {
  5123. m_host.AddScriptLPS(1);
  5124. ILandObject land = World.LandChannel.GetLandObject((float)pos.x, (float)pos.y);
  5125. if (land == null)
  5126. return UUID.Zero.ToString();
  5127. return land.LandData.OwnerID.ToString();
  5128. }
  5129. /// <summary>
  5130. /// According to http://lslwiki.net/lslwiki/wakka.php?wakka=llGetAgentSize
  5131. /// only the height of avatars vary and that says:
  5132. /// Width (x) and depth (y) are constant. (0.45m and 0.6m respectively).
  5133. /// </summary>
  5134. public LSL_Vector llGetAgentSize(string id)
  5135. {
  5136. m_host.AddScriptLPS(1);
  5137. ScenePresence avatar = World.GetScenePresence((UUID)id);
  5138. LSL_Vector agentSize;
  5139. if (avatar == null || avatar.IsChildAgent) // Fail if not in the same region
  5140. {
  5141. agentSize = ScriptBaseClass.ZERO_VECTOR;
  5142. }
  5143. else
  5144. {
  5145. agentSize = GetAgentSize(avatar);
  5146. }
  5147. return agentSize;
  5148. }
  5149. public LSL_Integer llSameGroup(string agent)
  5150. {
  5151. m_host.AddScriptLPS(1);
  5152. UUID agentId = new UUID();
  5153. if (!UUID.TryParse(agent, out agentId))
  5154. return new LSL_Integer(0);
  5155. ScenePresence presence = World.GetScenePresence(agentId);
  5156. if (presence == null || presence.IsChildAgent) // Return flase for child agents
  5157. return new LSL_Integer(0);
  5158. IClientAPI client = presence.ControllingClient;
  5159. if (m_host.GroupID == client.ActiveGroupId)
  5160. return new LSL_Integer(1);
  5161. else
  5162. return new LSL_Integer(0);
  5163. }
  5164. public void llUnSit(string id)
  5165. {
  5166. m_host.AddScriptLPS(1);
  5167. UUID key = new UUID();
  5168. if (UUID.TryParse(id, out key))
  5169. {
  5170. ScenePresence av = World.GetScenePresence(key);
  5171. if (av != null)
  5172. {
  5173. if (llAvatarOnSitTarget() == id)
  5174. {
  5175. // if the avatar is sitting on this object, then
  5176. // we can unsit them. We don't want random scripts unsitting random people
  5177. // Lets avoid the popcorn avatar scenario.
  5178. av.StandUp();
  5179. }
  5180. else
  5181. {
  5182. // If the object owner also owns the parcel
  5183. // or
  5184. // if the land is group owned and the object is group owned by the same group
  5185. // or
  5186. // if the object is owned by a person with estate access.
  5187. ILandObject parcel = World.LandChannel.GetLandObject(av.AbsolutePosition);
  5188. if (parcel != null)
  5189. {
  5190. if (m_host.OwnerID == parcel.LandData.OwnerID ||
  5191. (m_host.OwnerID == m_host.GroupID && m_host.GroupID == parcel.LandData.GroupID
  5192. && parcel.LandData.IsGroupOwned) || World.Permissions.IsGod(m_host.OwnerID))
  5193. {
  5194. av.StandUp();
  5195. }
  5196. }
  5197. }
  5198. }
  5199. }
  5200. }
  5201. public LSL_Vector llGroundSlope(LSL_Vector offset)
  5202. {
  5203. m_host.AddScriptLPS(1);
  5204. //Get the slope normal. This gives us the equation of the plane tangent to the slope.
  5205. LSL_Vector vsn = llGroundNormal(offset);
  5206. //Plug the x,y coordinates of the slope normal into the equation of the plane to get
  5207. //the height of that point on the plane. The resulting vector gives the slope.
  5208. Vector3 vsl = vsn;
  5209. vsl.Z = (float)(((vsn.x * vsn.x) + (vsn.y * vsn.y)) / (-1 * vsn.z));
  5210. vsl.Normalize();
  5211. //Normalization might be overkill here
  5212. vsn.x = vsl.X;
  5213. vsn.y = vsl.Y;
  5214. vsn.z = vsl.Z;
  5215. return vsn;
  5216. }
  5217. public LSL_Vector llGroundNormal(LSL_Vector offset)
  5218. {
  5219. m_host.AddScriptLPS(1);
  5220. Vector3 pos = m_host.GetWorldPosition() + (Vector3)offset;
  5221. // Clamp to valid position
  5222. if (pos.X < 0)
  5223. pos.X = 0;
  5224. else if (pos.X >= World.Heightmap.Width)
  5225. pos.X = World.Heightmap.Width - 1;
  5226. if (pos.Y < 0)
  5227. pos.Y = 0;
  5228. else if (pos.Y >= World.Heightmap.Height)
  5229. pos.Y = World.Heightmap.Height - 1;
  5230. //Find two points in addition to the position to define a plane
  5231. Vector3 p0 = new Vector3(pos.X, pos.Y,
  5232. (float)World.Heightmap[(int)pos.X, (int)pos.Y]);
  5233. Vector3 p1 = new Vector3();
  5234. Vector3 p2 = new Vector3();
  5235. if ((pos.X + 1.0f) >= World.Heightmap.Width)
  5236. p1 = new Vector3(pos.X + 1.0f, pos.Y,
  5237. (float)World.Heightmap[(int)pos.X, (int)pos.Y]);
  5238. else
  5239. p1 = new Vector3(pos.X + 1.0f, pos.Y,
  5240. (float)World.Heightmap[(int)(pos.X + 1.0f), (int)pos.Y]);
  5241. if ((pos.Y + 1.0f) >= World.Heightmap.Height)
  5242. p2 = new Vector3(pos.X, pos.Y + 1.0f,
  5243. (float)World.Heightmap[(int)pos.X, (int)pos.Y]);
  5244. else
  5245. p2 = new Vector3(pos.X, pos.Y + 1.0f,
  5246. (float)World.Heightmap[(int)pos.X, (int)(pos.Y + 1.0f)]);
  5247. //Find normalized vectors from p0 to p1 and p0 to p2
  5248. Vector3 v0 = new Vector3(p1.X - p0.X, p1.Y - p0.Y, p1.Z - p0.Z);
  5249. Vector3 v1 = new Vector3(p2.X - p0.X, p2.Y - p0.Y, p2.Z - p0.Z);
  5250. v0.Normalize();
  5251. v1.Normalize();
  5252. //Find the cross product of the vectors (the slope normal).
  5253. Vector3 vsn = new Vector3();
  5254. vsn.X = (v0.Y * v1.Z) - (v0.Z * v1.Y);
  5255. vsn.Y = (v0.Z * v1.X) - (v0.X * v1.Z);
  5256. vsn.Z = (v0.X * v1.Y) - (v0.Y * v1.X);
  5257. vsn.Normalize();
  5258. //I believe the crossproduct of two normalized vectors is a normalized vector so
  5259. //this normalization may be overkill
  5260. return new LSL_Vector(vsn);
  5261. }
  5262. public LSL_Vector llGroundContour(LSL_Vector offset)
  5263. {
  5264. m_host.AddScriptLPS(1);
  5265. LSL_Vector x = llGroundSlope(offset);
  5266. return new LSL_Vector(-x.y, x.x, 0.0);
  5267. }
  5268. public LSL_Integer llGetAttached()
  5269. {
  5270. m_host.AddScriptLPS(1);
  5271. return m_host.ParentGroup.AttachmentPoint;
  5272. }
  5273. public virtual LSL_Integer llGetFreeMemory()
  5274. {
  5275. m_host.AddScriptLPS(1);
  5276. // Make scripts designed for LSO happy
  5277. return 16384;
  5278. }
  5279. public LSL_Integer llGetFreeURLs()
  5280. {
  5281. m_host.AddScriptLPS(1);
  5282. if (m_UrlModule != null)
  5283. return new LSL_Integer(m_UrlModule.GetFreeUrls());
  5284. return new LSL_Integer(0);
  5285. }
  5286. public LSL_String llGetRegionName()
  5287. {
  5288. m_host.AddScriptLPS(1);
  5289. return World.RegionInfo.RegionName;
  5290. }
  5291. public LSL_Float llGetRegionTimeDilation()
  5292. {
  5293. m_host.AddScriptLPS(1);
  5294. return (double)World.TimeDilation;
  5295. }
  5296. /// <summary>
  5297. /// Returns the value reported in the client Statistics window
  5298. /// </summary>
  5299. public LSL_Float llGetRegionFPS()
  5300. {
  5301. m_host.AddScriptLPS(1);
  5302. return World.StatsReporter.LastReportedSimFPS;
  5303. }
  5304. /* particle system rules should be coming into this routine as doubles, that is
  5305. rule[0] should be an integer from this list and rule[1] should be the arg
  5306. for the same integer. wiki.secondlife.com has most of this mapping, but some
  5307. came from http://www.caligari-designs.com/p4u2
  5308. We iterate through the list for 'Count' elements, incrementing by two for each
  5309. iteration and set the members of Primitive.ParticleSystem, one at a time.
  5310. */
  5311. public enum PrimitiveRule : int
  5312. {
  5313. PSYS_PART_FLAGS = 0,
  5314. PSYS_PART_START_COLOR = 1,
  5315. PSYS_PART_START_ALPHA = 2,
  5316. PSYS_PART_END_COLOR = 3,
  5317. PSYS_PART_END_ALPHA = 4,
  5318. PSYS_PART_START_SCALE = 5,
  5319. PSYS_PART_END_SCALE = 6,
  5320. PSYS_PART_MAX_AGE = 7,
  5321. PSYS_SRC_ACCEL = 8,
  5322. PSYS_SRC_PATTERN = 9,
  5323. PSYS_SRC_INNERANGLE = 10,
  5324. PSYS_SRC_OUTERANGLE = 11,
  5325. PSYS_SRC_TEXTURE = 12,
  5326. PSYS_SRC_BURST_RATE = 13,
  5327. PSYS_SRC_BURST_PART_COUNT = 15,
  5328. PSYS_SRC_BURST_RADIUS = 16,
  5329. PSYS_SRC_BURST_SPEED_MIN = 17,
  5330. PSYS_SRC_BURST_SPEED_MAX = 18,
  5331. PSYS_SRC_MAX_AGE = 19,
  5332. PSYS_SRC_TARGET_KEY = 20,
  5333. PSYS_SRC_OMEGA = 21,
  5334. PSYS_SRC_ANGLE_BEGIN = 22,
  5335. PSYS_SRC_ANGLE_END = 23,
  5336. PSYS_PART_BLEND_FUNC_SOURCE = 24,
  5337. PSYS_PART_BLEND_FUNC_DEST = 25,
  5338. PSYS_PART_START_GLOW = 26,
  5339. PSYS_PART_END_GLOW = 27
  5340. }
  5341. internal Primitive.ParticleSystem.ParticleDataFlags ConvertUINTtoFlags(uint flags)
  5342. {
  5343. Primitive.ParticleSystem.ParticleDataFlags returnval = Primitive.ParticleSystem.ParticleDataFlags.None;
  5344. return returnval;
  5345. }
  5346. protected Primitive.ParticleSystem getNewParticleSystemWithSLDefaultValues()
  5347. {
  5348. Primitive.ParticleSystem ps = new Primitive.ParticleSystem();
  5349. // TODO find out about the other defaults and add them here
  5350. ps.PartStartColor = new Color4(1.0f, 1.0f, 1.0f, 1.0f);
  5351. ps.PartEndColor = new Color4(1.0f, 1.0f, 1.0f, 1.0f);
  5352. ps.PartStartScaleX = 1.0f;
  5353. ps.PartStartScaleY = 1.0f;
  5354. ps.PartEndScaleX = 1.0f;
  5355. ps.PartEndScaleY = 1.0f;
  5356. ps.BurstSpeedMin = 1.0f;
  5357. ps.BurstSpeedMax = 1.0f;
  5358. ps.BurstRate = 0.1f;
  5359. ps.PartMaxAge = 10.0f;
  5360. ps.BurstPartCount = 1;
  5361. ps.BlendFuncSource = ScriptBaseClass.PSYS_PART_BF_SOURCE_ALPHA;
  5362. ps.BlendFuncDest = ScriptBaseClass.PSYS_PART_BF_ONE_MINUS_SOURCE_ALPHA;
  5363. ps.PartStartGlow = 0.0f;
  5364. ps.PartEndGlow = 0.0f;
  5365. return ps;
  5366. }
  5367. public void llLinkParticleSystem(int linknumber, LSL_List rules)
  5368. {
  5369. m_host.AddScriptLPS(1);
  5370. List<SceneObjectPart> parts = GetLinkParts(linknumber);
  5371. foreach (SceneObjectPart part in parts)
  5372. {
  5373. SetParticleSystem(part, rules);
  5374. }
  5375. }
  5376. public void llParticleSystem(LSL_List rules)
  5377. {
  5378. m_host.AddScriptLPS(1);
  5379. SetParticleSystem(m_host, rules);
  5380. }
  5381. private void SetParticleSystem(SceneObjectPart part, LSL_List rules)
  5382. {
  5383. if (rules.Length == 0)
  5384. {
  5385. part.RemoveParticleSystem();
  5386. part.ParentGroup.HasGroupChanged = true;
  5387. }
  5388. else
  5389. {
  5390. Primitive.ParticleSystem prules = getNewParticleSystemWithSLDefaultValues();
  5391. LSL_Vector tempv = new LSL_Vector();
  5392. float tempf = 0;
  5393. int tmpi = 0;
  5394. for (int i = 0; i < rules.Length; i += 2)
  5395. {
  5396. switch (rules.GetLSLIntegerItem(i))
  5397. {
  5398. case (int)ScriptBaseClass.PSYS_PART_FLAGS:
  5399. prules.PartDataFlags = (Primitive.ParticleSystem.ParticleDataFlags)(uint)rules.GetLSLIntegerItem(i + 1);
  5400. break;
  5401. case (int)ScriptBaseClass.PSYS_PART_START_COLOR:
  5402. tempv = rules.GetVector3Item(i + 1);
  5403. prules.PartStartColor.R = (float)tempv.x;
  5404. prules.PartStartColor.G = (float)tempv.y;
  5405. prules.PartStartColor.B = (float)tempv.z;
  5406. break;
  5407. case (int)ScriptBaseClass.PSYS_PART_START_ALPHA:
  5408. tempf = (float)rules.GetLSLFloatItem(i + 1);
  5409. prules.PartStartColor.A = tempf;
  5410. break;
  5411. case (int)ScriptBaseClass.PSYS_PART_END_COLOR:
  5412. tempv = rules.GetVector3Item(i + 1);
  5413. prules.PartEndColor.R = (float)tempv.x;
  5414. prules.PartEndColor.G = (float)tempv.y;
  5415. prules.PartEndColor.B = (float)tempv.z;
  5416. break;
  5417. case (int)ScriptBaseClass.PSYS_PART_END_ALPHA:
  5418. tempf = (float)rules.GetLSLFloatItem(i + 1);
  5419. prules.PartEndColor.A = tempf;
  5420. break;
  5421. case (int)ScriptBaseClass.PSYS_PART_START_SCALE:
  5422. tempv = rules.GetVector3Item(i + 1);
  5423. prules.PartStartScaleX = (float)tempv.x;
  5424. prules.PartStartScaleY = (float)tempv.y;
  5425. break;
  5426. case (int)ScriptBaseClass.PSYS_PART_END_SCALE:
  5427. tempv = rules.GetVector3Item(i + 1);
  5428. prules.PartEndScaleX = (float)tempv.x;
  5429. prules.PartEndScaleY = (float)tempv.y;
  5430. break;
  5431. case (int)ScriptBaseClass.PSYS_PART_MAX_AGE:
  5432. tempf = (float)rules.GetLSLFloatItem(i + 1);
  5433. prules.PartMaxAge = tempf;
  5434. break;
  5435. case (int)ScriptBaseClass.PSYS_SRC_ACCEL:
  5436. tempv = rules.GetVector3Item(i + 1);
  5437. prules.PartAcceleration.X = (float)tempv.x;
  5438. prules.PartAcceleration.Y = (float)tempv.y;
  5439. prules.PartAcceleration.Z = (float)tempv.z;
  5440. break;
  5441. case (int)ScriptBaseClass.PSYS_SRC_PATTERN:
  5442. tmpi = (int)rules.GetLSLIntegerItem(i + 1);
  5443. prules.Pattern = (Primitive.ParticleSystem.SourcePattern)tmpi;
  5444. break;
  5445. // PSYS_SRC_INNERANGLE and PSYS_SRC_ANGLE_BEGIN use the same variables. The
  5446. // PSYS_SRC_OUTERANGLE and PSYS_SRC_ANGLE_END also use the same variable. The
  5447. // client tells the difference between the two by looking at the 0x02 bit in
  5448. // the PartFlags variable.
  5449. case (int)ScriptBaseClass.PSYS_SRC_INNERANGLE:
  5450. tempf = (float)rules.GetLSLFloatItem(i + 1);
  5451. prules.InnerAngle = (float)tempf;
  5452. prules.PartFlags &= 0xFFFFFFFD; // Make sure new angle format is off.
  5453. break;
  5454. case (int)ScriptBaseClass.PSYS_SRC_OUTERANGLE:
  5455. tempf = (float)rules.GetLSLFloatItem(i + 1);
  5456. prules.OuterAngle = (float)tempf;
  5457. prules.PartFlags &= 0xFFFFFFFD; // Make sure new angle format is off.
  5458. break;
  5459. case (int)ScriptBaseClass.PSYS_PART_BLEND_FUNC_SOURCE:
  5460. tmpi = (int)rules.GetLSLIntegerItem(i + 1);
  5461. prules.BlendFuncSource = (byte)tmpi;
  5462. break;
  5463. case (int)ScriptBaseClass.PSYS_PART_BLEND_FUNC_DEST:
  5464. tmpi = (int)rules.GetLSLIntegerItem(i + 1);
  5465. prules.BlendFuncDest = (byte)tmpi;
  5466. break;
  5467. case (int)ScriptBaseClass.PSYS_PART_START_GLOW:
  5468. tempf = (float)rules.GetLSLFloatItem(i + 1);
  5469. prules.PartStartGlow = (float)tempf;
  5470. break;
  5471. case (int)ScriptBaseClass.PSYS_PART_END_GLOW:
  5472. tempf = (float)rules.GetLSLFloatItem(i + 1);
  5473. prules.PartEndGlow = (float)tempf;
  5474. break;
  5475. case (int)ScriptBaseClass.PSYS_SRC_TEXTURE:
  5476. prules.Texture = ScriptUtils.GetAssetIdFromKeyOrItemName(m_host, rules.GetLSLStringItem(i + 1));
  5477. break;
  5478. case (int)ScriptBaseClass.PSYS_SRC_BURST_RATE:
  5479. tempf = (float)rules.GetLSLFloatItem(i + 1);
  5480. prules.BurstRate = (float)tempf;
  5481. break;
  5482. case (int)ScriptBaseClass.PSYS_SRC_BURST_PART_COUNT:
  5483. prules.BurstPartCount = (byte)(int)rules.GetLSLIntegerItem(i + 1);
  5484. break;
  5485. case (int)ScriptBaseClass.PSYS_SRC_BURST_RADIUS:
  5486. tempf = (float)rules.GetLSLFloatItem(i + 1);
  5487. prules.BurstRadius = (float)tempf;
  5488. break;
  5489. case (int)ScriptBaseClass.PSYS_SRC_BURST_SPEED_MIN:
  5490. tempf = (float)rules.GetLSLFloatItem(i + 1);
  5491. prules.BurstSpeedMin = (float)tempf;
  5492. break;
  5493. case (int)ScriptBaseClass.PSYS_SRC_BURST_SPEED_MAX:
  5494. tempf = (float)rules.GetLSLFloatItem(i + 1);
  5495. prules.BurstSpeedMax = (float)tempf;
  5496. break;
  5497. case (int)ScriptBaseClass.PSYS_SRC_MAX_AGE:
  5498. tempf = (float)rules.GetLSLFloatItem(i + 1);
  5499. prules.MaxAge = (float)tempf;
  5500. break;
  5501. case (int)ScriptBaseClass.PSYS_SRC_TARGET_KEY:
  5502. UUID key = UUID.Zero;
  5503. if (UUID.TryParse(rules.Data[i + 1].ToString(), out key))
  5504. {
  5505. prules.Target = key;
  5506. }
  5507. else
  5508. {
  5509. prules.Target = part.UUID;
  5510. }
  5511. break;
  5512. case (int)ScriptBaseClass.PSYS_SRC_OMEGA:
  5513. // AL: This is an assumption, since it is the only thing that would match.
  5514. tempv = rules.GetVector3Item(i + 1);
  5515. prules.AngularVelocity.X = (float)tempv.x;
  5516. prules.AngularVelocity.Y = (float)tempv.y;
  5517. prules.AngularVelocity.Z = (float)tempv.z;
  5518. break;
  5519. case (int)ScriptBaseClass.PSYS_SRC_ANGLE_BEGIN:
  5520. tempf = (float)rules.GetLSLFloatItem(i + 1);
  5521. prules.InnerAngle = (float)tempf;
  5522. prules.PartFlags |= 0x02; // Set new angle format.
  5523. break;
  5524. case (int)ScriptBaseClass.PSYS_SRC_ANGLE_END:
  5525. tempf = (float)rules.GetLSLFloatItem(i + 1);
  5526. prules.OuterAngle = (float)tempf;
  5527. prules.PartFlags |= 0x02; // Set new angle format.
  5528. break;
  5529. }
  5530. }
  5531. prules.CRC = 1;
  5532. part.AddNewParticleSystem(prules);
  5533. part.ParentGroup.HasGroupChanged = true;
  5534. }
  5535. part.SendFullUpdateToAllClients();
  5536. }
  5537. public void llGroundRepel(double height, int water, double tau)
  5538. {
  5539. m_host.AddScriptLPS(1);
  5540. if (m_host.PhysActor != null)
  5541. {
  5542. float ground = (float)llGround(new LSL_Types.Vector3(0, 0, 0));
  5543. float waterLevel = (float)llWater(new LSL_Types.Vector3(0, 0, 0));
  5544. PIDHoverType hoverType = PIDHoverType.Ground;
  5545. if (water != 0)
  5546. {
  5547. hoverType = PIDHoverType.GroundAndWater;
  5548. if (ground < waterLevel)
  5549. height += waterLevel;
  5550. else
  5551. height += ground;
  5552. }
  5553. else
  5554. {
  5555. height += ground;
  5556. }
  5557. m_host.SetHoverHeight((float)height, hoverType, (float)tau);
  5558. }
  5559. }
  5560. public void llGiveInventoryList(string destination, string category, LSL_List inventory)
  5561. {
  5562. m_host.AddScriptLPS(1);
  5563. UUID destID;
  5564. if (!UUID.TryParse(destination, out destID))
  5565. return;
  5566. List<UUID> itemList = new List<UUID>();
  5567. foreach (Object item in inventory.Data)
  5568. {
  5569. string rawItemString = item.ToString();
  5570. UUID itemID;
  5571. if (UUID.TryParse(rawItemString, out itemID))
  5572. {
  5573. itemList.Add(itemID);
  5574. }
  5575. else
  5576. {
  5577. TaskInventoryItem taskItem = m_host.Inventory.GetInventoryItem(rawItemString);
  5578. if (taskItem != null)
  5579. itemList.Add(taskItem.ItemID);
  5580. }
  5581. }
  5582. if (itemList.Count == 0)
  5583. return;
  5584. UUID folderID = m_ScriptEngine.World.MoveTaskInventoryItems(destID, category, m_host, itemList);
  5585. if (folderID == UUID.Zero)
  5586. return;
  5587. if (m_TransferModule != null)
  5588. {
  5589. byte[] bucket = new byte[] { (byte)AssetType.Folder };
  5590. Vector3 pos = m_host.AbsolutePosition;
  5591. GridInstantMessage msg = new GridInstantMessage(World,
  5592. m_host.OwnerID, m_host.Name, destID,
  5593. (byte)InstantMessageDialog.TaskInventoryOffered,
  5594. false, string.Format("'{0}'", category),
  5595. // We won't go so far as to add a SLURL, but this is the format used by LL as of 2012-10-06
  5596. // false, string.Format("'{0}' ( http://slurl.com/secondlife/{1}/{2}/{3}/{4} )", category, World.Name, (int)pos.X, (int)pos.Y, (int)pos.Z),
  5597. folderID, false, pos,
  5598. bucket, false);
  5599. m_TransferModule.SendInstantMessage(msg, delegate(bool success) {});
  5600. }
  5601. }
  5602. public void llSetVehicleType(int type)
  5603. {
  5604. m_host.AddScriptLPS(1);
  5605. if (!m_host.ParentGroup.IsDeleted)
  5606. {
  5607. m_host.ParentGroup.RootPart.SetVehicleType(type);
  5608. }
  5609. }
  5610. //CFK 9/28: Most, but not all of the underlying plumbing between here and the physics modules is in
  5611. //CFK 9/28: so these are not complete yet.
  5612. public void llSetVehicleFloatParam(int param, LSL_Float value)
  5613. {
  5614. m_host.AddScriptLPS(1);
  5615. if (!m_host.ParentGroup.IsDeleted)
  5616. {
  5617. m_host.ParentGroup.RootPart.SetVehicleFloatParam(param, (float)value);
  5618. }
  5619. }
  5620. //CFK 9/28: Most, but not all of the underlying plumbing between here and the physics modules is in
  5621. //CFK 9/28: so these are not complete yet.
  5622. public void llSetVehicleVectorParam(int param, LSL_Vector vec)
  5623. {
  5624. m_host.AddScriptLPS(1);
  5625. if (!m_host.ParentGroup.IsDeleted)
  5626. {
  5627. m_host.ParentGroup.RootPart.SetVehicleVectorParam(param, vec);
  5628. }
  5629. }
  5630. //CFK 9/28: Most, but not all of the underlying plumbing between here and the physics modules is in
  5631. //CFK 9/28: so these are not complete yet.
  5632. public void llSetVehicleRotationParam(int param, LSL_Rotation rot)
  5633. {
  5634. m_host.AddScriptLPS(1);
  5635. if (!m_host.ParentGroup.IsDeleted)
  5636. {
  5637. m_host.ParentGroup.RootPart.SetVehicleRotationParam(param, rot);
  5638. }
  5639. }
  5640. public void llSetVehicleFlags(int flags)
  5641. {
  5642. m_host.AddScriptLPS(1);
  5643. if (!m_host.ParentGroup.IsDeleted)
  5644. {
  5645. m_host.ParentGroup.RootPart.SetVehicleFlags(flags, false);
  5646. }
  5647. }
  5648. public void llRemoveVehicleFlags(int flags)
  5649. {
  5650. m_host.AddScriptLPS(1);
  5651. if (!m_host.ParentGroup.IsDeleted)
  5652. {
  5653. m_host.ParentGroup.RootPart.SetVehicleFlags(flags, true);
  5654. }
  5655. }
  5656. protected void SitTarget(SceneObjectPart part, LSL_Vector offset, LSL_Rotation rot)
  5657. {
  5658. part.SitTargetPosition = offset;
  5659. part.SitTargetOrientation = rot;
  5660. part.ParentGroup.HasGroupChanged = true;
  5661. }
  5662. public void llSitTarget(LSL_Vector offset, LSL_Rotation rot)
  5663. {
  5664. m_host.AddScriptLPS(1);
  5665. SitTarget(m_host, offset, rot);
  5666. }
  5667. public void llLinkSitTarget(LSL_Integer link, LSL_Vector offset, LSL_Rotation rot)
  5668. {
  5669. m_host.AddScriptLPS(1);
  5670. if (link == ScriptBaseClass.LINK_ROOT)
  5671. SitTarget(m_host.ParentGroup.RootPart, offset, rot);
  5672. else if (link == ScriptBaseClass.LINK_THIS)
  5673. SitTarget(m_host, offset, rot);
  5674. else
  5675. {
  5676. SceneObjectPart part = m_host.ParentGroup.GetLinkNumPart(link);
  5677. if (null != part)
  5678. {
  5679. SitTarget(part, offset, rot);
  5680. }
  5681. }
  5682. }
  5683. public LSL_String llAvatarOnSitTarget()
  5684. {
  5685. m_host.AddScriptLPS(1);
  5686. return m_host.SitTargetAvatar.ToString();
  5687. }
  5688. // http://wiki.secondlife.com/wiki/LlAvatarOnLinkSitTarget
  5689. public LSL_String llAvatarOnLinkSitTarget(int linknum)
  5690. {
  5691. m_host.AddScriptLPS(1);
  5692. if(linknum == ScriptBaseClass.LINK_SET ||
  5693. linknum == ScriptBaseClass.LINK_ALL_CHILDREN ||
  5694. linknum == ScriptBaseClass.LINK_ALL_OTHERS) return UUID.Zero.ToString();
  5695. List<SceneObjectPart> parts = GetLinkParts(linknum);
  5696. if (parts.Count == 0) return UUID.Zero.ToString();
  5697. return parts[0].SitTargetAvatar.ToString();
  5698. }
  5699. public void llAddToLandPassList(string avatar, double hours)
  5700. {
  5701. m_host.AddScriptLPS(1);
  5702. UUID key;
  5703. ILandObject land = World.LandChannel.GetLandObject(m_host.AbsolutePosition);
  5704. if (World.Permissions.CanEditParcelProperties(m_host.OwnerID, land, GroupPowers.LandManageBanned))
  5705. {
  5706. int expires = 0;
  5707. if (hours != 0)
  5708. expires = Util.UnixTimeSinceEpoch() + (int)(3600.0 * hours);
  5709. if (UUID.TryParse(avatar, out key))
  5710. {
  5711. int idx = land.LandData.ParcelAccessList.FindIndex(
  5712. delegate(LandAccessEntry e)
  5713. {
  5714. if (e.AgentID == key && e.Flags == AccessList.Access)
  5715. return true;
  5716. return false;
  5717. });
  5718. if (idx != -1 && (land.LandData.ParcelAccessList[idx].Expires == 0 || (expires != 0 && expires < land.LandData.ParcelAccessList[idx].Expires)))
  5719. return;
  5720. if (idx != -1)
  5721. land.LandData.ParcelAccessList.RemoveAt(idx);
  5722. LandAccessEntry entry = new LandAccessEntry();
  5723. entry.AgentID = key;
  5724. entry.Flags = AccessList.Access;
  5725. entry.Expires = expires;
  5726. land.LandData.ParcelAccessList.Add(entry);
  5727. World.EventManager.TriggerLandObjectUpdated((uint)land.LandData.LocalID, land);
  5728. }
  5729. }
  5730. ScriptSleep(100);
  5731. }
  5732. public void llSetTouchText(string text)
  5733. {
  5734. m_host.AddScriptLPS(1);
  5735. m_host.TouchName = text;
  5736. }
  5737. public void llSetSitText(string text)
  5738. {
  5739. m_host.AddScriptLPS(1);
  5740. m_host.SitName = text;
  5741. }
  5742. public void llSetCameraEyeOffset(LSL_Vector offset)
  5743. {
  5744. m_host.AddScriptLPS(1);
  5745. m_host.SetCameraEyeOffset(offset);
  5746. }
  5747. public void llSetCameraAtOffset(LSL_Vector offset)
  5748. {
  5749. m_host.AddScriptLPS(1);
  5750. m_host.SetCameraAtOffset(offset);
  5751. }
  5752. public void llSetLinkCamera(LSL_Integer link, LSL_Vector eye, LSL_Vector at)
  5753. {
  5754. m_host.AddScriptLPS(1);
  5755. if (link == ScriptBaseClass.LINK_SET ||
  5756. link == ScriptBaseClass.LINK_ALL_CHILDREN ||
  5757. link == ScriptBaseClass.LINK_ALL_OTHERS) return;
  5758. SceneObjectPart part = null;
  5759. switch (link)
  5760. {
  5761. case ScriptBaseClass.LINK_ROOT:
  5762. part = m_host.ParentGroup.RootPart;
  5763. break;
  5764. case ScriptBaseClass.LINK_THIS:
  5765. part = m_host;
  5766. break;
  5767. default:
  5768. part = m_host.ParentGroup.GetLinkNumPart(link);
  5769. break;
  5770. }
  5771. if (null != part)
  5772. {
  5773. part.SetCameraEyeOffset(eye);
  5774. part.SetCameraAtOffset(at);
  5775. }
  5776. }
  5777. public LSL_String llDumpList2String(LSL_List src, string seperator)
  5778. {
  5779. m_host.AddScriptLPS(1);
  5780. if (src.Length == 0)
  5781. {
  5782. return String.Empty;
  5783. }
  5784. string ret = String.Empty;
  5785. foreach (object o in src.Data)
  5786. {
  5787. ret = ret + o.ToString() + seperator;
  5788. }
  5789. ret = ret.Substring(0, ret.Length - seperator.Length);
  5790. return ret;
  5791. }
  5792. public LSL_Integer llScriptDanger(LSL_Vector pos)
  5793. {
  5794. m_host.AddScriptLPS(1);
  5795. bool result = World.ScriptDanger(m_host.LocalId, pos);
  5796. if (result)
  5797. {
  5798. return 1;
  5799. }
  5800. else
  5801. {
  5802. return 0;
  5803. }
  5804. }
  5805. public void llDialog(string avatar, string message, LSL_List buttons, int chat_channel)
  5806. {
  5807. IDialogModule dm = World.RequestModuleInterface<IDialogModule>();
  5808. if (dm == null)
  5809. return;
  5810. m_host.AddScriptLPS(1);
  5811. UUID av = new UUID();
  5812. if (!UUID.TryParse(avatar,out av))
  5813. {
  5814. Error("llDialog", "First parameter must be a key");
  5815. return;
  5816. }
  5817. if (buttons.Length < 1)
  5818. {
  5819. Error("llDialog", "At least 1 button must be shown");
  5820. return;
  5821. }
  5822. if (buttons.Length > 12)
  5823. {
  5824. Error("llDialog", "No more than 12 buttons can be shown");
  5825. return;
  5826. }
  5827. string[] buts = new string[buttons.Length];
  5828. for (int i = 0; i < buttons.Length; i++)
  5829. {
  5830. if (buttons.Data[i].ToString() == String.Empty)
  5831. {
  5832. Error("llDialog", "Button label cannot be blank");
  5833. return;
  5834. }
  5835. if (buttons.Data[i].ToString().Length > 24)
  5836. {
  5837. Error("llDialog", "Button label cannot be longer than 24 characters");
  5838. return;
  5839. }
  5840. buts[i] = buttons.Data[i].ToString();
  5841. }
  5842. dm.SendDialogToUser(
  5843. av, m_host.Name, m_host.UUID, m_host.OwnerID,
  5844. message, new UUID("00000000-0000-2222-3333-100000001000"), chat_channel, buts);
  5845. ScriptSleep(1000);
  5846. }
  5847. public void llVolumeDetect(int detect)
  5848. {
  5849. m_host.AddScriptLPS(1);
  5850. if (!m_host.ParentGroup.IsDeleted)
  5851. m_host.ParentGroup.ScriptSetVolumeDetect(detect != 0);
  5852. }
  5853. public void llRemoteLoadScript(string target, string name, int running, int start_param)
  5854. {
  5855. m_host.AddScriptLPS(1);
  5856. Deprecated("llRemoteLoadScript", "Use llRemoteLoadScriptPin instead");
  5857. ScriptSleep(3000);
  5858. }
  5859. public void llSetRemoteScriptAccessPin(int pin)
  5860. {
  5861. m_host.AddScriptLPS(1);
  5862. m_host.ScriptAccessPin = pin;
  5863. }
  5864. public void llRemoteLoadScriptPin(string target, string name, int pin, int running, int start_param)
  5865. {
  5866. m_host.AddScriptLPS(1);
  5867. UUID destId = UUID.Zero;
  5868. if (!UUID.TryParse(target, out destId))
  5869. {
  5870. Error("llRemoteLoadScriptPin", "Can't parse key '" + target + "'");
  5871. return;
  5872. }
  5873. // target must be a different prim than the one containing the script
  5874. if (m_host.UUID == destId)
  5875. {
  5876. return;
  5877. }
  5878. // copy the first script found with this inventory name
  5879. TaskInventoryItem item = m_host.Inventory.GetInventoryItem(name);
  5880. // make sure the object is a script
  5881. if (item == null || item.Type != 10)
  5882. {
  5883. Error("llRemoteLoadScriptPin", "Can't find script '" + name + "'");
  5884. return;
  5885. }
  5886. // the rest of the permission checks are done in RezScript, so check the pin there as well
  5887. World.RezScriptFromPrim(item.ItemID, m_host, destId, pin, running, start_param);
  5888. // this will cause the delay even if the script pin or permissions were wrong - seems ok
  5889. ScriptSleep(3000);
  5890. }
  5891. public void llOpenRemoteDataChannel()
  5892. {
  5893. m_host.AddScriptLPS(1);
  5894. IXMLRPC xmlrpcMod = m_ScriptEngine.World.RequestModuleInterface<IXMLRPC>();
  5895. if (xmlrpcMod != null && xmlrpcMod.IsEnabled())
  5896. {
  5897. UUID channelID = xmlrpcMod.OpenXMLRPCChannel(m_host.LocalId, m_item.ItemID, UUID.Zero);
  5898. IXmlRpcRouter xmlRpcRouter = m_ScriptEngine.World.RequestModuleInterface<IXmlRpcRouter>();
  5899. if (xmlRpcRouter != null)
  5900. {
  5901. string ExternalHostName = m_ScriptEngine.World.RegionInfo.ExternalHostName;
  5902. xmlRpcRouter.RegisterNewReceiver(m_ScriptEngine.ScriptModule, channelID, m_host.UUID,
  5903. m_item.ItemID, String.Format("http://{0}:{1}/", ExternalHostName,
  5904. xmlrpcMod.Port.ToString()));
  5905. }
  5906. object[] resobj = new object[]
  5907. {
  5908. new LSL_Integer(1),
  5909. new LSL_String(channelID.ToString()),
  5910. new LSL_String(UUID.Zero.ToString()),
  5911. new LSL_String(String.Empty),
  5912. new LSL_Integer(0),
  5913. new LSL_String(String.Empty)
  5914. };
  5915. m_ScriptEngine.PostScriptEvent(m_item.ItemID, new EventParams("remote_data", resobj,
  5916. new DetectParams[0]));
  5917. }
  5918. ScriptSleep(1000);
  5919. }
  5920. public LSL_String llSendRemoteData(string channel, string dest, int idata, string sdata)
  5921. {
  5922. m_host.AddScriptLPS(1);
  5923. IXMLRPC xmlrpcMod = m_ScriptEngine.World.RequestModuleInterface<IXMLRPC>();
  5924. ScriptSleep(3000);
  5925. if (xmlrpcMod == null)
  5926. return "";
  5927. return (xmlrpcMod.SendRemoteData(m_host.LocalId, m_item.ItemID, channel, dest, idata, sdata)).ToString();
  5928. }
  5929. public void llRemoteDataReply(string channel, string message_id, string sdata, int idata)
  5930. {
  5931. m_host.AddScriptLPS(1);
  5932. IXMLRPC xmlrpcMod = m_ScriptEngine.World.RequestModuleInterface<IXMLRPC>();
  5933. if (xmlrpcMod != null)
  5934. xmlrpcMod.RemoteDataReply(channel, message_id, sdata, idata);
  5935. ScriptSleep(3000);
  5936. }
  5937. public void llCloseRemoteDataChannel(string channel)
  5938. {
  5939. m_host.AddScriptLPS(1);
  5940. IXmlRpcRouter xmlRpcRouter = m_ScriptEngine.World.RequestModuleInterface<IXmlRpcRouter>();
  5941. if (xmlRpcRouter != null)
  5942. {
  5943. xmlRpcRouter.UnRegisterReceiver(channel, m_item.ItemID);
  5944. }
  5945. IXMLRPC xmlrpcMod = m_ScriptEngine.World.RequestModuleInterface<IXMLRPC>();
  5946. if (xmlrpcMod != null)
  5947. xmlrpcMod.CloseXMLRPCChannel((UUID)channel);
  5948. ScriptSleep(1000);
  5949. }
  5950. public LSL_String llMD5String(string src, int nonce)
  5951. {
  5952. m_host.AddScriptLPS(1);
  5953. return Util.Md5Hash(String.Format("{0}:{1}", src, nonce.ToString()));
  5954. }
  5955. public LSL_String llSHA1String(string src)
  5956. {
  5957. m_host.AddScriptLPS(1);
  5958. return Util.SHA1Hash(src).ToLower();
  5959. }
  5960. protected ObjectShapePacket.ObjectDataBlock SetPrimitiveBlockShapeParams(SceneObjectPart part, int holeshape, LSL_Vector cut, float hollow, LSL_Vector twist, byte profileshape, byte pathcurve)
  5961. {
  5962. float tempFloat; // Use in float expressions below to avoid byte cast precision issues.
  5963. ObjectShapePacket.ObjectDataBlock shapeBlock = new ObjectShapePacket.ObjectDataBlock();
  5964. if (holeshape != (int)ScriptBaseClass.PRIM_HOLE_DEFAULT &&
  5965. holeshape != (int)ScriptBaseClass.PRIM_HOLE_CIRCLE &&
  5966. holeshape != (int)ScriptBaseClass.PRIM_HOLE_SQUARE &&
  5967. holeshape != (int)ScriptBaseClass.PRIM_HOLE_TRIANGLE)
  5968. {
  5969. holeshape = (int)ScriptBaseClass.PRIM_HOLE_DEFAULT;
  5970. }
  5971. shapeBlock.PathCurve = pathcurve;
  5972. shapeBlock.ProfileCurve = (byte)holeshape; // Set the hole shape.
  5973. shapeBlock.ProfileCurve += profileshape; // Add in the profile shape.
  5974. if (cut.x < 0f)
  5975. {
  5976. cut.x = 0f;
  5977. }
  5978. if (cut.x > 1f)
  5979. {
  5980. cut.x = 1f;
  5981. }
  5982. if (cut.y < 0f)
  5983. {
  5984. cut.y = 0f;
  5985. }
  5986. if (cut.y > 1f)
  5987. {
  5988. cut.y = 1f;
  5989. }
  5990. if (cut.y - cut.x < 0.05f)
  5991. {
  5992. cut.x = cut.y - 0.05f;
  5993. if (cut.x < 0.0f)
  5994. {
  5995. cut.x = 0.0f;
  5996. cut.y = 0.05f;
  5997. }
  5998. }
  5999. shapeBlock.ProfileBegin = (ushort)(50000 * cut.x);
  6000. shapeBlock.ProfileEnd = (ushort)(50000 * (1 - cut.y));
  6001. if (hollow < 0f)
  6002. {
  6003. hollow = 0f;
  6004. }
  6005. // If the prim is a Cylinder, Prism, Sphere, Torus or Ring (or not a
  6006. // Box or Tube) and the hole shape is a square, hollow is limited to
  6007. // a max of 70%. The viewer performs its own check on this value but
  6008. // we need to do it here also so llGetPrimitiveParams can have access
  6009. // to the correct value.
  6010. if (profileshape != (byte)ProfileCurve.Square &&
  6011. holeshape == (int)ScriptBaseClass.PRIM_HOLE_SQUARE)
  6012. {
  6013. if (hollow > 0.70f)
  6014. {
  6015. hollow = 0.70f;
  6016. }
  6017. }
  6018. // Otherwise, hollow is limited to 95%.
  6019. else
  6020. {
  6021. if (hollow > 0.95f)
  6022. {
  6023. hollow = 0.95f;
  6024. }
  6025. }
  6026. shapeBlock.ProfileHollow = (ushort)(50000 * hollow);
  6027. if (twist.x < -1.0f)
  6028. {
  6029. twist.x = -1.0f;
  6030. }
  6031. if (twist.x > 1.0f)
  6032. {
  6033. twist.x = 1.0f;
  6034. }
  6035. if (twist.y < -1.0f)
  6036. {
  6037. twist.y = -1.0f;
  6038. }
  6039. if (twist.y > 1.0f)
  6040. {
  6041. twist.y = 1.0f;
  6042. }
  6043. // A fairly large precision error occurs for some calculations,
  6044. // if a float or double is directly cast to a byte or sbyte
  6045. // variable, in both .Net and Mono. In .Net, coding
  6046. // "(sbyte)(float)(some expression)" corrects the precision
  6047. // errors. But this does not work for Mono. This longer coding
  6048. // form of creating a tempoary float variable from the
  6049. // expression first, then casting that variable to a byte or
  6050. // sbyte, works for both .Net and Mono. These types of
  6051. // assignments occur in SetPrimtiveBlockShapeParams and
  6052. // SetPrimitiveShapeParams in support of llSetPrimitiveParams.
  6053. tempFloat = (float)(100.0d * twist.x);
  6054. shapeBlock.PathTwistBegin = (sbyte)tempFloat;
  6055. tempFloat = (float)(100.0d * twist.y);
  6056. shapeBlock.PathTwist = (sbyte)tempFloat;
  6057. shapeBlock.ObjectLocalID = part.LocalId;
  6058. part.Shape.SculptEntry = false;
  6059. return shapeBlock;
  6060. }
  6061. // Prim type box, cylinder and prism.
  6062. 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)
  6063. {
  6064. float tempFloat; // Use in float expressions below to avoid byte cast precision issues.
  6065. ObjectShapePacket.ObjectDataBlock shapeBlock;
  6066. shapeBlock = SetPrimitiveBlockShapeParams(part, holeshape, cut, hollow, twist, profileshape, pathcurve);
  6067. if (taper_b.x < 0f)
  6068. {
  6069. taper_b.x = 0f;
  6070. }
  6071. if (taper_b.x > 2f)
  6072. {
  6073. taper_b.x = 2f;
  6074. }
  6075. if (taper_b.y < 0f)
  6076. {
  6077. taper_b.y = 0f;
  6078. }
  6079. if (taper_b.y > 2f)
  6080. {
  6081. taper_b.y = 2f;
  6082. }
  6083. tempFloat = (float)(100.0d * (2.0d - taper_b.x));
  6084. shapeBlock.PathScaleX = (byte)tempFloat;
  6085. tempFloat = (float)(100.0d * (2.0d - taper_b.y));
  6086. shapeBlock.PathScaleY = (byte)tempFloat;
  6087. if (topshear.x < -0.5f)
  6088. {
  6089. topshear.x = -0.5f;
  6090. }
  6091. if (topshear.x > 0.5f)
  6092. {
  6093. topshear.x = 0.5f;
  6094. }
  6095. if (topshear.y < -0.5f)
  6096. {
  6097. topshear.y = -0.5f;
  6098. }
  6099. if (topshear.y > 0.5f)
  6100. {
  6101. topshear.y = 0.5f;
  6102. }
  6103. tempFloat = (float)(100.0d * topshear.x);
  6104. shapeBlock.PathShearX = (byte)tempFloat;
  6105. tempFloat = (float)(100.0d * topshear.y);
  6106. shapeBlock.PathShearY = (byte)tempFloat;
  6107. part.Shape.SculptEntry = false;
  6108. part.UpdateShape(shapeBlock);
  6109. }
  6110. // Prim type sphere.
  6111. protected void SetPrimitiveShapeParams(SceneObjectPart part, int holeshape, LSL_Vector cut, float hollow, LSL_Vector twist, LSL_Vector dimple, byte profileshape, byte pathcurve)
  6112. {
  6113. ObjectShapePacket.ObjectDataBlock shapeBlock;
  6114. shapeBlock = SetPrimitiveBlockShapeParams(part, holeshape, cut, hollow, twist, profileshape, pathcurve);
  6115. // profile/path swapped for a sphere
  6116. shapeBlock.PathBegin = shapeBlock.ProfileBegin;
  6117. shapeBlock.PathEnd = shapeBlock.ProfileEnd;
  6118. shapeBlock.PathScaleX = 100;
  6119. shapeBlock.PathScaleY = 100;
  6120. if (dimple.x < 0f)
  6121. {
  6122. dimple.x = 0f;
  6123. }
  6124. if (dimple.x > 1f)
  6125. {
  6126. dimple.x = 1f;
  6127. }
  6128. if (dimple.y < 0f)
  6129. {
  6130. dimple.y = 0f;
  6131. }
  6132. if (dimple.y > 1f)
  6133. {
  6134. dimple.y = 1f;
  6135. }
  6136. if (dimple.y - cut.x < 0.05f)
  6137. {
  6138. dimple.x = cut.y - 0.05f;
  6139. }
  6140. shapeBlock.ProfileBegin = (ushort)(50000 * dimple.x);
  6141. shapeBlock.ProfileEnd = (ushort)(50000 * (1 - dimple.y));
  6142. part.Shape.SculptEntry = false;
  6143. part.UpdateShape(shapeBlock);
  6144. }
  6145. // Prim type torus, tube and ring.
  6146. 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)
  6147. {
  6148. float tempFloat; // Use in float expressions below to avoid byte cast precision issues.
  6149. ObjectShapePacket.ObjectDataBlock shapeBlock;
  6150. shapeBlock = SetPrimitiveBlockShapeParams(part, holeshape, cut, hollow, twist, profileshape, pathcurve);
  6151. // profile/path swapped for a torrus, tube, ring
  6152. shapeBlock.PathBegin = shapeBlock.ProfileBegin;
  6153. shapeBlock.PathEnd = shapeBlock.ProfileEnd;
  6154. if (holesize.x < 0.05f)
  6155. {
  6156. holesize.x = 0.05f;
  6157. }
  6158. if (holesize.x > 1f)
  6159. {
  6160. holesize.x = 1f;
  6161. }
  6162. if (holesize.y < 0.05f)
  6163. {
  6164. holesize.y = 0.05f;
  6165. }
  6166. if (holesize.y > 0.5f)
  6167. {
  6168. holesize.y = 0.5f;
  6169. }
  6170. tempFloat = (float)(100.0d * (2.0d - holesize.x));
  6171. shapeBlock.PathScaleX = (byte)tempFloat;
  6172. tempFloat = (float)(100.0d * (2.0d - holesize.y));
  6173. shapeBlock.PathScaleY = (byte)tempFloat;
  6174. if (topshear.x < -0.5f)
  6175. {
  6176. topshear.x = -0.5f;
  6177. }
  6178. if (topshear.x > 0.5f)
  6179. {
  6180. topshear.x = 0.5f;
  6181. }
  6182. if (topshear.y < -0.5f)
  6183. {
  6184. topshear.y = -0.5f;
  6185. }
  6186. if (topshear.y > 0.5f)
  6187. {
  6188. topshear.y = 0.5f;
  6189. }
  6190. tempFloat = (float)(100.0d * topshear.x);
  6191. shapeBlock.PathShearX = (byte)tempFloat;
  6192. tempFloat = (float)(100.0d * topshear.y);
  6193. shapeBlock.PathShearY = (byte)tempFloat;
  6194. if (profilecut.x < 0f)
  6195. {
  6196. profilecut.x = 0f;
  6197. }
  6198. if (profilecut.x > 1f)
  6199. {
  6200. profilecut.x = 1f;
  6201. }
  6202. if (profilecut.y < 0f)
  6203. {
  6204. profilecut.y = 0f;
  6205. }
  6206. if (profilecut.y > 1f)
  6207. {
  6208. profilecut.y = 1f;
  6209. }
  6210. if (profilecut.y - profilecut.x < 0.05f)
  6211. {
  6212. profilecut.x = profilecut.y - 0.05f;
  6213. if (profilecut.x < 0.0f)
  6214. {
  6215. profilecut.x = 0.0f;
  6216. profilecut.y = 0.05f;
  6217. }
  6218. }
  6219. shapeBlock.ProfileBegin = (ushort)(50000 * profilecut.x);
  6220. shapeBlock.ProfileEnd = (ushort)(50000 * (1 - profilecut.y));
  6221. if (taper_a.x < -1f)
  6222. {
  6223. taper_a.x = -1f;
  6224. }
  6225. if (taper_a.x > 1f)
  6226. {
  6227. taper_a.x = 1f;
  6228. }
  6229. if (taper_a.y < -1f)
  6230. {
  6231. taper_a.y = -1f;
  6232. }
  6233. if (taper_a.y > 1f)
  6234. {
  6235. taper_a.y = 1f;
  6236. }
  6237. tempFloat = (float)(100.0d * taper_a.x);
  6238. shapeBlock.PathTaperX = (sbyte)tempFloat;
  6239. tempFloat = (float)(100.0d * taper_a.y);
  6240. shapeBlock.PathTaperY = (sbyte)tempFloat;
  6241. if (revolutions < 1f)
  6242. {
  6243. revolutions = 1f;
  6244. }
  6245. if (revolutions > 4f)
  6246. {
  6247. revolutions = 4f;
  6248. }
  6249. tempFloat = 66.66667f * (revolutions - 1.0f);
  6250. shapeBlock.PathRevolutions = (byte)tempFloat;
  6251. // limits on radiusoffset depend on revolutions and hole size (how?) seems like the maximum range is 0 to 1
  6252. if (radiusoffset < 0f)
  6253. {
  6254. radiusoffset = 0f;
  6255. }
  6256. if (radiusoffset > 1f)
  6257. {
  6258. radiusoffset = 1f;
  6259. }
  6260. tempFloat = 100.0f * radiusoffset;
  6261. shapeBlock.PathRadiusOffset = (sbyte)tempFloat;
  6262. if (skew < -0.95f)
  6263. {
  6264. skew = -0.95f;
  6265. }
  6266. if (skew > 0.95f)
  6267. {
  6268. skew = 0.95f;
  6269. }
  6270. tempFloat = 100.0f * skew;
  6271. shapeBlock.PathSkew = (sbyte)tempFloat;
  6272. part.Shape.SculptEntry = false;
  6273. part.UpdateShape(shapeBlock);
  6274. }
  6275. // Prim type sculpt.
  6276. protected void SetPrimitiveShapeParams(SceneObjectPart part, string map, int type, byte pathcurve)
  6277. {
  6278. ObjectShapePacket.ObjectDataBlock shapeBlock = new ObjectShapePacket.ObjectDataBlock();
  6279. UUID sculptId;
  6280. if (!UUID.TryParse(map, out sculptId))
  6281. sculptId = ScriptUtils.GetAssetIdFromItemName(m_host, map, (int)AssetType.Texture);
  6282. if (sculptId == UUID.Zero)
  6283. return;
  6284. shapeBlock.PathCurve = pathcurve;
  6285. shapeBlock.ObjectLocalID = part.LocalId;
  6286. shapeBlock.PathScaleX = 100;
  6287. shapeBlock.PathScaleY = 150;
  6288. int flag = type & (ScriptBaseClass.PRIM_SCULPT_FLAG_INVERT | ScriptBaseClass.PRIM_SCULPT_FLAG_MIRROR);
  6289. if (type != (ScriptBaseClass.PRIM_SCULPT_TYPE_CYLINDER | flag) &&
  6290. type != (ScriptBaseClass.PRIM_SCULPT_TYPE_PLANE | flag) &&
  6291. type != (ScriptBaseClass.PRIM_SCULPT_TYPE_SPHERE | flag) &&
  6292. type != (ScriptBaseClass.PRIM_SCULPT_TYPE_TORUS | flag))
  6293. {
  6294. // default
  6295. type = (int)ScriptBaseClass.PRIM_SCULPT_TYPE_SPHERE;
  6296. }
  6297. part.Shape.SetSculptProperties((byte)type, sculptId);
  6298. part.Shape.SculptEntry = true;
  6299. part.UpdateShape(shapeBlock);
  6300. }
  6301. public void llSetPrimitiveParams(LSL_List rules)
  6302. {
  6303. m_host.AddScriptLPS(1);
  6304. setLinkPrimParams(ScriptBaseClass.LINK_THIS, rules, "llSetPrimitiveParams");
  6305. ScriptSleep(200);
  6306. }
  6307. public void llSetLinkPrimitiveParams(int linknumber, LSL_List rules)
  6308. {
  6309. m_host.AddScriptLPS(1);
  6310. setLinkPrimParams(linknumber, rules, "llSetLinkPrimitiveParams");
  6311. ScriptSleep(200);
  6312. }
  6313. public void llSetLinkPrimitiveParamsFast(int linknumber, LSL_List rules)
  6314. {
  6315. m_host.AddScriptLPS(1);
  6316. setLinkPrimParams(linknumber, rules, "llSetLinkPrimitiveParamsFast");
  6317. }
  6318. protected void setLinkPrimParams(int linknumber, LSL_List rules, string originFunc)
  6319. {
  6320. List<SceneObjectPart> parts = GetLinkParts(linknumber);
  6321. LSL_List remaining = null;
  6322. uint rulesParsed = 0;
  6323. foreach (SceneObjectPart part in parts)
  6324. remaining = SetPrimParams(part, rules, originFunc, ref rulesParsed);
  6325. while (remaining != null && remaining.Length > 2)
  6326. {
  6327. linknumber = remaining.GetLSLIntegerItem(0);
  6328. rules = remaining.GetSublist(1, -1);
  6329. parts = GetLinkParts(linknumber);
  6330. foreach (SceneObjectPart part in parts)
  6331. remaining = SetPrimParams(part, rules, originFunc, ref rulesParsed);
  6332. }
  6333. }
  6334. public void llSetKeyframedMotion(LSL_List frames, LSL_List options)
  6335. {
  6336. SceneObjectGroup group = m_host.ParentGroup;
  6337. if (group.RootPart.PhysActor != null && group.RootPart.PhysActor.IsPhysical)
  6338. return;
  6339. if (group.IsAttachment)
  6340. return;
  6341. if (frames.Data.Length > 0) // We are getting a new motion
  6342. {
  6343. if (group.RootPart.KeyframeMotion != null)
  6344. group.RootPart.KeyframeMotion.Delete();
  6345. group.RootPart.KeyframeMotion = null;
  6346. int idx = 0;
  6347. KeyframeMotion.PlayMode mode = KeyframeMotion.PlayMode.Forward;
  6348. KeyframeMotion.DataFormat data = KeyframeMotion.DataFormat.Translation | KeyframeMotion.DataFormat.Rotation;
  6349. while (idx < options.Data.Length)
  6350. {
  6351. int option = (int)options.GetLSLIntegerItem(idx++);
  6352. int remain = options.Data.Length - idx;
  6353. switch (option)
  6354. {
  6355. case ScriptBaseClass.KFM_MODE:
  6356. if (remain < 1)
  6357. break;
  6358. int modeval = (int)options.GetLSLIntegerItem(idx++);
  6359. switch(modeval)
  6360. {
  6361. case ScriptBaseClass.KFM_FORWARD:
  6362. mode = KeyframeMotion.PlayMode.Forward;
  6363. break;
  6364. case ScriptBaseClass.KFM_REVERSE:
  6365. mode = KeyframeMotion.PlayMode.Reverse;
  6366. break;
  6367. case ScriptBaseClass.KFM_LOOP:
  6368. mode = KeyframeMotion.PlayMode.Loop;
  6369. break;
  6370. case ScriptBaseClass.KFM_PING_PONG:
  6371. mode = KeyframeMotion.PlayMode.PingPong;
  6372. break;
  6373. }
  6374. break;
  6375. case ScriptBaseClass.KFM_DATA:
  6376. if (remain < 1)
  6377. break;
  6378. int dataval = (int)options.GetLSLIntegerItem(idx++);
  6379. data = (KeyframeMotion.DataFormat)dataval;
  6380. break;
  6381. }
  6382. }
  6383. group.RootPart.KeyframeMotion = new KeyframeMotion(group, mode, data);
  6384. idx = 0;
  6385. int elemLength = 2;
  6386. if (data == (KeyframeMotion.DataFormat.Translation | KeyframeMotion.DataFormat.Rotation))
  6387. elemLength = 3;
  6388. List<KeyframeMotion.Keyframe> keyframes = new List<KeyframeMotion.Keyframe>();
  6389. while (idx < frames.Data.Length)
  6390. {
  6391. int remain = frames.Data.Length - idx;
  6392. if (remain < elemLength)
  6393. break;
  6394. KeyframeMotion.Keyframe frame = new KeyframeMotion.Keyframe();
  6395. frame.Position = null;
  6396. frame.Rotation = null;
  6397. if ((data & KeyframeMotion.DataFormat.Translation) != 0)
  6398. {
  6399. LSL_Types.Vector3 tempv = frames.GetVector3Item(idx++);
  6400. frame.Position = new Vector3((float)tempv.x, (float)tempv.y, (float)tempv.z);
  6401. }
  6402. if ((data & KeyframeMotion.DataFormat.Rotation) != 0)
  6403. {
  6404. LSL_Types.Quaternion tempq = frames.GetQuaternionItem(idx++);
  6405. Quaternion q = new Quaternion((float)tempq.x, (float)tempq.y, (float)tempq.z, (float)tempq.s);
  6406. q.Normalize();
  6407. frame.Rotation = q;
  6408. }
  6409. float tempf = (float)frames.GetLSLFloatItem(idx++);
  6410. frame.TimeMS = (int)(tempf * 1000.0f);
  6411. keyframes.Add(frame);
  6412. }
  6413. group.RootPart.KeyframeMotion.SetKeyframes(keyframes.ToArray());
  6414. group.RootPart.KeyframeMotion.Start();
  6415. }
  6416. else
  6417. {
  6418. if (group.RootPart.KeyframeMotion == null)
  6419. return;
  6420. if (options.Data.Length == 0)
  6421. {
  6422. group.RootPart.KeyframeMotion.Stop();
  6423. return;
  6424. }
  6425. int idx = 0;
  6426. while (idx < options.Data.Length)
  6427. {
  6428. int option = (int)options.GetLSLIntegerItem(idx++);
  6429. switch (option)
  6430. {
  6431. case ScriptBaseClass.KFM_COMMAND:
  6432. int cmd = (int)options.GetLSLIntegerItem(idx++);
  6433. switch (cmd)
  6434. {
  6435. case ScriptBaseClass.KFM_CMD_PLAY:
  6436. group.RootPart.KeyframeMotion.Start();
  6437. break;
  6438. case ScriptBaseClass.KFM_CMD_STOP:
  6439. group.RootPart.KeyframeMotion.Stop();
  6440. break;
  6441. case ScriptBaseClass.KFM_CMD_PAUSE:
  6442. group.RootPart.KeyframeMotion.Pause();
  6443. break;
  6444. }
  6445. break;
  6446. }
  6447. }
  6448. }
  6449. }
  6450. protected LSL_List SetPrimParams(SceneObjectPart part, LSL_List rules, string originFunc, ref uint rulesParsed)
  6451. {
  6452. int idx = 0;
  6453. int idxStart = 0;
  6454. bool positionChanged = false;
  6455. LSL_Vector currentPosition = GetPartLocalPos(part);
  6456. try
  6457. {
  6458. while (idx < rules.Length)
  6459. {
  6460. ++rulesParsed;
  6461. int code = rules.GetLSLIntegerItem(idx++);
  6462. int remain = rules.Length - idx;
  6463. idxStart = idx;
  6464. int face;
  6465. LSL_Vector v;
  6466. switch (code)
  6467. {
  6468. case (int)ScriptBaseClass.PRIM_POSITION:
  6469. case (int)ScriptBaseClass.PRIM_POS_LOCAL:
  6470. if (remain < 1)
  6471. return null;
  6472. v=rules.GetVector3Item(idx++);
  6473. positionChanged = true;
  6474. currentPosition = GetSetPosTarget(part, v, currentPosition);
  6475. break;
  6476. case (int)ScriptBaseClass.PRIM_SIZE:
  6477. if (remain < 1)
  6478. return null;
  6479. v=rules.GetVector3Item(idx++);
  6480. SetScale(part, v);
  6481. break;
  6482. case (int)ScriptBaseClass.PRIM_ROTATION:
  6483. if (remain < 1)
  6484. return null;
  6485. LSL_Rotation q = rules.GetQuaternionItem(idx++);
  6486. // try to let this work as in SL...
  6487. if (part.ParentID == 0)
  6488. {
  6489. // special case: If we are root, rotate complete SOG to new rotation
  6490. SetRot(part, q);
  6491. }
  6492. else
  6493. {
  6494. // we are a child. The rotation values will be set to the one of root modified by rot, as in SL. Don't ask.
  6495. SceneObjectPart rootPart = part.ParentGroup.RootPart;
  6496. SetRot(part, rootPart.RotationOffset * (Quaternion)q);
  6497. }
  6498. break;
  6499. case (int)ScriptBaseClass.PRIM_TYPE:
  6500. if (remain < 3)
  6501. return null;
  6502. code = (int)rules.GetLSLIntegerItem(idx++);
  6503. remain = rules.Length - idx;
  6504. float hollow;
  6505. LSL_Vector twist;
  6506. LSL_Vector taper_b;
  6507. LSL_Vector topshear;
  6508. float revolutions;
  6509. float radiusoffset;
  6510. float skew;
  6511. LSL_Vector holesize;
  6512. LSL_Vector profilecut;
  6513. switch (code)
  6514. {
  6515. case (int)ScriptBaseClass.PRIM_TYPE_BOX:
  6516. if (remain < 6)
  6517. return null;
  6518. face = (int)rules.GetLSLIntegerItem(idx++);
  6519. v = rules.GetVector3Item(idx++); // cut
  6520. hollow = (float)rules.GetLSLFloatItem(idx++);
  6521. twist = rules.GetVector3Item(idx++);
  6522. taper_b = rules.GetVector3Item(idx++);
  6523. topshear = rules.GetVector3Item(idx++);
  6524. SetPrimitiveShapeParams(part, face, v, hollow, twist, taper_b, topshear,
  6525. (byte)ProfileShape.Square, (byte)Extrusion.Straight);
  6526. break;
  6527. case (int)ScriptBaseClass.PRIM_TYPE_CYLINDER:
  6528. if (remain < 6)
  6529. return null;
  6530. face = (int)rules.GetLSLIntegerItem(idx++); // holeshape
  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.Circle, (byte)Extrusion.Straight);
  6538. break;
  6539. case (int)ScriptBaseClass.PRIM_TYPE_PRISM:
  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.EquilateralTriangle, (byte)Extrusion.Straight);
  6550. break;
  6551. case (int)ScriptBaseClass.PRIM_TYPE_SPHERE:
  6552. if (remain < 5)
  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++); // dimple
  6559. SetPrimitiveShapeParams(part, face, v, hollow, twist, taper_b,
  6560. (byte)ProfileShape.HalfCircle, (byte)Extrusion.Curve1);
  6561. break;
  6562. case (int)ScriptBaseClass.PRIM_TYPE_TORUS:
  6563. if (remain < 11)
  6564. return null;
  6565. face = (int)rules.GetLSLIntegerItem(idx++); // holeshape
  6566. v = rules.GetVector3Item(idx++); //cut
  6567. hollow = (float)rules.GetLSLFloatItem(idx++);
  6568. twist = rules.GetVector3Item(idx++);
  6569. holesize = rules.GetVector3Item(idx++);
  6570. topshear = rules.GetVector3Item(idx++);
  6571. profilecut = rules.GetVector3Item(idx++);
  6572. taper_b = rules.GetVector3Item(idx++); // taper_a
  6573. revolutions = (float)rules.GetLSLFloatItem(idx++);
  6574. radiusoffset = (float)rules.GetLSLFloatItem(idx++);
  6575. skew = (float)rules.GetLSLFloatItem(idx++);
  6576. SetPrimitiveShapeParams(part, face, v, hollow, twist, holesize, topshear, profilecut, taper_b,
  6577. revolutions, radiusoffset, skew, (byte)ProfileShape.Circle, (byte)Extrusion.Curve1);
  6578. break;
  6579. case (int)ScriptBaseClass.PRIM_TYPE_TUBE:
  6580. if (remain < 11)
  6581. return null;
  6582. face = (int)rules.GetLSLIntegerItem(idx++); // holeshape
  6583. v = rules.GetVector3Item(idx++); //cut
  6584. hollow = (float)rules.GetLSLFloatItem(idx++);
  6585. twist = rules.GetVector3Item(idx++);
  6586. holesize = rules.GetVector3Item(idx++);
  6587. topshear = rules.GetVector3Item(idx++);
  6588. profilecut = rules.GetVector3Item(idx++);
  6589. taper_b = rules.GetVector3Item(idx++); // taper_a
  6590. revolutions = (float)rules.GetLSLFloatItem(idx++);
  6591. radiusoffset = (float)rules.GetLSLFloatItem(idx++);
  6592. skew = (float)rules.GetLSLFloatItem(idx++);
  6593. SetPrimitiveShapeParams(part, face, v, hollow, twist, holesize, topshear, profilecut, taper_b,
  6594. revolutions, radiusoffset, skew, (byte)ProfileShape.Square, (byte)Extrusion.Curve1);
  6595. break;
  6596. case (int)ScriptBaseClass.PRIM_TYPE_RING:
  6597. if (remain < 11)
  6598. return null;
  6599. face = (int)rules.GetLSLIntegerItem(idx++); // holeshape
  6600. v = rules.GetVector3Item(idx++); //cut
  6601. hollow = (float)rules.GetLSLFloatItem(idx++);
  6602. twist = rules.GetVector3Item(idx++);
  6603. holesize = rules.GetVector3Item(idx++);
  6604. topshear = rules.GetVector3Item(idx++);
  6605. profilecut = rules.GetVector3Item(idx++);
  6606. taper_b = rules.GetVector3Item(idx++); // taper_a
  6607. revolutions = (float)rules.GetLSLFloatItem(idx++);
  6608. radiusoffset = (float)rules.GetLSLFloatItem(idx++);
  6609. skew = (float)rules.GetLSLFloatItem(idx++);
  6610. SetPrimitiveShapeParams(part, face, v, hollow, twist, holesize, topshear, profilecut, taper_b,
  6611. revolutions, radiusoffset, skew, (byte)ProfileShape.EquilateralTriangle, (byte)Extrusion.Curve1);
  6612. break;
  6613. case (int)ScriptBaseClass.PRIM_TYPE_SCULPT:
  6614. if (remain < 2)
  6615. return null;
  6616. string map = rules.Data[idx++].ToString();
  6617. face = (int)rules.GetLSLIntegerItem(idx++); // type
  6618. SetPrimitiveShapeParams(part, map, face, (byte)Extrusion.Curve1);
  6619. break;
  6620. }
  6621. break;
  6622. case (int)ScriptBaseClass.PRIM_TEXTURE:
  6623. if (remain < 5)
  6624. return null;
  6625. face=(int)rules.GetLSLIntegerItem(idx++);
  6626. string tex=rules.Data[idx++].ToString();
  6627. LSL_Vector repeats=rules.GetVector3Item(idx++);
  6628. LSL_Vector offsets=rules.GetVector3Item(idx++);
  6629. double rotation=(double)rules.GetLSLFloatItem(idx++);
  6630. SetTexture(part, tex, face);
  6631. ScaleTexture(part, repeats.x, repeats.y, face);
  6632. OffsetTexture(part, offsets.x, offsets.y, face);
  6633. RotateTexture(part, rotation, face);
  6634. break;
  6635. case (int)ScriptBaseClass.PRIM_COLOR:
  6636. if (remain < 3)
  6637. return null;
  6638. face=(int)rules.GetLSLIntegerItem(idx++);
  6639. LSL_Vector color=rules.GetVector3Item(idx++);
  6640. double alpha=(double)rules.GetLSLFloatItem(idx++);
  6641. part.SetFaceColorAlpha(face, color, alpha);
  6642. break;
  6643. case (int)ScriptBaseClass.PRIM_FLEXIBLE:
  6644. if (remain < 7)
  6645. return null;
  6646. bool flexi = rules.GetLSLIntegerItem(idx++);
  6647. int softness = rules.GetLSLIntegerItem(idx++);
  6648. float gravity = (float)rules.GetLSLFloatItem(idx++);
  6649. float friction = (float)rules.GetLSLFloatItem(idx++);
  6650. float wind = (float)rules.GetLSLFloatItem(idx++);
  6651. float tension = (float)rules.GetLSLFloatItem(idx++);
  6652. LSL_Vector force = rules.GetVector3Item(idx++);
  6653. SetFlexi(part, flexi, softness, gravity, friction, wind, tension, force);
  6654. break;
  6655. case (int)ScriptBaseClass.PRIM_POINT_LIGHT:
  6656. if (remain < 5)
  6657. return null;
  6658. bool light = rules.GetLSLIntegerItem(idx++);
  6659. LSL_Vector lightcolor = rules.GetVector3Item(idx++);
  6660. float intensity = (float)rules.GetLSLFloatItem(idx++);
  6661. float radius = (float)rules.GetLSLFloatItem(idx++);
  6662. float falloff = (float)rules.GetLSLFloatItem(idx++);
  6663. SetPointLight(part, light, lightcolor, intensity, radius, falloff);
  6664. break;
  6665. case (int)ScriptBaseClass.PRIM_GLOW:
  6666. if (remain < 2)
  6667. return null;
  6668. face = rules.GetLSLIntegerItem(idx++);
  6669. float glow = (float)rules.GetLSLFloatItem(idx++);
  6670. SetGlow(part, face, glow);
  6671. break;
  6672. case (int)ScriptBaseClass.PRIM_BUMP_SHINY:
  6673. if (remain < 3)
  6674. return null;
  6675. face = (int)rules.GetLSLIntegerItem(idx++);
  6676. int shiny = (int)rules.GetLSLIntegerItem(idx++);
  6677. Bumpiness bump = (Bumpiness)(int)rules.GetLSLIntegerItem(idx++);
  6678. SetShiny(part, face, shiny, bump);
  6679. break;
  6680. case (int)ScriptBaseClass.PRIM_FULLBRIGHT:
  6681. if (remain < 2)
  6682. return null;
  6683. face = rules.GetLSLIntegerItem(idx++);
  6684. bool st = rules.GetLSLIntegerItem(idx++);
  6685. SetFullBright(part, face , st);
  6686. break;
  6687. case (int)ScriptBaseClass.PRIM_MATERIAL:
  6688. if (remain < 1)
  6689. return null;
  6690. int mat = rules.GetLSLIntegerItem(idx++);
  6691. if (mat < 0 || mat > 7)
  6692. return null;
  6693. part.Material = Convert.ToByte(mat);
  6694. break;
  6695. case (int)ScriptBaseClass.PRIM_PHANTOM:
  6696. if (remain < 1)
  6697. return null;
  6698. string ph = rules.Data[idx++].ToString();
  6699. part.ParentGroup.ScriptSetPhantomStatus(ph.Equals("1"));
  6700. break;
  6701. case (int)ScriptBaseClass.PRIM_PHYSICS:
  6702. if (remain < 1)
  6703. return null;
  6704. string phy = rules.Data[idx++].ToString();
  6705. bool physics;
  6706. if (phy.Equals("1"))
  6707. physics = true;
  6708. else
  6709. physics = false;
  6710. part.ScriptSetPhysicsStatus(physics);
  6711. break;
  6712. case (int)ScriptBaseClass.PRIM_PHYSICS_SHAPE_TYPE:
  6713. if (remain < 1)
  6714. return null;
  6715. int shape_type = rules.GetLSLIntegerItem(idx++);
  6716. ExtraPhysicsData physdata = new ExtraPhysicsData();
  6717. physdata.Density = part.Density;
  6718. physdata.Bounce = part.Restitution;
  6719. physdata.GravitationModifier = part.GravityModifier;
  6720. physdata.PhysShapeType = (PhysShapeType)shape_type;
  6721. part.UpdateExtraPhysics(physdata);
  6722. break;
  6723. case (int)ScriptBaseClass.PRIM_TEMP_ON_REZ:
  6724. if (remain < 1)
  6725. return null;
  6726. string temp = rules.Data[idx++].ToString();
  6727. part.ParentGroup.ScriptSetTemporaryStatus(temp.Equals("1"));
  6728. break;
  6729. case (int)ScriptBaseClass.PRIM_TEXGEN:
  6730. if (remain < 2)
  6731. return null;
  6732. //face,type
  6733. face = rules.GetLSLIntegerItem(idx++);
  6734. int style = rules.GetLSLIntegerItem(idx++);
  6735. SetTexGen(part, face, style);
  6736. break;
  6737. case (int)ScriptBaseClass.PRIM_TEXT:
  6738. if (remain < 3)
  6739. return null;
  6740. string primText = rules.GetLSLStringItem(idx++);
  6741. LSL_Vector primTextColor = rules.GetVector3Item(idx++);
  6742. LSL_Float primTextAlpha = rules.GetLSLFloatItem(idx++);
  6743. Vector3 av3 = Util.Clip(primTextColor, 0.0f, 1.0f);
  6744. part.SetText(primText, av3, Util.Clip((float)primTextAlpha, 0.0f, 1.0f));
  6745. break;
  6746. case (int)ScriptBaseClass.PRIM_NAME:
  6747. if (remain < 1)
  6748. return null;
  6749. string primName = rules.GetLSLStringItem(idx++);
  6750. part.Name = primName;
  6751. break;
  6752. case (int)ScriptBaseClass.PRIM_DESC:
  6753. if (remain < 1)
  6754. return null;
  6755. string primDesc = rules.GetLSLStringItem(idx++);
  6756. part.Description = primDesc;
  6757. break;
  6758. case (int)ScriptBaseClass.PRIM_ROT_LOCAL:
  6759. if (remain < 1)
  6760. return null;
  6761. SetRot(part, rules.GetQuaternionItem(idx++));
  6762. break;
  6763. case (int)ScriptBaseClass.PRIM_OMEGA:
  6764. if (remain < 3)
  6765. return null;
  6766. LSL_Vector axis = rules.GetVector3Item(idx++);
  6767. LSL_Float spinrate = rules.GetLSLFloatItem(idx++);
  6768. LSL_Float gain = rules.GetLSLFloatItem(idx++);
  6769. TargetOmega(part, axis, (double)spinrate, (double)gain);
  6770. break;
  6771. case (int)ScriptBaseClass.PRIM_SLICE:
  6772. if (remain < 1)
  6773. return null;
  6774. LSL_Vector slice = rules.GetVector3Item(idx++);
  6775. part.UpdateSlice((float)slice.x, (float)slice.y);
  6776. break;
  6777. case (int)ScriptBaseClass.PRIM_LINK_TARGET:
  6778. if (remain < 3) // setting to 3 on the basis that parsing any usage of PRIM_LINK_TARGET that has nothing following it is pointless.
  6779. return null;
  6780. return rules.GetSublist(idx, -1);
  6781. }
  6782. }
  6783. }
  6784. catch (InvalidCastException e)
  6785. {
  6786. Error(originFunc, string.Format("Error running rule #{0}: arg #{1} - ", rulesParsed, idx - idxStart) + e.Message);
  6787. }
  6788. finally
  6789. {
  6790. if (positionChanged)
  6791. {
  6792. if (part.ParentGroup.RootPart == part)
  6793. {
  6794. SceneObjectGroup parent = part.ParentGroup;
  6795. parent.UpdateGroupPosition(currentPosition);
  6796. }
  6797. else
  6798. {
  6799. part.OffsetPosition = currentPosition;
  6800. SceneObjectGroup parent = part.ParentGroup;
  6801. parent.HasGroupChanged = true;
  6802. parent.ScheduleGroupForTerseUpdate();
  6803. }
  6804. }
  6805. }
  6806. return null;
  6807. }
  6808. public LSL_String llStringToBase64(string str)
  6809. {
  6810. m_host.AddScriptLPS(1);
  6811. try
  6812. {
  6813. byte[] encData_byte = new byte[str.Length];
  6814. encData_byte = Util.UTF8.GetBytes(str);
  6815. string encodedData = Convert.ToBase64String(encData_byte);
  6816. return encodedData;
  6817. }
  6818. catch
  6819. {
  6820. Error("llBase64ToString", "Error encoding string");
  6821. return String.Empty;
  6822. }
  6823. }
  6824. public LSL_String llBase64ToString(string str)
  6825. {
  6826. m_host.AddScriptLPS(1);
  6827. try
  6828. {
  6829. return Util.Base64ToString(str);
  6830. }
  6831. catch
  6832. {
  6833. Error("llBase64ToString", "Error decoding string");
  6834. return String.Empty;
  6835. }
  6836. }
  6837. public LSL_String llXorBase64Strings(string str1, string str2)
  6838. {
  6839. m_host.AddScriptLPS(1);
  6840. Deprecated("llXorBase64Strings", "Use llXorBase64 instead");
  6841. ScriptSleep(300);
  6842. return String.Empty;
  6843. }
  6844. public void llRemoteDataSetRegion()
  6845. {
  6846. m_host.AddScriptLPS(1);
  6847. Deprecated("llRemoteDataSetRegion", "Use llOpenRemoteDataChannel instead");
  6848. }
  6849. public LSL_Float llLog10(double val)
  6850. {
  6851. m_host.AddScriptLPS(1);
  6852. return (double)Math.Log10(val);
  6853. }
  6854. public LSL_Float llLog(double val)
  6855. {
  6856. m_host.AddScriptLPS(1);
  6857. return (double)Math.Log(val);
  6858. }
  6859. public LSL_List llGetAnimationList(string id)
  6860. {
  6861. m_host.AddScriptLPS(1);
  6862. LSL_List l = new LSL_List();
  6863. ScenePresence av = World.GetScenePresence((UUID)id);
  6864. if (av == null || av.IsChildAgent) // only if in the region
  6865. return l;
  6866. UUID[] anims;
  6867. anims = av.Animator.GetAnimationArray();
  6868. foreach (UUID foo in anims)
  6869. l.Add(new LSL_Key(foo.ToString()));
  6870. return l;
  6871. }
  6872. public void llSetParcelMusicURL(string url)
  6873. {
  6874. m_host.AddScriptLPS(1);
  6875. ILandObject land = World.LandChannel.GetLandObject(m_host.AbsolutePosition);
  6876. if (land.LandData.OwnerID != m_host.OwnerID)
  6877. return;
  6878. land.SetMusicUrl(url);
  6879. ScriptSleep(2000);
  6880. }
  6881. public LSL_String llGetParcelMusicURL()
  6882. {
  6883. m_host.AddScriptLPS(1);
  6884. ILandObject land = World.LandChannel.GetLandObject(m_host.AbsolutePosition);
  6885. if (land.LandData.OwnerID != m_host.OwnerID)
  6886. return String.Empty;
  6887. return land.GetMusicUrl();
  6888. }
  6889. public LSL_Vector llGetRootPosition()
  6890. {
  6891. m_host.AddScriptLPS(1);
  6892. return new LSL_Vector(m_host.ParentGroup.AbsolutePosition);
  6893. }
  6894. /// <summary>
  6895. /// http://lslwiki.net/lslwiki/wakka.php?wakka=llGetRot
  6896. /// http://lslwiki.net/lslwiki/wakka.php?wakka=ChildRotation
  6897. /// Also tested in sl in regards to the behaviour in attachments/mouselook
  6898. /// In the root prim:-
  6899. /// Returns the object rotation if not attached
  6900. /// Returns the avatars rotation if attached
  6901. /// Returns the camera rotation if attached and the avatar is in mouselook
  6902. /// </summary>
  6903. public LSL_Rotation llGetRootRotation()
  6904. {
  6905. m_host.AddScriptLPS(1);
  6906. Quaternion q;
  6907. if (m_host.ParentGroup.AttachmentPoint != 0)
  6908. {
  6909. ScenePresence avatar = World.GetScenePresence(m_host.ParentGroup.AttachedAvatar);
  6910. if (avatar != null)
  6911. if ((avatar.AgentControlFlags & (uint)AgentManager.ControlFlags.AGENT_CONTROL_MOUSELOOK) != 0)
  6912. q = avatar.CameraRotation; // Mouselook
  6913. else
  6914. q = avatar.GetWorldRotation(); // Currently infrequently updated so may be inaccurate
  6915. else
  6916. q = m_host.ParentGroup.GroupRotation; // Likely never get here but just in case
  6917. }
  6918. else
  6919. q = m_host.ParentGroup.GroupRotation; // just the group rotation
  6920. return new LSL_Rotation(q);
  6921. }
  6922. public LSL_String llGetObjectDesc()
  6923. {
  6924. return m_host.Description!=null?m_host.Description:String.Empty;
  6925. }
  6926. public void llSetObjectDesc(string desc)
  6927. {
  6928. m_host.AddScriptLPS(1);
  6929. m_host.Description = desc!=null?desc:String.Empty;
  6930. }
  6931. public LSL_String llGetCreator()
  6932. {
  6933. m_host.AddScriptLPS(1);
  6934. return m_host.CreatorID.ToString();
  6935. }
  6936. public LSL_String llGetTimestamp()
  6937. {
  6938. m_host.AddScriptLPS(1);
  6939. return DateTime.Now.ToUniversalTime().ToString("yyyy-MM-ddTHH:mm:ss.fffffffZ");
  6940. }
  6941. public LSL_Integer llGetNumberOfPrims()
  6942. {
  6943. m_host.AddScriptLPS(1);
  6944. return m_host.ParentGroup.PrimCount + m_host.ParentGroup.GetSittingAvatarsCount();
  6945. }
  6946. /// <summary>
  6947. /// A partial implementation.
  6948. /// http://lslwiki.net/lslwiki/wakka.php?wakka=llGetBoundingBox
  6949. /// So far only valid for standing/flying/ground sitting avatars and single prim objects.
  6950. /// If the object has multiple prims and/or a sitting avatar then the bounding
  6951. /// box is for the root prim only.
  6952. /// </summary>
  6953. public LSL_List llGetBoundingBox(string obj)
  6954. {
  6955. m_host.AddScriptLPS(1);
  6956. UUID objID = UUID.Zero;
  6957. LSL_List result = new LSL_List();
  6958. if (!UUID.TryParse(obj, out objID))
  6959. {
  6960. result.Add(new LSL_Vector());
  6961. result.Add(new LSL_Vector());
  6962. return result;
  6963. }
  6964. ScenePresence presence = World.GetScenePresence(objID);
  6965. if (presence != null)
  6966. {
  6967. if (presence.ParentID == 0) // not sat on an object
  6968. {
  6969. LSL_Vector lower;
  6970. LSL_Vector upper;
  6971. if (presence.Animator.Animations.ImplicitDefaultAnimation.AnimID
  6972. == DefaultAvatarAnimations.AnimsUUID["SIT_GROUND_CONSTRAINED"])
  6973. {
  6974. // This is for ground sitting avatars
  6975. float height = presence.Appearance.AvatarHeight / 2.66666667f;
  6976. lower = new LSL_Vector(-0.3375f, -0.45f, height * -1.0f);
  6977. upper = new LSL_Vector(0.3375f, 0.45f, 0.0f);
  6978. }
  6979. else
  6980. {
  6981. // This is for standing/flying avatars
  6982. float height = presence.Appearance.AvatarHeight / 2.0f;
  6983. lower = new LSL_Vector(-0.225f, -0.3f, height * -1.0f);
  6984. upper = new LSL_Vector(0.225f, 0.3f, height + 0.05f);
  6985. }
  6986. result.Add(lower);
  6987. result.Add(upper);
  6988. return result;
  6989. }
  6990. else
  6991. {
  6992. // sitting on an object so we need the bounding box of that
  6993. // which should include the avatar so set the UUID to the
  6994. // UUID of the object the avatar is sat on and allow it to fall through
  6995. // to processing an object
  6996. SceneObjectPart p = World.GetSceneObjectPart(presence.ParentID);
  6997. objID = p.UUID;
  6998. }
  6999. }
  7000. SceneObjectPart part = World.GetSceneObjectPart(objID);
  7001. // Currently only works for single prims without a sitting avatar
  7002. if (part != null)
  7003. {
  7004. Vector3 halfSize = part.Scale / 2.0f;
  7005. LSL_Vector lower = (new LSL_Vector(halfSize)) * -1.0f;
  7006. LSL_Vector upper = new LSL_Vector(halfSize);
  7007. result.Add(lower);
  7008. result.Add(upper);
  7009. return result;
  7010. }
  7011. // Not found so return empty values
  7012. result.Add(new LSL_Vector());
  7013. result.Add(new LSL_Vector());
  7014. return result;
  7015. }
  7016. public LSL_Vector llGetGeometricCenter()
  7017. {
  7018. return new LSL_Vector(m_host.GetGeometricCenter());
  7019. }
  7020. public LSL_List GetEntityParams(ISceneEntity entity, LSL_List rules)
  7021. {
  7022. LSL_List result = new LSL_List();
  7023. LSL_List remaining = null;
  7024. while (true)
  7025. {
  7026. // m_log.DebugFormat(
  7027. // "[LSL API]: GetEntityParams has {0} rules with scene entity named {1}",
  7028. // rules.Length, entity != null ? entity.Name : "NULL");
  7029. if (entity == null)
  7030. return result;
  7031. if (entity is SceneObjectPart)
  7032. remaining = GetPrimParams((SceneObjectPart)entity, rules, ref result);
  7033. else
  7034. remaining = GetAgentParams((ScenePresence)entity, rules, ref result);
  7035. if (remaining == null || remaining.Length < 2)
  7036. return result;
  7037. int linknumber = remaining.GetLSLIntegerItem(0);
  7038. rules = remaining.GetSublist(1, -1);
  7039. entity = GetLinkEntity(linknumber);
  7040. }
  7041. }
  7042. public LSL_List llGetPrimitiveParams(LSL_List rules)
  7043. {
  7044. m_host.AddScriptLPS(1);
  7045. return GetEntityParams(m_host, rules);
  7046. }
  7047. public LSL_List llGetLinkPrimitiveParams(int linknumber, LSL_List rules)
  7048. {
  7049. m_host.AddScriptLPS(1);
  7050. return GetEntityParams(GetLinkEntity(linknumber), rules);
  7051. }
  7052. public LSL_Vector GetAgentSize(ScenePresence sp)
  7053. {
  7054. return new LSL_Vector(0.45, 0.6, sp.Appearance.AvatarHeight);
  7055. }
  7056. /// <summary>
  7057. /// Gets params for a seated avatar in a linkset.
  7058. /// </summary>
  7059. /// <returns></returns>
  7060. /// <param name='sp'></param>
  7061. /// <param name='rules'></param>
  7062. /// <param name='res'></param>
  7063. public LSL_List GetAgentParams(ScenePresence sp, LSL_List rules, ref LSL_List res)
  7064. {
  7065. int idx = 0;
  7066. while (idx < rules.Length)
  7067. {
  7068. int code = (int)rules.GetLSLIntegerItem(idx++);
  7069. int remain = rules.Length-idx;
  7070. switch (code)
  7071. {
  7072. case (int)ScriptBaseClass.PRIM_MATERIAL:
  7073. res.Add(new LSL_Integer(ScriptBaseClass.PRIM_MATERIAL_FLESH));
  7074. break;
  7075. case (int)ScriptBaseClass.PRIM_PHYSICS:
  7076. res.Add(ScriptBaseClass.FALSE);
  7077. break;
  7078. case (int)ScriptBaseClass.PRIM_TEMP_ON_REZ:
  7079. res.Add(ScriptBaseClass.FALSE);
  7080. break;
  7081. case (int)ScriptBaseClass.PRIM_PHANTOM:
  7082. res.Add(ScriptBaseClass.FALSE);
  7083. break;
  7084. case (int)ScriptBaseClass.PRIM_POSITION:
  7085. res.Add(new LSL_Vector(sp.AbsolutePosition));
  7086. break;
  7087. case (int)ScriptBaseClass.PRIM_SIZE:
  7088. res.Add(GetAgentSize(sp));
  7089. break;
  7090. case (int)ScriptBaseClass.PRIM_ROTATION:
  7091. res.Add(sp.GetWorldRotation());
  7092. break;
  7093. case (int)ScriptBaseClass.PRIM_TYPE:
  7094. res.Add(new LSL_Integer(ScriptBaseClass.PRIM_TYPE_BOX));
  7095. res.Add(new LSL_Integer(ScriptBaseClass.PRIM_HOLE_DEFAULT));
  7096. res.Add(new LSL_Vector(0, 1, 0));
  7097. res.Add(new LSL_Float(0));
  7098. res.Add(new LSL_Vector(0, 0, 0));
  7099. res.Add(new LSL_Vector(1, 1, 0));
  7100. res.Add(new LSL_Vector(0, 0, 0));
  7101. break;
  7102. case (int)ScriptBaseClass.PRIM_TEXTURE:
  7103. if (remain < 1)
  7104. return null;
  7105. int face = (int)rules.GetLSLIntegerItem(idx++);
  7106. if (face > 21)
  7107. break;
  7108. res.Add(new LSL_String(""));
  7109. res.Add(ScriptBaseClass.ZERO_VECTOR);
  7110. res.Add(ScriptBaseClass.ZERO_VECTOR);
  7111. res.Add(new LSL_Float(0));
  7112. break;
  7113. case (int)ScriptBaseClass.PRIM_COLOR:
  7114. if (remain < 1)
  7115. return null;
  7116. face = (int)rules.GetLSLIntegerItem(idx++);
  7117. if (face > 21)
  7118. break;
  7119. res.Add(ScriptBaseClass.ZERO_VECTOR);
  7120. res.Add(new LSL_Float(0));
  7121. break;
  7122. case (int)ScriptBaseClass.PRIM_BUMP_SHINY:
  7123. if (remain < 1)
  7124. return null;
  7125. face = (int)rules.GetLSLIntegerItem(idx++);
  7126. if (face > 21)
  7127. break;
  7128. res.Add(ScriptBaseClass.PRIM_SHINY_NONE);
  7129. res.Add(ScriptBaseClass.PRIM_BUMP_NONE);
  7130. break;
  7131. case (int)ScriptBaseClass.PRIM_FULLBRIGHT:
  7132. if (remain < 1)
  7133. return null;
  7134. face = (int)rules.GetLSLIntegerItem(idx++);
  7135. if (face > 21)
  7136. break;
  7137. res.Add(ScriptBaseClass.FALSE);
  7138. break;
  7139. case (int)ScriptBaseClass.PRIM_FLEXIBLE:
  7140. res.Add(ScriptBaseClass.FALSE);
  7141. res.Add(new LSL_Integer(0));
  7142. res.Add(new LSL_Float(0));
  7143. res.Add(new LSL_Float(0));
  7144. res.Add(new LSL_Float(0));
  7145. res.Add(new LSL_Float(0));
  7146. res.Add(ScriptBaseClass.ZERO_VECTOR);
  7147. break;
  7148. case (int)ScriptBaseClass.PRIM_TEXGEN:
  7149. if (remain < 1)
  7150. return null;
  7151. face = (int)rules.GetLSLIntegerItem(idx++);
  7152. if (face > 21)
  7153. break;
  7154. res.Add(ScriptBaseClass.PRIM_TEXGEN_DEFAULT);
  7155. break;
  7156. case (int)ScriptBaseClass.PRIM_POINT_LIGHT:
  7157. res.Add(ScriptBaseClass.FALSE);
  7158. res.Add(ScriptBaseClass.ZERO_VECTOR);
  7159. res.Add(ScriptBaseClass.ZERO_VECTOR);
  7160. break;
  7161. case (int)ScriptBaseClass.PRIM_GLOW:
  7162. if (remain < 1)
  7163. return null;
  7164. face = (int)rules.GetLSLIntegerItem(idx++);
  7165. if (face > 21)
  7166. break;
  7167. res.Add(new LSL_Float(0));
  7168. break;
  7169. case (int)ScriptBaseClass.PRIM_TEXT:
  7170. res.Add(new LSL_String(""));
  7171. res.Add(ScriptBaseClass.ZERO_VECTOR);
  7172. res.Add(new LSL_Float(1));
  7173. break;
  7174. case (int)ScriptBaseClass.PRIM_ROT_LOCAL:
  7175. res.Add(new LSL_Rotation(sp.Rotation));
  7176. break;
  7177. case (int)ScriptBaseClass.PRIM_POS_LOCAL:
  7178. res.Add(new LSL_Vector(sp.OffsetPosition));
  7179. break;
  7180. case (int)ScriptBaseClass.PRIM_SLICE:
  7181. res.Add(new LSL_Vector(0, 1, 0));
  7182. break;
  7183. case (int)ScriptBaseClass.PRIM_LINK_TARGET:
  7184. if(remain < 3)
  7185. return null;
  7186. return rules.GetSublist(idx, -1);
  7187. }
  7188. }
  7189. return null;
  7190. }
  7191. public LSL_List GetPrimParams(SceneObjectPart part, LSL_List rules, ref LSL_List res)
  7192. {
  7193. int idx = 0;
  7194. while (idx < rules.Length)
  7195. {
  7196. int code = (int)rules.GetLSLIntegerItem(idx++);
  7197. int remain = rules.Length - idx;
  7198. switch (code)
  7199. {
  7200. case (int)ScriptBaseClass.PRIM_MATERIAL:
  7201. res.Add(new LSL_Integer(part.Material));
  7202. break;
  7203. case (int)ScriptBaseClass.PRIM_PHYSICS:
  7204. if ((part.GetEffectiveObjectFlags() & (uint)PrimFlags.Physics) != 0)
  7205. res.Add(new LSL_Integer(1));
  7206. else
  7207. res.Add(new LSL_Integer(0));
  7208. break;
  7209. case (int)ScriptBaseClass.PRIM_TEMP_ON_REZ:
  7210. if ((part.GetEffectiveObjectFlags() & (uint)PrimFlags.TemporaryOnRez) != 0)
  7211. res.Add(new LSL_Integer(1));
  7212. else
  7213. res.Add(new LSL_Integer(0));
  7214. break;
  7215. case (int)ScriptBaseClass.PRIM_PHANTOM:
  7216. if ((part.GetEffectiveObjectFlags() & (uint)PrimFlags.Phantom) != 0)
  7217. res.Add(new LSL_Integer(1));
  7218. else
  7219. res.Add(new LSL_Integer(0));
  7220. break;
  7221. case (int)ScriptBaseClass.PRIM_POSITION:
  7222. LSL_Vector v = new LSL_Vector(part.AbsolutePosition);
  7223. // For some reason, the part.AbsolutePosition.* values do not change if the
  7224. // linkset is rotated; they always reflect the child prim's world position
  7225. // as though the linkset is unrotated. This is incompatible behavior with SL's
  7226. // implementation, so will break scripts imported from there (not to mention it
  7227. // makes it more difficult to determine a child prim's actual inworld position).
  7228. if (!part.IsRoot)
  7229. {
  7230. LSL_Vector rootPos = new LSL_Vector(m_host.ParentGroup.AbsolutePosition);
  7231. v = ((v - rootPos) * llGetRootRotation()) + rootPos;
  7232. }
  7233. res.Add(v);
  7234. break;
  7235. case (int)ScriptBaseClass.PRIM_SIZE:
  7236. res.Add(new LSL_Vector(part.Scale));
  7237. break;
  7238. case (int)ScriptBaseClass.PRIM_ROTATION:
  7239. res.Add(GetPartRot(part));
  7240. break;
  7241. case (int)ScriptBaseClass.PRIM_TYPE:
  7242. // implementing box
  7243. PrimitiveBaseShape Shape = part.Shape;
  7244. int primType = (int)part.GetPrimType();
  7245. res.Add(new LSL_Integer(primType));
  7246. double topshearx = (double)(sbyte)Shape.PathShearX / 100.0; // Fix negative values for PathShearX
  7247. double topsheary = (double)(sbyte)Shape.PathShearY / 100.0; // and PathShearY.
  7248. switch (primType)
  7249. {
  7250. case ScriptBaseClass.PRIM_TYPE_BOX:
  7251. case ScriptBaseClass.PRIM_TYPE_CYLINDER:
  7252. case ScriptBaseClass.PRIM_TYPE_PRISM:
  7253. res.Add(new LSL_Integer(Shape.ProfileCurve) & 0xf0); // Isolate hole shape nibble.
  7254. res.Add(new LSL_Vector(Shape.ProfileBegin / 50000.0, 1 - Shape.ProfileEnd / 50000.0, 0));
  7255. res.Add(new LSL_Float(Shape.ProfileHollow / 50000.0));
  7256. res.Add(new LSL_Vector(Shape.PathTwistBegin / 100.0, Shape.PathTwist / 100.0, 0));
  7257. res.Add(new LSL_Vector(1 - (Shape.PathScaleX / 100.0 - 1), 1 - (Shape.PathScaleY / 100.0 - 1), 0));
  7258. res.Add(new LSL_Vector(topshearx, topsheary, 0));
  7259. break;
  7260. case ScriptBaseClass.PRIM_TYPE_SPHERE:
  7261. res.Add(new LSL_Integer(Shape.ProfileCurve) & 0xf0); // Isolate hole shape nibble.
  7262. res.Add(new LSL_Vector(Shape.PathBegin / 50000.0, 1 - Shape.PathEnd / 50000.0, 0));
  7263. res.Add(new LSL_Float(Shape.ProfileHollow / 50000.0));
  7264. res.Add(new LSL_Vector(Shape.PathTwistBegin / 100.0, Shape.PathTwist / 100.0, 0));
  7265. res.Add(new LSL_Vector(Shape.ProfileBegin / 50000.0, 1 - Shape.ProfileEnd / 50000.0, 0));
  7266. break;
  7267. case ScriptBaseClass.PRIM_TYPE_SCULPT:
  7268. res.Add(new LSL_String(Shape.SculptTexture.ToString()));
  7269. res.Add(new LSL_Integer(Shape.SculptType));
  7270. break;
  7271. case ScriptBaseClass.PRIM_TYPE_RING:
  7272. case ScriptBaseClass.PRIM_TYPE_TUBE:
  7273. case ScriptBaseClass.PRIM_TYPE_TORUS:
  7274. // holeshape
  7275. res.Add(new LSL_Integer(Shape.ProfileCurve) & 0xf0); // Isolate hole shape nibble.
  7276. // cut
  7277. res.Add(new LSL_Vector(Shape.PathBegin / 50000.0, 1 - Shape.PathEnd / 50000.0, 0));
  7278. // hollow
  7279. res.Add(new LSL_Float(Shape.ProfileHollow / 50000.0));
  7280. // twist
  7281. res.Add(new LSL_Vector(Shape.PathTwistBegin / 100.0, Shape.PathTwist / 100.0, 0));
  7282. // vector holesize
  7283. res.Add(new LSL_Vector(1 - (Shape.PathScaleX / 100.0 - 1), 1 - (Shape.PathScaleY / 100.0 - 1), 0));
  7284. // vector topshear
  7285. res.Add(new LSL_Vector(topshearx, topsheary, 0));
  7286. // vector profilecut
  7287. res.Add(new LSL_Vector(Shape.ProfileBegin / 50000.0, 1 - Shape.ProfileEnd / 50000.0, 0));
  7288. // vector tapera
  7289. res.Add(new LSL_Vector(Shape.PathTaperX / 100.0, Shape.PathTaperY / 100.0, 0));
  7290. // float revolutions
  7291. res.Add(new LSL_Float(Math.Round(Shape.PathRevolutions * 0.015d, 2, MidpointRounding.AwayFromZero)) + 1.0d);
  7292. // Slightly inaccurate, because an unsigned byte is being used to represent
  7293. // the entire range of floating-point values from 1.0 through 4.0 (which is how
  7294. // SL does it).
  7295. //
  7296. // Using these formulas to store and retrieve PathRevolutions, it is not
  7297. // possible to use all values between 1.00 and 4.00. For instance, you can't
  7298. // represent 1.10. You can represent 1.09 and 1.11, but not 1.10. So, if you
  7299. // use llSetPrimitiveParams to set revolutions to 1.10 and then retreive them
  7300. // with llGetPrimitiveParams, you'll retrieve 1.09. You can also see a similar
  7301. // behavior in the viewer as you cannot set 1.10. The viewer jumps to 1.11.
  7302. // In SL, llSetPrimitveParams and llGetPrimitiveParams can set and get a value
  7303. // such as 1.10. So, SL must store and retreive the actual user input rather
  7304. // than only storing the encoded value.
  7305. // float radiusoffset
  7306. res.Add(new LSL_Float(Shape.PathRadiusOffset / 100.0));
  7307. // float skew
  7308. res.Add(new LSL_Float(Shape.PathSkew / 100.0));
  7309. break;
  7310. }
  7311. break;
  7312. case (int)ScriptBaseClass.PRIM_TEXTURE:
  7313. if (remain < 1)
  7314. return null;
  7315. int face = (int)rules.GetLSLIntegerItem(idx++);
  7316. Primitive.TextureEntry tex = part.Shape.Textures;
  7317. if (face == ScriptBaseClass.ALL_SIDES)
  7318. {
  7319. for (face = 0 ; face < GetNumberOfSides(part); face++)
  7320. {
  7321. Primitive.TextureEntryFace texface = tex.GetFace((uint)face);
  7322. res.Add(new LSL_String(texface.TextureID.ToString()));
  7323. res.Add(new LSL_Vector(texface.RepeatU,
  7324. texface.RepeatV,
  7325. 0));
  7326. res.Add(new LSL_Vector(texface.OffsetU,
  7327. texface.OffsetV,
  7328. 0));
  7329. res.Add(new LSL_Float(texface.Rotation));
  7330. }
  7331. }
  7332. else
  7333. {
  7334. if (face >= 0 && face < GetNumberOfSides(part))
  7335. {
  7336. Primitive.TextureEntryFace texface = tex.GetFace((uint)face);
  7337. res.Add(new LSL_String(texface.TextureID.ToString()));
  7338. res.Add(new LSL_Vector(texface.RepeatU,
  7339. texface.RepeatV,
  7340. 0));
  7341. res.Add(new LSL_Vector(texface.OffsetU,
  7342. texface.OffsetV,
  7343. 0));
  7344. res.Add(new LSL_Float(texface.Rotation));
  7345. }
  7346. }
  7347. break;
  7348. case (int)ScriptBaseClass.PRIM_COLOR:
  7349. if (remain < 1)
  7350. return null;
  7351. face=(int)rules.GetLSLIntegerItem(idx++);
  7352. tex = part.Shape.Textures;
  7353. Color4 texcolor;
  7354. if (face == ScriptBaseClass.ALL_SIDES)
  7355. {
  7356. for (face = 0 ; face < GetNumberOfSides(part); face++)
  7357. {
  7358. texcolor = tex.GetFace((uint)face).RGBA;
  7359. res.Add(new LSL_Vector(texcolor.R,
  7360. texcolor.G,
  7361. texcolor.B));
  7362. res.Add(new LSL_Float(texcolor.A));
  7363. }
  7364. }
  7365. else
  7366. {
  7367. texcolor = tex.GetFace((uint)face).RGBA;
  7368. res.Add(new LSL_Vector(texcolor.R,
  7369. texcolor.G,
  7370. texcolor.B));
  7371. res.Add(new LSL_Float(texcolor.A));
  7372. }
  7373. break;
  7374. case (int)ScriptBaseClass.PRIM_BUMP_SHINY:
  7375. if (remain < 1)
  7376. return null;
  7377. face=(int)rules.GetLSLIntegerItem(idx++);
  7378. tex = part.Shape.Textures;
  7379. if (face == ScriptBaseClass.ALL_SIDES)
  7380. {
  7381. for (face = 0; face < GetNumberOfSides(part); face++)
  7382. {
  7383. Primitive.TextureEntryFace texface = tex.GetFace((uint)face);
  7384. // Convert Shininess to PRIM_SHINY_*
  7385. res.Add(new LSL_Integer((uint)texface.Shiny >> 6));
  7386. // PRIM_BUMP_*
  7387. res.Add(new LSL_Integer((int)texface.Bump));
  7388. }
  7389. }
  7390. else
  7391. {
  7392. if (face >= 0 && face < GetNumberOfSides(part))
  7393. {
  7394. Primitive.TextureEntryFace texface = tex.GetFace((uint)face);
  7395. // Convert Shininess to PRIM_SHINY_*
  7396. res.Add(new LSL_Integer((uint)texface.Shiny >> 6));
  7397. // PRIM_BUMP_*
  7398. res.Add(new LSL_Integer((int)texface.Bump));
  7399. }
  7400. }
  7401. break;
  7402. case (int)ScriptBaseClass.PRIM_FULLBRIGHT:
  7403. if (remain < 1)
  7404. return null;
  7405. face = (int)rules.GetLSLIntegerItem(idx++);
  7406. tex = part.Shape.Textures;
  7407. if (face == ScriptBaseClass.ALL_SIDES)
  7408. {
  7409. for (face = 0; face < GetNumberOfSides(part); face++)
  7410. {
  7411. Primitive.TextureEntryFace texface = tex.GetFace((uint)face);
  7412. res.Add(new LSL_Integer(texface.Fullbright ? 1 : 0));
  7413. }
  7414. }
  7415. else
  7416. {
  7417. if (face >= 0 && face < GetNumberOfSides(part))
  7418. {
  7419. Primitive.TextureEntryFace texface = tex.GetFace((uint)face);
  7420. res.Add(new LSL_Integer(texface.Fullbright ? 1 : 0));
  7421. }
  7422. }
  7423. break;
  7424. case (int)ScriptBaseClass.PRIM_FLEXIBLE:
  7425. PrimitiveBaseShape shape = part.Shape;
  7426. if (shape.FlexiEntry)
  7427. res.Add(new LSL_Integer(1)); // active
  7428. else
  7429. res.Add(new LSL_Integer(0));
  7430. res.Add(new LSL_Integer(shape.FlexiSoftness));// softness
  7431. res.Add(new LSL_Float(shape.FlexiGravity)); // gravity
  7432. res.Add(new LSL_Float(shape.FlexiDrag)); // friction
  7433. res.Add(new LSL_Float(shape.FlexiWind)); // wind
  7434. res.Add(new LSL_Float(shape.FlexiTension)); // tension
  7435. res.Add(new LSL_Vector(shape.FlexiForceX, // force
  7436. shape.FlexiForceY,
  7437. shape.FlexiForceZ));
  7438. break;
  7439. case (int)ScriptBaseClass.PRIM_TEXGEN:
  7440. if (remain < 1)
  7441. return null;
  7442. face=(int)rules.GetLSLIntegerItem(idx++);
  7443. tex = part.Shape.Textures;
  7444. if (face == ScriptBaseClass.ALL_SIDES)
  7445. {
  7446. for (face = 0; face < GetNumberOfSides(part); face++)
  7447. {
  7448. MappingType texgen = tex.GetFace((uint)face).TexMapType;
  7449. // Convert MappingType to PRIM_TEXGEN_DEFAULT, PRIM_TEXGEN_PLANAR etc.
  7450. res.Add(new LSL_Integer((uint)texgen >> 1));
  7451. }
  7452. }
  7453. else
  7454. {
  7455. if (face >= 0 && face < GetNumberOfSides(part))
  7456. {
  7457. MappingType texgen = tex.GetFace((uint)face).TexMapType;
  7458. res.Add(new LSL_Integer((uint)texgen >> 1));
  7459. }
  7460. }
  7461. break;
  7462. case (int)ScriptBaseClass.PRIM_POINT_LIGHT:
  7463. shape = part.Shape;
  7464. if (shape.LightEntry)
  7465. res.Add(new LSL_Integer(1)); // active
  7466. else
  7467. res.Add(new LSL_Integer(0));
  7468. res.Add(new LSL_Vector(shape.LightColorR, // color
  7469. shape.LightColorG,
  7470. shape.LightColorB));
  7471. res.Add(new LSL_Float(shape.LightIntensity)); // intensity
  7472. res.Add(new LSL_Float(shape.LightRadius)); // radius
  7473. res.Add(new LSL_Float(shape.LightFalloff)); // falloff
  7474. break;
  7475. case (int)ScriptBaseClass.PRIM_GLOW:
  7476. if (remain < 1)
  7477. return null;
  7478. face=(int)rules.GetLSLIntegerItem(idx++);
  7479. tex = part.Shape.Textures;
  7480. if (face == ScriptBaseClass.ALL_SIDES)
  7481. {
  7482. for (face = 0; face < GetNumberOfSides(part); face++)
  7483. {
  7484. Primitive.TextureEntryFace texface = tex.GetFace((uint)face);
  7485. res.Add(new LSL_Float(texface.Glow));
  7486. }
  7487. }
  7488. else
  7489. {
  7490. if (face >= 0 && face < GetNumberOfSides(part))
  7491. {
  7492. Primitive.TextureEntryFace texface = tex.GetFace((uint)face);
  7493. res.Add(new LSL_Float(texface.Glow));
  7494. }
  7495. }
  7496. break;
  7497. case (int)ScriptBaseClass.PRIM_TEXT:
  7498. Color4 textColor = part.GetTextColor();
  7499. res.Add(new LSL_String(part.Text));
  7500. res.Add(new LSL_Vector(textColor.R,
  7501. textColor.G,
  7502. textColor.B));
  7503. res.Add(new LSL_Float(textColor.A));
  7504. break;
  7505. case (int)ScriptBaseClass.PRIM_NAME:
  7506. res.Add(new LSL_String(part.Name));
  7507. break;
  7508. case (int)ScriptBaseClass.PRIM_DESC:
  7509. res.Add(new LSL_String(part.Description));
  7510. break;
  7511. case (int)ScriptBaseClass.PRIM_ROT_LOCAL:
  7512. res.Add(new LSL_Rotation(part.RotationOffset));
  7513. break;
  7514. case (int)ScriptBaseClass.PRIM_POS_LOCAL:
  7515. res.Add(new LSL_Vector(GetPartLocalPos(part)));
  7516. break;
  7517. case (int)ScriptBaseClass.PRIM_SLICE:
  7518. PrimType prim_type = part.GetPrimType();
  7519. bool useProfileBeginEnd = (prim_type == PrimType.SPHERE || prim_type == PrimType.TORUS || prim_type == PrimType.TUBE || prim_type == PrimType.RING);
  7520. res.Add(new LSL_Vector(
  7521. (useProfileBeginEnd ? part.Shape.ProfileBegin : part.Shape.PathBegin) / 50000.0,
  7522. 1 - (useProfileBeginEnd ? part.Shape.ProfileEnd : part.Shape.PathEnd) / 50000.0,
  7523. 0
  7524. ));
  7525. break;
  7526. case (int)ScriptBaseClass.PRIM_LINK_TARGET:
  7527. // TODO: Should be issuing a runtime script warning in this case.
  7528. if (remain < 2)
  7529. return null;
  7530. return rules.GetSublist(idx, -1);
  7531. }
  7532. }
  7533. return null;
  7534. }
  7535. public LSL_List llGetPrimMediaParams(int face, LSL_List rules)
  7536. {
  7537. m_host.AddScriptLPS(1);
  7538. ScriptSleep(1000);
  7539. return GetPrimMediaParams(m_host, face, rules);
  7540. }
  7541. public LSL_List llGetLinkMedia(LSL_Integer link, LSL_Integer face, LSL_List rules)
  7542. {
  7543. m_host.AddScriptLPS(1);
  7544. ScriptSleep(1000);
  7545. if (link == ScriptBaseClass.LINK_ROOT)
  7546. return GetPrimMediaParams(m_host.ParentGroup.RootPart, face, rules);
  7547. else if (link == ScriptBaseClass.LINK_THIS)
  7548. return GetPrimMediaParams(m_host, face, rules);
  7549. else
  7550. {
  7551. SceneObjectPart part = m_host.ParentGroup.GetLinkNumPart(link);
  7552. if (null != part)
  7553. return GetPrimMediaParams(part, face, rules);
  7554. }
  7555. return new LSL_List();
  7556. }
  7557. private LSL_List GetPrimMediaParams(SceneObjectPart part, int face, LSL_List rules)
  7558. {
  7559. // LSL Spec http://wiki.secondlife.com/wiki/LlGetPrimMediaParams says to fail silently if face is invalid
  7560. // TODO: Need to correctly handle case where a face has no media (which gives back an empty list).
  7561. // Assuming silently fail means give back an empty list. Ideally, need to check this.
  7562. if (face < 0 || face > part.GetNumberOfSides() - 1)
  7563. return new LSL_List();
  7564. IMoapModule module = m_ScriptEngine.World.RequestModuleInterface<IMoapModule>();
  7565. if (null == module)
  7566. return new LSL_List();
  7567. MediaEntry me = module.GetMediaEntry(part, face);
  7568. // As per http://wiki.secondlife.com/wiki/LlGetPrimMediaParams
  7569. if (null == me)
  7570. return new LSL_List();
  7571. LSL_List res = new LSL_List();
  7572. for (int i = 0; i < rules.Length; i++)
  7573. {
  7574. int code = (int)rules.GetLSLIntegerItem(i);
  7575. switch (code)
  7576. {
  7577. case ScriptBaseClass.PRIM_MEDIA_ALT_IMAGE_ENABLE:
  7578. // Not implemented
  7579. res.Add(new LSL_Integer(0));
  7580. break;
  7581. case ScriptBaseClass.PRIM_MEDIA_CONTROLS:
  7582. if (me.Controls == MediaControls.Standard)
  7583. res.Add(new LSL_Integer(ScriptBaseClass.PRIM_MEDIA_CONTROLS_STANDARD));
  7584. else
  7585. res.Add(new LSL_Integer(ScriptBaseClass.PRIM_MEDIA_CONTROLS_MINI));
  7586. break;
  7587. case ScriptBaseClass.PRIM_MEDIA_CURRENT_URL:
  7588. res.Add(new LSL_String(me.CurrentURL));
  7589. break;
  7590. case ScriptBaseClass.PRIM_MEDIA_HOME_URL:
  7591. res.Add(new LSL_String(me.HomeURL));
  7592. break;
  7593. case ScriptBaseClass.PRIM_MEDIA_AUTO_LOOP:
  7594. res.Add(me.AutoLoop ? ScriptBaseClass.TRUE : ScriptBaseClass.FALSE);
  7595. break;
  7596. case ScriptBaseClass.PRIM_MEDIA_AUTO_PLAY:
  7597. res.Add(me.AutoPlay ? ScriptBaseClass.TRUE : ScriptBaseClass.FALSE);
  7598. break;
  7599. case ScriptBaseClass.PRIM_MEDIA_AUTO_SCALE:
  7600. res.Add(me.AutoScale ? ScriptBaseClass.TRUE : ScriptBaseClass.FALSE);
  7601. break;
  7602. case ScriptBaseClass.PRIM_MEDIA_AUTO_ZOOM:
  7603. res.Add(me.AutoZoom ? ScriptBaseClass.TRUE : ScriptBaseClass.FALSE);
  7604. break;
  7605. case ScriptBaseClass.PRIM_MEDIA_FIRST_CLICK_INTERACT:
  7606. res.Add(me.InteractOnFirstClick ? ScriptBaseClass.TRUE : ScriptBaseClass.FALSE);
  7607. break;
  7608. case ScriptBaseClass.PRIM_MEDIA_WIDTH_PIXELS:
  7609. res.Add(new LSL_Integer(me.Width));
  7610. break;
  7611. case ScriptBaseClass.PRIM_MEDIA_HEIGHT_PIXELS:
  7612. res.Add(new LSL_Integer(me.Height));
  7613. break;
  7614. case ScriptBaseClass.PRIM_MEDIA_WHITELIST_ENABLE:
  7615. res.Add(me.EnableWhiteList ? ScriptBaseClass.TRUE : ScriptBaseClass.FALSE);
  7616. break;
  7617. case ScriptBaseClass.PRIM_MEDIA_WHITELIST:
  7618. string[] urls = (string[])me.WhiteList.Clone();
  7619. for (int j = 0; j < urls.Length; j++)
  7620. urls[j] = Uri.EscapeDataString(urls[j]);
  7621. res.Add(new LSL_String(string.Join(", ", urls)));
  7622. break;
  7623. case ScriptBaseClass.PRIM_MEDIA_PERMS_INTERACT:
  7624. res.Add(new LSL_Integer((int)me.InteractPermissions));
  7625. break;
  7626. case ScriptBaseClass.PRIM_MEDIA_PERMS_CONTROL:
  7627. res.Add(new LSL_Integer((int)me.ControlPermissions));
  7628. break;
  7629. default: return ScriptBaseClass.LSL_STATUS_MALFORMED_PARAMS;
  7630. }
  7631. }
  7632. return res;
  7633. }
  7634. public LSL_Integer llSetPrimMediaParams(LSL_Integer face, LSL_List rules)
  7635. {
  7636. m_host.AddScriptLPS(1);
  7637. ScriptSleep(1000);
  7638. return SetPrimMediaParams(m_host, face, rules);
  7639. }
  7640. public LSL_Integer llSetLinkMedia(LSL_Integer link, LSL_Integer face, LSL_List rules)
  7641. {
  7642. m_host.AddScriptLPS(1);
  7643. ScriptSleep(1000);
  7644. if (link == ScriptBaseClass.LINK_ROOT)
  7645. return SetPrimMediaParams(m_host.ParentGroup.RootPart, face, rules);
  7646. else if (link == ScriptBaseClass.LINK_THIS)
  7647. return SetPrimMediaParams(m_host, face, rules);
  7648. else
  7649. {
  7650. SceneObjectPart part = m_host.ParentGroup.GetLinkNumPart(link);
  7651. if (null != part)
  7652. return SetPrimMediaParams(part, face, rules);
  7653. }
  7654. return ScriptBaseClass.LSL_STATUS_NOT_FOUND;
  7655. }
  7656. private LSL_Integer SetPrimMediaParams(SceneObjectPart part, LSL_Integer face, LSL_List rules)
  7657. {
  7658. // LSL Spec http://wiki.secondlife.com/wiki/LlSetPrimMediaParams says to fail silently if face is invalid
  7659. // Assuming silently fail means sending back LSL_STATUS_OK. Ideally, need to check this.
  7660. // Don't perform the media check directly
  7661. if (face < 0 || face > part.GetNumberOfSides() - 1)
  7662. return ScriptBaseClass.LSL_STATUS_NOT_FOUND;
  7663. IMoapModule module = m_ScriptEngine.World.RequestModuleInterface<IMoapModule>();
  7664. if (null == module)
  7665. return ScriptBaseClass.LSL_STATUS_NOT_SUPPORTED;
  7666. MediaEntry me = module.GetMediaEntry(part, face);
  7667. if (null == me)
  7668. me = new MediaEntry();
  7669. int i = 0;
  7670. while (i < rules.Length - 1)
  7671. {
  7672. int code = rules.GetLSLIntegerItem(i++);
  7673. switch (code)
  7674. {
  7675. case ScriptBaseClass.PRIM_MEDIA_ALT_IMAGE_ENABLE:
  7676. me.EnableAlterntiveImage = (rules.GetLSLIntegerItem(i++) != 0 ? true : false);
  7677. break;
  7678. case ScriptBaseClass.PRIM_MEDIA_CONTROLS:
  7679. int v = rules.GetLSLIntegerItem(i++);
  7680. if (ScriptBaseClass.PRIM_MEDIA_CONTROLS_STANDARD == v)
  7681. me.Controls = MediaControls.Standard;
  7682. else
  7683. me.Controls = MediaControls.Mini;
  7684. break;
  7685. case ScriptBaseClass.PRIM_MEDIA_CURRENT_URL:
  7686. me.CurrentURL = rules.GetLSLStringItem(i++);
  7687. break;
  7688. case ScriptBaseClass.PRIM_MEDIA_HOME_URL:
  7689. me.HomeURL = rules.GetLSLStringItem(i++);
  7690. break;
  7691. case ScriptBaseClass.PRIM_MEDIA_AUTO_LOOP:
  7692. me.AutoLoop = (ScriptBaseClass.TRUE == rules.GetLSLIntegerItem(i++) ? true : false);
  7693. break;
  7694. case ScriptBaseClass.PRIM_MEDIA_AUTO_PLAY:
  7695. me.AutoPlay = (ScriptBaseClass.TRUE == rules.GetLSLIntegerItem(i++) ? true : false);
  7696. break;
  7697. case ScriptBaseClass.PRIM_MEDIA_AUTO_SCALE:
  7698. me.AutoScale = (ScriptBaseClass.TRUE == rules.GetLSLIntegerItem(i++) ? true : false);
  7699. break;
  7700. case ScriptBaseClass.PRIM_MEDIA_AUTO_ZOOM:
  7701. me.AutoZoom = (ScriptBaseClass.TRUE == rules.GetLSLIntegerItem(i++) ? true : false);
  7702. break;
  7703. case ScriptBaseClass.PRIM_MEDIA_FIRST_CLICK_INTERACT:
  7704. me.InteractOnFirstClick = (ScriptBaseClass.TRUE == rules.GetLSLIntegerItem(i++) ? true : false);
  7705. break;
  7706. case ScriptBaseClass.PRIM_MEDIA_WIDTH_PIXELS:
  7707. me.Width = (int)rules.GetLSLIntegerItem(i++);
  7708. break;
  7709. case ScriptBaseClass.PRIM_MEDIA_HEIGHT_PIXELS:
  7710. me.Height = (int)rules.GetLSLIntegerItem(i++);
  7711. break;
  7712. case ScriptBaseClass.PRIM_MEDIA_WHITELIST_ENABLE:
  7713. me.EnableWhiteList = (ScriptBaseClass.TRUE == rules.GetLSLIntegerItem(i++) ? true : false);
  7714. break;
  7715. case ScriptBaseClass.PRIM_MEDIA_WHITELIST:
  7716. string[] rawWhiteListUrls = rules.GetLSLStringItem(i++).ToString().Split(new char[] { ',' });
  7717. List<string> whiteListUrls = new List<string>();
  7718. Array.ForEach(
  7719. rawWhiteListUrls, delegate(string rawUrl) { whiteListUrls.Add(rawUrl.Trim()); });
  7720. me.WhiteList = whiteListUrls.ToArray();
  7721. break;
  7722. case ScriptBaseClass.PRIM_MEDIA_PERMS_INTERACT:
  7723. me.InteractPermissions = (MediaPermission)(byte)(int)rules.GetLSLIntegerItem(i++);
  7724. break;
  7725. case ScriptBaseClass.PRIM_MEDIA_PERMS_CONTROL:
  7726. me.ControlPermissions = (MediaPermission)(byte)(int)rules.GetLSLIntegerItem(i++);
  7727. break;
  7728. default: return ScriptBaseClass.LSL_STATUS_MALFORMED_PARAMS;
  7729. }
  7730. }
  7731. module.SetMediaEntry(part, face, me);
  7732. return ScriptBaseClass.LSL_STATUS_OK;
  7733. }
  7734. public LSL_Integer llClearPrimMedia(LSL_Integer face)
  7735. {
  7736. m_host.AddScriptLPS(1);
  7737. ScriptSleep(1000);
  7738. return ClearPrimMedia(m_host, face);
  7739. }
  7740. public LSL_Integer llClearLinkMedia(LSL_Integer link, LSL_Integer face)
  7741. {
  7742. m_host.AddScriptLPS(1);
  7743. ScriptSleep(1000);
  7744. if (link == ScriptBaseClass.LINK_ROOT)
  7745. return ClearPrimMedia(m_host.ParentGroup.RootPart, face);
  7746. else if (link == ScriptBaseClass.LINK_THIS)
  7747. return ClearPrimMedia(m_host, face);
  7748. else
  7749. {
  7750. SceneObjectPart part = m_host.ParentGroup.GetLinkNumPart(link);
  7751. if (null != part)
  7752. return ClearPrimMedia(part, face);
  7753. }
  7754. return ScriptBaseClass.LSL_STATUS_NOT_FOUND;
  7755. }
  7756. private LSL_Integer ClearPrimMedia(SceneObjectPart part, LSL_Integer face)
  7757. {
  7758. // LSL Spec http://wiki.secondlife.com/wiki/LlClearPrimMedia says to fail silently if face is invalid
  7759. // Assuming silently fail means sending back LSL_STATUS_OK. Ideally, need to check this.
  7760. // FIXME: Don't perform the media check directly
  7761. if (face < 0 || face > part.GetNumberOfSides() - 1)
  7762. return ScriptBaseClass.LSL_STATUS_NOT_FOUND;
  7763. IMoapModule module = m_ScriptEngine.World.RequestModuleInterface<IMoapModule>();
  7764. if (null == module)
  7765. return ScriptBaseClass.LSL_STATUS_NOT_SUPPORTED;
  7766. module.ClearMediaEntry(part, face);
  7767. return ScriptBaseClass.LSL_STATUS_OK;
  7768. }
  7769. // <remarks>
  7770. // <para>
  7771. // The .NET definition of base 64 is:
  7772. // <list>
  7773. // <item>
  7774. // Significant: A-Z a-z 0-9 + -
  7775. // </item>
  7776. // <item>
  7777. // Whitespace: \t \n \r ' '
  7778. // </item>
  7779. // <item>
  7780. // Valueless: =
  7781. // </item>
  7782. // <item>
  7783. // End-of-string: \0 or '=='
  7784. // </item>
  7785. // </list>
  7786. // </para>
  7787. // <para>
  7788. // Each point in a base-64 string represents
  7789. // a 6 bit value. A 32-bit integer can be
  7790. // represented using 6 characters (with some
  7791. // redundancy).
  7792. // </para>
  7793. // <para>
  7794. // LSL requires a base64 string to be 8
  7795. // characters in length. LSL also uses '/'
  7796. // rather than '-' (MIME compliant).
  7797. // </para>
  7798. // <para>
  7799. // RFC 1341 used as a reference (as specified
  7800. // by the SecondLife Wiki).
  7801. // </para>
  7802. // <para>
  7803. // SL do not record any kind of exception for
  7804. // these functions, so the string to integer
  7805. // conversion returns '0' if an invalid
  7806. // character is encountered during conversion.
  7807. // </para>
  7808. // <para>
  7809. // References
  7810. // <list>
  7811. // <item>
  7812. // http://lslwiki.net/lslwiki/wakka.php?wakka=Base64
  7813. // </item>
  7814. // <item>
  7815. // </item>
  7816. // </list>
  7817. // </para>
  7818. // </remarks>
  7819. // <summary>
  7820. // Table for converting 6-bit integers into
  7821. // base-64 characters
  7822. // </summary>
  7823. protected static readonly char[] i2ctable =
  7824. {
  7825. 'A','B','C','D','E','F','G','H',
  7826. 'I','J','K','L','M','N','O','P',
  7827. 'Q','R','S','T','U','V','W','X',
  7828. 'Y','Z',
  7829. 'a','b','c','d','e','f','g','h',
  7830. 'i','j','k','l','m','n','o','p',
  7831. 'q','r','s','t','u','v','w','x',
  7832. 'y','z',
  7833. '0','1','2','3','4','5','6','7',
  7834. '8','9',
  7835. '+','/'
  7836. };
  7837. // <summary>
  7838. // Table for converting base-64 characters
  7839. // into 6-bit integers.
  7840. // </summary>
  7841. protected static readonly int[] c2itable =
  7842. {
  7843. -1,-1,-1,-1,-1,-1,-1,-1, // 0x
  7844. -1,-1,-1,-1,-1,-1,-1,-1,
  7845. -1,-1,-1,-1,-1,-1,-1,-1, // 1x
  7846. -1,-1,-1,-1,-1,-1,-1,-1,
  7847. -1,-1,-1,-1,-1,-1,-1,-1, // 2x
  7848. -1,-1,-1,63,-1,-1,-1,64,
  7849. 53,54,55,56,57,58,59,60, // 3x
  7850. 61,62,-1,-1,-1,0,-1,-1,
  7851. -1,1,2,3,4,5,6,7, // 4x
  7852. 8,9,10,11,12,13,14,15,
  7853. 16,17,18,19,20,21,22,23, // 5x
  7854. 24,25,26,-1,-1,-1,-1,-1,
  7855. -1,27,28,29,30,31,32,33, // 6x
  7856. 34,35,36,37,38,39,40,41,
  7857. 42,43,44,45,46,47,48,49, // 7x
  7858. 50,51,52,-1,-1,-1,-1,-1,
  7859. -1,-1,-1,-1,-1,-1,-1,-1, // 8x
  7860. -1,-1,-1,-1,-1,-1,-1,-1,
  7861. -1,-1,-1,-1,-1,-1,-1,-1, // 9x
  7862. -1,-1,-1,-1,-1,-1,-1,-1,
  7863. -1,-1,-1,-1,-1,-1,-1,-1, // Ax
  7864. -1,-1,-1,-1,-1,-1,-1,-1,
  7865. -1,-1,-1,-1,-1,-1,-1,-1, // Bx
  7866. -1,-1,-1,-1,-1,-1,-1,-1,
  7867. -1,-1,-1,-1,-1,-1,-1,-1, // Cx
  7868. -1,-1,-1,-1,-1,-1,-1,-1,
  7869. -1,-1,-1,-1,-1,-1,-1,-1, // Dx
  7870. -1,-1,-1,-1,-1,-1,-1,-1,
  7871. -1,-1,-1,-1,-1,-1,-1,-1, // Ex
  7872. -1,-1,-1,-1,-1,-1,-1,-1,
  7873. -1,-1,-1,-1,-1,-1,-1,-1, // Fx
  7874. -1,-1,-1,-1,-1,-1,-1,-1
  7875. };
  7876. // <summary>
  7877. // Converts a 32-bit integer into a Base64
  7878. // character string. Base64 character strings
  7879. // are always 8 characters long. All iinteger
  7880. // values are acceptable.
  7881. // </summary>
  7882. // <param name="number">
  7883. // 32-bit integer to be converted.
  7884. // </param>
  7885. // <returns>
  7886. // 8 character string. The 1st six characters
  7887. // contain the encoded number, the last two
  7888. // characters are padded with "=".
  7889. // </returns>
  7890. public LSL_String llIntegerToBase64(int number)
  7891. {
  7892. // uninitialized string
  7893. char[] imdt = new char[8];
  7894. m_host.AddScriptLPS(1);
  7895. // Manually unroll the loop
  7896. imdt[7] = '=';
  7897. imdt[6] = '=';
  7898. imdt[5] = i2ctable[number<<4 & 0x3F];
  7899. imdt[4] = i2ctable[number>>2 & 0x3F];
  7900. imdt[3] = i2ctable[number>>8 & 0x3F];
  7901. imdt[2] = i2ctable[number>>14 & 0x3F];
  7902. imdt[1] = i2ctable[number>>20 & 0x3F];
  7903. imdt[0] = i2ctable[number>>26 & 0x3F];
  7904. return new string(imdt);
  7905. }
  7906. // <summary>
  7907. // Converts an eight character base-64 string
  7908. // into a 32-bit integer.
  7909. // </summary>
  7910. // <param name="str">
  7911. // 8 characters string to be converted. Other
  7912. // length strings return zero.
  7913. // </param>
  7914. // <returns>
  7915. // Returns an integer representing the
  7916. // encoded value providedint he 1st 6
  7917. // characters of the string.
  7918. // </returns>
  7919. // <remarks>
  7920. // This is coded to behave like LSL's
  7921. // implementation (I think), based upon the
  7922. // information available at the Wiki.
  7923. // If more than 8 characters are supplied,
  7924. // zero is returned.
  7925. // If a NULL string is supplied, zero will
  7926. // be returned.
  7927. // If fewer than 6 characters are supplied, then
  7928. // the answer will reflect a partial
  7929. // accumulation.
  7930. // <para>
  7931. // The 6-bit segments are
  7932. // extracted left-to-right in big-endian mode,
  7933. // which means that segment 6 only contains the
  7934. // two low-order bits of the 32 bit integer as
  7935. // its high order 2 bits. A short string therefore
  7936. // means loss of low-order information. E.g.
  7937. //
  7938. // |<---------------------- 32-bit integer ----------------------->|<-Pad->|
  7939. // |<--Byte 0----->|<--Byte 1----->|<--Byte 2----->|<--Byte 3----->|<-Pad->|
  7940. // |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|
  7941. // |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|
  7942. // | str[0] | str[1] | str[2] | str[3] | str[4] | str[6] |
  7943. //
  7944. // </para>
  7945. // </remarks>
  7946. public LSL_Integer llBase64ToInteger(string str)
  7947. {
  7948. int number = 0;
  7949. int digit;
  7950. m_host.AddScriptLPS(1);
  7951. // Require a well-fromed base64 string
  7952. if (str.Length > 8)
  7953. return 0;
  7954. // The loop is unrolled in the interests
  7955. // of performance and simple necessity.
  7956. //
  7957. // MUST find 6 digits to be well formed
  7958. // -1 == invalid
  7959. // 0 == padding
  7960. if ((digit = c2itable[str[0]]) <= 0)
  7961. {
  7962. return digit < 0 ? (int)0 : number;
  7963. }
  7964. number += --digit<<26;
  7965. if ((digit = c2itable[str[1]]) <= 0)
  7966. {
  7967. return digit < 0 ? (int)0 : number;
  7968. }
  7969. number += --digit<<20;
  7970. if ((digit = c2itable[str[2]]) <= 0)
  7971. {
  7972. return digit < 0 ? (int)0 : number;
  7973. }
  7974. number += --digit<<14;
  7975. if ((digit = c2itable[str[3]]) <= 0)
  7976. {
  7977. return digit < 0 ? (int)0 : number;
  7978. }
  7979. number += --digit<<8;
  7980. if ((digit = c2itable[str[4]]) <= 0)
  7981. {
  7982. return digit < 0 ? (int)0 : number;
  7983. }
  7984. number += --digit<<2;
  7985. if ((digit = c2itable[str[5]]) <= 0)
  7986. {
  7987. return digit < 0 ? (int)0 : number;
  7988. }
  7989. number += --digit>>4;
  7990. // ignore trailing padding
  7991. return number;
  7992. }
  7993. public LSL_Float llGetGMTclock()
  7994. {
  7995. m_host.AddScriptLPS(1);
  7996. return DateTime.UtcNow.TimeOfDay.TotalSeconds;
  7997. }
  7998. public LSL_String llGetHTTPHeader(LSL_Key request_id, string header)
  7999. {
  8000. m_host.AddScriptLPS(1);
  8001. if (m_UrlModule != null)
  8002. return m_UrlModule.GetHttpHeader(new UUID(request_id), header);
  8003. return String.Empty;
  8004. }
  8005. public LSL_String llGetSimulatorHostname()
  8006. {
  8007. m_host.AddScriptLPS(1);
  8008. IUrlModule UrlModule = World.RequestModuleInterface<IUrlModule>();
  8009. return UrlModule.ExternalHostNameForLSL;
  8010. }
  8011. // <summary>
  8012. // Scan the string supplied in 'src' and
  8013. // tokenize it based upon two sets of
  8014. // tokenizers provided in two lists,
  8015. // separators and spacers.
  8016. // </summary>
  8017. //
  8018. // <remarks>
  8019. // Separators demarcate tokens and are
  8020. // elided as they are encountered. Spacers
  8021. // also demarcate tokens, but are themselves
  8022. // retained as tokens.
  8023. //
  8024. // Both separators and spacers may be arbitrarily
  8025. // long strings. i.e. ":::".
  8026. //
  8027. // The function returns an ordered list
  8028. // representing the tokens found in the supplied
  8029. // sources string. If two successive tokenizers
  8030. // are encountered, then a NULL entry is added
  8031. // to the list.
  8032. //
  8033. // It is a precondition that the source and
  8034. // toekizer lisst are non-null. If they are null,
  8035. // then a null pointer exception will be thrown
  8036. // while their lengths are being determined.
  8037. //
  8038. // A small amount of working memoryis required
  8039. // of approximately 8*#tokenizers.
  8040. //
  8041. // There are many ways in which this function
  8042. // can be implemented, this implementation is
  8043. // fairly naive and assumes that when the
  8044. // function is invooked with a short source
  8045. // string and/or short lists of tokenizers, then
  8046. // performance will not be an issue.
  8047. //
  8048. // In order to minimize the perofrmance
  8049. // effects of long strings, or large numbers
  8050. // of tokeizers, the function skips as far as
  8051. // possible whenever a toekenizer is found,
  8052. // and eliminates redundant tokenizers as soon
  8053. // as is possible.
  8054. //
  8055. // The implementation tries to avoid any copying
  8056. // of arrays or other objects.
  8057. // </remarks>
  8058. private LSL_List ParseString(string src, LSL_List separators, LSL_List spacers, bool keepNulls)
  8059. {
  8060. int beginning = 0;
  8061. int srclen = src.Length;
  8062. int seplen = separators.Length;
  8063. object[] separray = separators.Data;
  8064. int spclen = spacers.Length;
  8065. object[] spcarray = spacers.Data;
  8066. int mlen = seplen+spclen;
  8067. int[] offset = new int[mlen+1];
  8068. bool[] active = new bool[mlen];
  8069. int best;
  8070. int j;
  8071. // Initial capacity reduces resize cost
  8072. LSL_List tokens = new LSL_List();
  8073. // All entries are initially valid
  8074. for (int i = 0; i < mlen; i++)
  8075. active[i] = true;
  8076. offset[mlen] = srclen;
  8077. while (beginning < srclen)
  8078. {
  8079. best = mlen; // as bad as it gets
  8080. // Scan for separators
  8081. for (j = 0; j < seplen; j++)
  8082. {
  8083. if (separray[j].ToString() == String.Empty)
  8084. active[j] = false;
  8085. if (active[j])
  8086. {
  8087. // scan all of the markers
  8088. if ((offset[j] = src.IndexOf(separray[j].ToString(), beginning)) == -1)
  8089. {
  8090. // not present at all
  8091. active[j] = false;
  8092. }
  8093. else
  8094. {
  8095. // present and correct
  8096. if (offset[j] < offset[best])
  8097. {
  8098. // closest so far
  8099. best = j;
  8100. if (offset[best] == beginning)
  8101. break;
  8102. }
  8103. }
  8104. }
  8105. }
  8106. // Scan for spacers
  8107. if (offset[best] != beginning)
  8108. {
  8109. for (j = seplen; (j < mlen) && (offset[best] > beginning); j++)
  8110. {
  8111. if (spcarray[j-seplen].ToString() == String.Empty)
  8112. active[j] = false;
  8113. if (active[j])
  8114. {
  8115. // scan all of the markers
  8116. if ((offset[j] = src.IndexOf(spcarray[j-seplen].ToString(), beginning)) == -1)
  8117. {
  8118. // not present at all
  8119. active[j] = false;
  8120. }
  8121. else
  8122. {
  8123. // present and correct
  8124. if (offset[j] < offset[best])
  8125. {
  8126. // closest so far
  8127. best = j;
  8128. }
  8129. }
  8130. }
  8131. }
  8132. }
  8133. // This is the normal exit from the scanning loop
  8134. if (best == mlen)
  8135. {
  8136. // no markers were found on this pass
  8137. // so we're pretty much done
  8138. if ((keepNulls) || ((!keepNulls) && (srclen - beginning) > 0))
  8139. tokens.Add(new LSL_String(src.Substring(beginning, srclen - beginning)));
  8140. break;
  8141. }
  8142. // Otherwise we just add the newly delimited token
  8143. // and recalculate where the search should continue.
  8144. if ((keepNulls) || ((!keepNulls) && (offset[best] - beginning) > 0))
  8145. tokens.Add(new LSL_String(src.Substring(beginning,offset[best]-beginning)));
  8146. if (best < seplen)
  8147. {
  8148. beginning = offset[best] + (separray[best].ToString()).Length;
  8149. }
  8150. else
  8151. {
  8152. beginning = offset[best] + (spcarray[best - seplen].ToString()).Length;
  8153. string str = spcarray[best - seplen].ToString();
  8154. if ((keepNulls) || ((!keepNulls) && (str.Length > 0)))
  8155. tokens.Add(new LSL_String(str));
  8156. }
  8157. }
  8158. // This an awkward an not very intuitive boundary case. If the
  8159. // last substring is a tokenizer, then there is an implied trailing
  8160. // null list entry. Hopefully the single comparison will not be too
  8161. // arduous. Alternatively the 'break' could be replced with a return
  8162. // but that's shabby programming.
  8163. if ((beginning == srclen) && (keepNulls))
  8164. {
  8165. if (srclen != 0)
  8166. tokens.Add(new LSL_String(""));
  8167. }
  8168. return tokens;
  8169. }
  8170. public LSL_List llParseString2List(string src, LSL_List separators, LSL_List spacers)
  8171. {
  8172. m_host.AddScriptLPS(1);
  8173. return this.ParseString(src, separators, spacers, false);
  8174. }
  8175. public LSL_List llParseStringKeepNulls(string src, LSL_List separators, LSL_List spacers)
  8176. {
  8177. m_host.AddScriptLPS(1);
  8178. return this.ParseString(src, separators, spacers, true);
  8179. }
  8180. public LSL_Integer llGetObjectPermMask(int mask)
  8181. {
  8182. m_host.AddScriptLPS(1);
  8183. int permmask = 0;
  8184. if (mask == ScriptBaseClass.MASK_BASE)//0
  8185. {
  8186. permmask = (int)m_host.BaseMask;
  8187. }
  8188. else if (mask == ScriptBaseClass.MASK_OWNER)//1
  8189. {
  8190. permmask = (int)m_host.OwnerMask;
  8191. }
  8192. else if (mask == ScriptBaseClass.MASK_GROUP)//2
  8193. {
  8194. permmask = (int)m_host.GroupMask;
  8195. }
  8196. else if (mask == ScriptBaseClass.MASK_EVERYONE)//3
  8197. {
  8198. permmask = (int)m_host.EveryoneMask;
  8199. }
  8200. else if (mask == ScriptBaseClass.MASK_NEXT)//4
  8201. {
  8202. permmask = (int)m_host.NextOwnerMask;
  8203. }
  8204. return permmask;
  8205. }
  8206. public void llSetObjectPermMask(int mask, int value)
  8207. {
  8208. m_host.AddScriptLPS(1);
  8209. if (m_ScriptEngine.Config.GetBoolean("AllowGodFunctions", false))
  8210. {
  8211. if (World.Permissions.CanRunConsoleCommand(m_host.OwnerID))
  8212. {
  8213. if (mask == ScriptBaseClass.MASK_BASE)//0
  8214. {
  8215. m_host.BaseMask = (uint)value;
  8216. }
  8217. else if (mask == ScriptBaseClass.MASK_OWNER)//1
  8218. {
  8219. m_host.OwnerMask = (uint)value;
  8220. }
  8221. else if (mask == ScriptBaseClass.MASK_GROUP)//2
  8222. {
  8223. m_host.GroupMask = (uint)value;
  8224. }
  8225. else if (mask == ScriptBaseClass.MASK_EVERYONE)//3
  8226. {
  8227. m_host.EveryoneMask = (uint)value;
  8228. }
  8229. else if (mask == ScriptBaseClass.MASK_NEXT)//4
  8230. {
  8231. m_host.NextOwnerMask = (uint)value;
  8232. }
  8233. }
  8234. }
  8235. }
  8236. public LSL_Integer llGetInventoryPermMask(string itemName, int mask)
  8237. {
  8238. m_host.AddScriptLPS(1);
  8239. TaskInventoryItem item = m_host.Inventory.GetInventoryItem(itemName);
  8240. if (item == null)
  8241. return -1;
  8242. switch (mask)
  8243. {
  8244. case 0:
  8245. return (int)item.BasePermissions;
  8246. case 1:
  8247. return (int)item.CurrentPermissions;
  8248. case 2:
  8249. return (int)item.GroupPermissions;
  8250. case 3:
  8251. return (int)item.EveryonePermissions;
  8252. case 4:
  8253. return (int)item.NextPermissions;
  8254. }
  8255. return -1;
  8256. }
  8257. public void llSetInventoryPermMask(string itemName, int mask, int value)
  8258. {
  8259. m_host.AddScriptLPS(1);
  8260. if (m_ScriptEngine.Config.GetBoolean("AllowGodFunctions", false))
  8261. {
  8262. if (World.Permissions.CanRunConsoleCommand(m_host.OwnerID))
  8263. {
  8264. TaskInventoryItem item = m_host.Inventory.GetInventoryItem(itemName);
  8265. if (item != null)
  8266. {
  8267. switch (mask)
  8268. {
  8269. case 0:
  8270. item.BasePermissions = (uint)value;
  8271. break;
  8272. case 1:
  8273. item.CurrentPermissions = (uint)value;
  8274. break;
  8275. case 2:
  8276. item.GroupPermissions = (uint)value;
  8277. break;
  8278. case 3:
  8279. item.EveryonePermissions = (uint)value;
  8280. break;
  8281. case 4:
  8282. item.NextPermissions = (uint)value;
  8283. break;
  8284. }
  8285. }
  8286. }
  8287. }
  8288. }
  8289. public LSL_String llGetInventoryCreator(string itemName)
  8290. {
  8291. m_host.AddScriptLPS(1);
  8292. TaskInventoryItem item = m_host.Inventory.GetInventoryItem(itemName);
  8293. if (item == null)
  8294. {
  8295. Error("llGetInventoryCreator", "Can't find item '" + item + "'");
  8296. return String.Empty;
  8297. }
  8298. return item.CreatorID.ToString();
  8299. }
  8300. public void llOwnerSay(string msg)
  8301. {
  8302. m_host.AddScriptLPS(1);
  8303. World.SimChatBroadcast(Utils.StringToBytes(msg), ChatTypeEnum.Owner, 0,
  8304. m_host.AbsolutePosition, m_host.Name, m_host.UUID, false);
  8305. // IWorldComm wComm = m_ScriptEngine.World.RequestModuleInterface<IWorldComm>();
  8306. // wComm.DeliverMessage(ChatTypeEnum.Owner, 0, m_host.Name, m_host.UUID, msg);
  8307. }
  8308. public LSL_String llRequestSecureURL()
  8309. {
  8310. m_host.AddScriptLPS(1);
  8311. if (m_UrlModule != null)
  8312. return m_UrlModule.RequestSecureURL(m_ScriptEngine.ScriptModule, m_host, m_item.ItemID).ToString();
  8313. return UUID.Zero.ToString();
  8314. }
  8315. public LSL_String llRequestSimulatorData(string simulator, int data)
  8316. {
  8317. IOSSL_Api ossl = (IOSSL_Api)m_ScriptEngine.GetApi(m_item.ItemID, "OSSL");
  8318. try
  8319. {
  8320. m_host.AddScriptLPS(1);
  8321. string reply = String.Empty;
  8322. GridRegion info;
  8323. if (World.RegionInfo.RegionName == simulator)
  8324. info = new GridRegion(World.RegionInfo);
  8325. else
  8326. info = World.GridService.GetRegionByName(m_ScriptEngine.World.RegionInfo.ScopeID, simulator);
  8327. switch (data)
  8328. {
  8329. case ScriptBaseClass.DATA_SIM_POS:
  8330. if (info == null)
  8331. {
  8332. ScriptSleep(1000);
  8333. return UUID.Zero.ToString();
  8334. }
  8335. bool isHypergridRegion = false;
  8336. if (World.RegionInfo.RegionName != simulator && info.RegionSecret != "")
  8337. {
  8338. // Hypergrid is currently placing real destination region co-ords into RegionSecret.
  8339. // But other code can also use this field for a genuine RegionSecret! Therefore, if
  8340. // anything is present we need to disambiguate.
  8341. //
  8342. // FIXME: Hypergrid should be storing this data in a different field.
  8343. RegionFlags regionFlags
  8344. = (RegionFlags)m_ScriptEngine.World.GridService.GetRegionFlags(
  8345. info.ScopeID, info.RegionID);
  8346. isHypergridRegion = (regionFlags & RegionFlags.Hyperlink) != 0;
  8347. }
  8348. if (isHypergridRegion)
  8349. {
  8350. uint rx = 0, ry = 0;
  8351. Utils.LongToUInts(Convert.ToUInt64(info.RegionSecret), out rx, out ry);
  8352. reply = new LSL_Vector(
  8353. rx,
  8354. ry,
  8355. 0).ToString();
  8356. }
  8357. else
  8358. {
  8359. // Local grid co-oridnates
  8360. reply = new LSL_Vector(
  8361. info.RegionLocX,
  8362. info.RegionLocY,
  8363. 0).ToString();
  8364. }
  8365. break;
  8366. case ScriptBaseClass.DATA_SIM_STATUS:
  8367. if (info != null)
  8368. reply = "up"; // Duh!
  8369. else
  8370. reply = "unknown";
  8371. break;
  8372. case ScriptBaseClass.DATA_SIM_RATING:
  8373. if (info == null)
  8374. {
  8375. ScriptSleep(1000);
  8376. return UUID.Zero.ToString();
  8377. }
  8378. int access = info.Maturity;
  8379. if (access == 0)
  8380. reply = "PG";
  8381. else if (access == 1)
  8382. reply = "MATURE";
  8383. else if (access == 2)
  8384. reply = "ADULT";
  8385. else
  8386. reply = "UNKNOWN";
  8387. break;
  8388. case ScriptBaseClass.DATA_SIM_RELEASE:
  8389. if (ossl != null)
  8390. ossl.CheckThreatLevel(ThreatLevel.High, "llRequestSimulatorData");
  8391. reply = "OpenSim";
  8392. break;
  8393. default:
  8394. ScriptSleep(1000);
  8395. return UUID.Zero.ToString(); // Raise no event
  8396. }
  8397. UUID rq = UUID.Random();
  8398. UUID tid = AsyncCommands.
  8399. DataserverPlugin.RegisterRequest(m_host.LocalId, m_item.ItemID, rq.ToString());
  8400. AsyncCommands.
  8401. DataserverPlugin.DataserverReply(rq.ToString(), reply);
  8402. ScriptSleep(1000);
  8403. return tid.ToString();
  8404. }
  8405. catch(Exception)
  8406. {
  8407. //m_log.Error("[LSL_API]: llRequestSimulatorData" + e.ToString());
  8408. return UUID.Zero.ToString();
  8409. }
  8410. }
  8411. public LSL_String llRequestURL()
  8412. {
  8413. m_host.AddScriptLPS(1);
  8414. if (m_UrlModule != null)
  8415. return m_UrlModule.RequestURL(m_ScriptEngine.ScriptModule, m_host, m_item.ItemID).ToString();
  8416. return UUID.Zero.ToString();
  8417. }
  8418. public void llForceMouselook(int mouselook)
  8419. {
  8420. m_host.AddScriptLPS(1);
  8421. m_host.SetForceMouselook(mouselook != 0);
  8422. }
  8423. public LSL_Float llGetObjectMass(string id)
  8424. {
  8425. m_host.AddScriptLPS(1);
  8426. UUID key = new UUID();
  8427. if (UUID.TryParse(id, out key))
  8428. {
  8429. try
  8430. {
  8431. SceneObjectPart obj = World.GetSceneObjectPart(World.Entities[key].LocalId);
  8432. if (obj != null)
  8433. return (double)obj.GetMass();
  8434. // the object is null so the key is for an avatar
  8435. ScenePresence avatar = World.GetScenePresence(key);
  8436. if (avatar != null)
  8437. if (avatar.IsChildAgent)
  8438. // reference http://www.lslwiki.net/lslwiki/wakka.php?wakka=llGetObjectMass
  8439. // child agents have a mass of 1.0
  8440. return 1;
  8441. else
  8442. return (double)avatar.GetMass();
  8443. }
  8444. catch (KeyNotFoundException)
  8445. {
  8446. return 0; // The Object/Agent not in the region so just return zero
  8447. }
  8448. }
  8449. return 0;
  8450. }
  8451. /// <summary>
  8452. /// illListReplaceList removes the sub-list defined by the inclusive indices
  8453. /// start and end and inserts the src list in its place. The inclusive
  8454. /// nature of the indices means that at least one element must be deleted
  8455. /// if the indices are within the bounds of the existing list. I.e. 2,2
  8456. /// will remove the element at index 2 and replace it with the source
  8457. /// list. Both indices may be negative, with the usual interpretation. An
  8458. /// interesting case is where end is lower than start. As these indices
  8459. /// bound the list to be removed, then 0->end, and start->lim are removed
  8460. /// and the source list is added as a suffix.
  8461. /// </summary>
  8462. public LSL_List llListReplaceList(LSL_List dest, LSL_List src, int start, int end)
  8463. {
  8464. LSL_List pref = null;
  8465. m_host.AddScriptLPS(1);
  8466. // Note that although we have normalized, both
  8467. // indices could still be negative.
  8468. if (start < 0)
  8469. {
  8470. start = start+dest.Length;
  8471. }
  8472. if (end < 0)
  8473. {
  8474. end = end+dest.Length;
  8475. }
  8476. // The comventional case, remove a sequence starting with
  8477. // start and ending with end. And then insert the source
  8478. // list.
  8479. if (start <= end)
  8480. {
  8481. // If greater than zero, then there is going to be a
  8482. // surviving prefix. Otherwise the inclusive nature
  8483. // of the indices mean that we're going to add the
  8484. // source list as a prefix.
  8485. if (start > 0)
  8486. {
  8487. pref = dest.GetSublist(0,start-1);
  8488. // Only add a suffix if there is something
  8489. // beyond the end index (it's inclusive too).
  8490. if (end + 1 < dest.Length)
  8491. {
  8492. return pref + src + dest.GetSublist(end + 1, -1);
  8493. }
  8494. else
  8495. {
  8496. return pref + src;
  8497. }
  8498. }
  8499. // If start is less than or equal to zero, then
  8500. // the new list is simply a prefix. We still need to
  8501. // figure out any necessary surgery to the destination
  8502. // based upon end. Note that if end exceeds the upper
  8503. // bound in this case, the entire destination list
  8504. // is removed.
  8505. else
  8506. {
  8507. if (end + 1 < dest.Length)
  8508. {
  8509. return src + dest.GetSublist(end + 1, -1);
  8510. }
  8511. else
  8512. {
  8513. return src;
  8514. }
  8515. }
  8516. }
  8517. // Finally, if start > end, we strip away a prefix and
  8518. // a suffix, to leave the list that sits <between> ens
  8519. // and start, and then tag on the src list. AT least
  8520. // that's my interpretation. We can get sublist to do
  8521. // this for us. Note that one, or both of the indices
  8522. // might have been negative.
  8523. else
  8524. {
  8525. return dest.GetSublist(end + 1, start - 1) + src;
  8526. }
  8527. }
  8528. public void llLoadURL(string avatar_id, string message, string url)
  8529. {
  8530. m_host.AddScriptLPS(1);
  8531. IDialogModule dm = World.RequestModuleInterface<IDialogModule>();
  8532. if (null != dm)
  8533. dm.SendUrlToUser(
  8534. new UUID(avatar_id), m_host.Name, m_host.UUID, m_host.OwnerID, false, message, url);
  8535. ScriptSleep(10000);
  8536. }
  8537. public void llParcelMediaCommandList(LSL_List commandList)
  8538. {
  8539. // TODO: Not implemented yet (missing in libomv?):
  8540. // 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)
  8541. m_host.AddScriptLPS(1);
  8542. // according to the docs, this command only works if script owner and land owner are the same
  8543. // lets add estate owners and gods, too, and use the generic permission check.
  8544. ILandObject landObject = World.LandChannel.GetLandObject(m_host.AbsolutePosition);
  8545. if (!World.Permissions.CanEditParcelProperties(m_host.OwnerID, landObject, GroupPowers.ChangeMedia)) return;
  8546. bool update = false; // send a ParcelMediaUpdate (and possibly change the land's media URL)?
  8547. byte loop = 0;
  8548. LandData landData = landObject.LandData;
  8549. string url = landData.MediaURL;
  8550. string texture = landData.MediaID.ToString();
  8551. bool autoAlign = landData.MediaAutoScale != 0;
  8552. string mediaType = ""; // TODO these have to be added as soon as LandData supports it
  8553. string description = "";
  8554. int width = 0;
  8555. int height = 0;
  8556. ParcelMediaCommandEnum? commandToSend = null;
  8557. float time = 0.0f; // default is from start
  8558. ScenePresence presence = null;
  8559. for (int i = 0; i < commandList.Data.Length; i++)
  8560. {
  8561. ParcelMediaCommandEnum command = (ParcelMediaCommandEnum)commandList.Data[i];
  8562. switch (command)
  8563. {
  8564. case ParcelMediaCommandEnum.Agent:
  8565. // we send only to one agent
  8566. if ((i + 1) < commandList.Length)
  8567. {
  8568. if (commandList.Data[i + 1] is LSL_String)
  8569. {
  8570. UUID agentID;
  8571. if (UUID.TryParse((LSL_String)commandList.Data[i + 1], out agentID))
  8572. {
  8573. presence = World.GetScenePresence(agentID);
  8574. }
  8575. }
  8576. else Error("llParcelMediaCommandList", "The argument of PARCEL_MEDIA_COMMAND_AGENT must be a key");
  8577. ++i;
  8578. }
  8579. break;
  8580. case ParcelMediaCommandEnum.Loop:
  8581. loop = 1;
  8582. commandToSend = command;
  8583. update = true; //need to send the media update packet to set looping
  8584. break;
  8585. case ParcelMediaCommandEnum.Play:
  8586. loop = 0;
  8587. commandToSend = command;
  8588. update = true; //need to send the media update packet to make sure it doesn't loop
  8589. break;
  8590. case ParcelMediaCommandEnum.Pause:
  8591. case ParcelMediaCommandEnum.Stop:
  8592. case ParcelMediaCommandEnum.Unload:
  8593. commandToSend = command;
  8594. break;
  8595. case ParcelMediaCommandEnum.Url:
  8596. if ((i + 1) < commandList.Length)
  8597. {
  8598. if (commandList.Data[i + 1] is LSL_String)
  8599. {
  8600. url = (LSL_String)commandList.Data[i + 1];
  8601. update = true;
  8602. }
  8603. else Error("llParcelMediaCommandList", "The argument of PARCEL_MEDIA_COMMAND_URL must be a string");
  8604. ++i;
  8605. }
  8606. break;
  8607. case ParcelMediaCommandEnum.Texture:
  8608. if ((i + 1) < commandList.Length)
  8609. {
  8610. if (commandList.Data[i + 1] is LSL_String)
  8611. {
  8612. texture = (LSL_String)commandList.Data[i + 1];
  8613. update = true;
  8614. }
  8615. else Error("llParcelMediaCommandList", "The argument of PARCEL_MEDIA_COMMAND_TEXTURE must be a string or a key");
  8616. ++i;
  8617. }
  8618. break;
  8619. case ParcelMediaCommandEnum.Time:
  8620. if ((i + 1) < commandList.Length)
  8621. {
  8622. if (commandList.Data[i + 1] is LSL_Float)
  8623. {
  8624. time = (float)(LSL_Float)commandList.Data[i + 1];
  8625. }
  8626. else Error("llParcelMediaCommandList", "The argument of PARCEL_MEDIA_COMMAND_TIME must be a float");
  8627. ++i;
  8628. }
  8629. break;
  8630. case ParcelMediaCommandEnum.AutoAlign:
  8631. if ((i + 1) < commandList.Length)
  8632. {
  8633. if (commandList.Data[i + 1] is LSL_Integer)
  8634. {
  8635. autoAlign = (LSL_Integer)commandList.Data[i + 1];
  8636. update = true;
  8637. }
  8638. else Error("llParcelMediaCommandList", "The argument of PARCEL_MEDIA_COMMAND_AUTO_ALIGN must be an integer");
  8639. ++i;
  8640. }
  8641. break;
  8642. case ParcelMediaCommandEnum.Type:
  8643. if ((i + 1) < commandList.Length)
  8644. {
  8645. if (commandList.Data[i + 1] is LSL_String)
  8646. {
  8647. mediaType = (LSL_String)commandList.Data[i + 1];
  8648. update = true;
  8649. }
  8650. else Error("llParcelMediaCommandList", "The argument of PARCEL_MEDIA_COMMAND_TYPE must be a string");
  8651. ++i;
  8652. }
  8653. break;
  8654. case ParcelMediaCommandEnum.Desc:
  8655. if ((i + 1) < commandList.Length)
  8656. {
  8657. if (commandList.Data[i + 1] is LSL_String)
  8658. {
  8659. description = (LSL_String)commandList.Data[i + 1];
  8660. update = true;
  8661. }
  8662. else Error("llParcelMediaCommandList", "The argument of PARCEL_MEDIA_COMMAND_DESC must be a string");
  8663. ++i;
  8664. }
  8665. break;
  8666. case ParcelMediaCommandEnum.Size:
  8667. if ((i + 2) < commandList.Length)
  8668. {
  8669. if (commandList.Data[i + 1] is LSL_Integer)
  8670. {
  8671. if (commandList.Data[i + 2] is LSL_Integer)
  8672. {
  8673. width = (LSL_Integer)commandList.Data[i + 1];
  8674. height = (LSL_Integer)commandList.Data[i + 2];
  8675. update = true;
  8676. }
  8677. else Error("llParcelMediaCommandList", "The second argument of PARCEL_MEDIA_COMMAND_SIZE must be an integer");
  8678. }
  8679. else Error("llParcelMediaCommandList", "The first argument of PARCEL_MEDIA_COMMAND_SIZE must be an integer");
  8680. i += 2;
  8681. }
  8682. break;
  8683. default:
  8684. NotImplemented("llParcelMediaCommandList", "Parameter not supported yet: " + Enum.Parse(typeof(ParcelMediaCommandEnum), commandList.Data[i].ToString()).ToString());
  8685. break;
  8686. }//end switch
  8687. }//end for
  8688. // if we didn't get a presence, we send to all and change the url
  8689. // if we did get a presence, we only send to the agent specified, and *don't change the land settings*!
  8690. // did something important change or do we only start/stop/pause?
  8691. if (update)
  8692. {
  8693. if (presence == null)
  8694. {
  8695. // we send to all
  8696. landData.MediaID = new UUID(texture);
  8697. landData.MediaAutoScale = autoAlign ? (byte)1 : (byte)0;
  8698. landData.MediaWidth = width;
  8699. landData.MediaHeight = height;
  8700. landData.MediaType = mediaType;
  8701. // do that one last, it will cause a ParcelPropertiesUpdate
  8702. landObject.SetMediaUrl(url);
  8703. // now send to all (non-child) agents in the parcel
  8704. World.ForEachRootScenePresence(delegate(ScenePresence sp)
  8705. {
  8706. if (sp.currentParcelUUID == landData.GlobalID)
  8707. {
  8708. sp.ControllingClient.SendParcelMediaUpdate(landData.MediaURL,
  8709. landData.MediaID,
  8710. landData.MediaAutoScale,
  8711. mediaType,
  8712. description,
  8713. width, height,
  8714. loop);
  8715. }
  8716. });
  8717. }
  8718. else if (!presence.IsChildAgent)
  8719. {
  8720. // we only send to one (root) agent
  8721. presence.ControllingClient.SendParcelMediaUpdate(url,
  8722. new UUID(texture),
  8723. autoAlign ? (byte)1 : (byte)0,
  8724. mediaType,
  8725. description,
  8726. width, height,
  8727. loop);
  8728. }
  8729. }
  8730. if (commandToSend != null)
  8731. {
  8732. // the commandList contained a start/stop/... command, too
  8733. if (presence == null)
  8734. {
  8735. // send to all (non-child) agents in the parcel
  8736. World.ForEachRootScenePresence(delegate(ScenePresence sp)
  8737. {
  8738. if (sp.currentParcelUUID == landData.GlobalID)
  8739. {
  8740. sp.ControllingClient.SendParcelMediaCommand(0x4, // TODO what is this?
  8741. (ParcelMediaCommandEnum)commandToSend,
  8742. time);
  8743. }
  8744. });
  8745. }
  8746. else if (!presence.IsChildAgent)
  8747. {
  8748. presence.ControllingClient.SendParcelMediaCommand(0x4, // TODO what is this?
  8749. (ParcelMediaCommandEnum)commandToSend,
  8750. time);
  8751. }
  8752. }
  8753. ScriptSleep(2000);
  8754. }
  8755. public LSL_List llParcelMediaQuery(LSL_List aList)
  8756. {
  8757. m_host.AddScriptLPS(1);
  8758. LSL_List list = new LSL_List();
  8759. //TO DO: make the implementation for the missing commands
  8760. //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)
  8761. for (int i = 0; i < aList.Data.Length; i++)
  8762. {
  8763. if (aList.Data[i] != null)
  8764. {
  8765. switch ((ParcelMediaCommandEnum) aList.Data[i])
  8766. {
  8767. case ParcelMediaCommandEnum.Url:
  8768. list.Add(new LSL_String(World.GetLandData(m_host.AbsolutePosition).MediaURL));
  8769. break;
  8770. case ParcelMediaCommandEnum.Desc:
  8771. list.Add(new LSL_String(World.GetLandData(m_host.AbsolutePosition).Description));
  8772. break;
  8773. case ParcelMediaCommandEnum.Texture:
  8774. list.Add(new LSL_String(World.GetLandData(m_host.AbsolutePosition).MediaID.ToString()));
  8775. break;
  8776. case ParcelMediaCommandEnum.Type:
  8777. list.Add(new LSL_String(World.GetLandData(m_host.AbsolutePosition).MediaType));
  8778. break;
  8779. case ParcelMediaCommandEnum.Size:
  8780. list.Add(new LSL_String(World.GetLandData(m_host.AbsolutePosition).MediaWidth));
  8781. list.Add(new LSL_String(World.GetLandData(m_host.AbsolutePosition).MediaHeight));
  8782. break;
  8783. default:
  8784. ParcelMediaCommandEnum mediaCommandEnum = ParcelMediaCommandEnum.Url;
  8785. NotImplemented("llParcelMediaQuery", "Parameter not supported yet: " + Enum.Parse(mediaCommandEnum.GetType() , aList.Data[i].ToString()).ToString());
  8786. break;
  8787. }
  8788. }
  8789. }
  8790. ScriptSleep(2000);
  8791. return list;
  8792. }
  8793. public LSL_Integer llModPow(int a, int b, int c)
  8794. {
  8795. m_host.AddScriptLPS(1);
  8796. Int64 tmp = 0;
  8797. Math.DivRem(Convert.ToInt64(Math.Pow(a, b)), c, out tmp);
  8798. ScriptSleep(1000);
  8799. return Convert.ToInt32(tmp);
  8800. }
  8801. public LSL_Integer llGetInventoryType(string name)
  8802. {
  8803. m_host.AddScriptLPS(1);
  8804. TaskInventoryItem item = m_host.Inventory.GetInventoryItem(name);
  8805. if (item == null)
  8806. return -1;
  8807. return item.Type;
  8808. }
  8809. public void llSetPayPrice(int price, LSL_List quick_pay_buttons)
  8810. {
  8811. m_host.AddScriptLPS(1);
  8812. if (quick_pay_buttons.Data.Length < 4)
  8813. {
  8814. Error("llSetPayPrice", "List must have at least 4 elements");
  8815. return;
  8816. }
  8817. m_host.ParentGroup.RootPart.PayPrice[0]=price;
  8818. m_host.ParentGroup.RootPart.PayPrice[1]=(LSL_Integer)quick_pay_buttons.Data[0];
  8819. m_host.ParentGroup.RootPart.PayPrice[2]=(LSL_Integer)quick_pay_buttons.Data[1];
  8820. m_host.ParentGroup.RootPart.PayPrice[3]=(LSL_Integer)quick_pay_buttons.Data[2];
  8821. m_host.ParentGroup.RootPart.PayPrice[4]=(LSL_Integer)quick_pay_buttons.Data[3];
  8822. m_host.ParentGroup.HasGroupChanged = true;
  8823. }
  8824. public LSL_Vector llGetCameraPos()
  8825. {
  8826. m_host.AddScriptLPS(1);
  8827. if (m_item.PermsGranter == UUID.Zero)
  8828. return Vector3.Zero;
  8829. if ((m_item.PermsMask & ScriptBaseClass.PERMISSION_TRACK_CAMERA) == 0)
  8830. {
  8831. Error("llGetCameraPos", "No permissions to track the camera");
  8832. return Vector3.Zero;
  8833. }
  8834. ScenePresence presence = World.GetScenePresence(m_host.OwnerID);
  8835. if (presence != null)
  8836. {
  8837. LSL_Vector pos = new LSL_Vector(presence.CameraPosition);
  8838. return pos;
  8839. }
  8840. return Vector3.Zero;
  8841. }
  8842. public LSL_Rotation llGetCameraRot()
  8843. {
  8844. m_host.AddScriptLPS(1);
  8845. if (m_item.PermsGranter == UUID.Zero)
  8846. return Quaternion.Identity;
  8847. if ((m_item.PermsMask & ScriptBaseClass.PERMISSION_TRACK_CAMERA) == 0)
  8848. {
  8849. Error("llGetCameraRot", "No permissions to track the camera");
  8850. return Quaternion.Identity;
  8851. }
  8852. ScenePresence presence = World.GetScenePresence(m_host.OwnerID);
  8853. if (presence != null)
  8854. {
  8855. return new LSL_Rotation(presence.CameraRotation);
  8856. }
  8857. return Quaternion.Identity;
  8858. }
  8859. public void llSetPrimURL(string url)
  8860. {
  8861. m_host.AddScriptLPS(1);
  8862. Deprecated("llSetPrimURL", "Use llSetPrimMediaParams instead");
  8863. ScriptSleep(2000);
  8864. }
  8865. public void llRefreshPrimURL()
  8866. {
  8867. m_host.AddScriptLPS(1);
  8868. Deprecated("llRefreshPrimURL");
  8869. ScriptSleep(20000);
  8870. }
  8871. public LSL_String llEscapeURL(string url)
  8872. {
  8873. m_host.AddScriptLPS(1);
  8874. try
  8875. {
  8876. return Uri.EscapeDataString(url);
  8877. }
  8878. catch (Exception ex)
  8879. {
  8880. return "llEscapeURL: " + ex.ToString();
  8881. }
  8882. }
  8883. public LSL_String llUnescapeURL(string url)
  8884. {
  8885. m_host.AddScriptLPS(1);
  8886. try
  8887. {
  8888. return Uri.UnescapeDataString(url);
  8889. }
  8890. catch (Exception ex)
  8891. {
  8892. return "llUnescapeURL: " + ex.ToString();
  8893. }
  8894. }
  8895. public void llMapDestination(string simname, LSL_Vector pos, LSL_Vector lookAt)
  8896. {
  8897. m_host.AddScriptLPS(1);
  8898. DetectParams detectedParams = m_ScriptEngine.GetDetectParams(m_item.ItemID, 0);
  8899. if (detectedParams == null) return; // only works on the first detected avatar
  8900. ScenePresence avatar = World.GetScenePresence(detectedParams.Key);
  8901. if (avatar != null)
  8902. {
  8903. avatar.ControllingClient.SendScriptTeleportRequest(m_host.Name,
  8904. simname, pos, lookAt);
  8905. }
  8906. ScriptSleep(1000);
  8907. }
  8908. public void llAddToLandBanList(string avatar, double hours)
  8909. {
  8910. m_host.AddScriptLPS(1);
  8911. UUID key;
  8912. ILandObject land = World.LandChannel.GetLandObject(m_host.AbsolutePosition);
  8913. if (World.Permissions.CanEditParcelProperties(m_host.OwnerID, land, GroupPowers.LandManageBanned))
  8914. {
  8915. int expires = 0;
  8916. if (hours != 0)
  8917. expires = Util.UnixTimeSinceEpoch() + (int)(3600.0 * hours);
  8918. if (UUID.TryParse(avatar, out key))
  8919. {
  8920. int idx = land.LandData.ParcelAccessList.FindIndex(
  8921. delegate(LandAccessEntry e)
  8922. {
  8923. if (e.AgentID == key && e.Flags == AccessList.Ban)
  8924. return true;
  8925. return false;
  8926. });
  8927. if (idx != -1 && (land.LandData.ParcelAccessList[idx].Expires == 0 || (expires != 0 && expires < land.LandData.ParcelAccessList[idx].Expires)))
  8928. return;
  8929. if (idx != -1)
  8930. land.LandData.ParcelAccessList.RemoveAt(idx);
  8931. LandAccessEntry entry = new LandAccessEntry();
  8932. entry.AgentID = key;
  8933. entry.Flags = AccessList.Ban;
  8934. entry.Expires = expires;
  8935. land.LandData.ParcelAccessList.Add(entry);
  8936. World.EventManager.TriggerLandObjectUpdated((uint)land.LandData.LocalID, land);
  8937. }
  8938. }
  8939. ScriptSleep(100);
  8940. }
  8941. public void llRemoveFromLandPassList(string avatar)
  8942. {
  8943. m_host.AddScriptLPS(1);
  8944. UUID key;
  8945. ILandObject land = World.LandChannel.GetLandObject(m_host.AbsolutePosition);
  8946. if (World.Permissions.CanEditParcelProperties(m_host.OwnerID, land, GroupPowers.LandManageAllowed))
  8947. {
  8948. if (UUID.TryParse(avatar, out key))
  8949. {
  8950. int idx = land.LandData.ParcelAccessList.FindIndex(
  8951. delegate(LandAccessEntry e)
  8952. {
  8953. if (e.AgentID == key && e.Flags == AccessList.Access)
  8954. return true;
  8955. return false;
  8956. });
  8957. if (idx != -1)
  8958. {
  8959. land.LandData.ParcelAccessList.RemoveAt(idx);
  8960. World.EventManager.TriggerLandObjectUpdated((uint)land.LandData.LocalID, land);
  8961. }
  8962. }
  8963. }
  8964. ScriptSleep(100);
  8965. }
  8966. public void llRemoveFromLandBanList(string avatar)
  8967. {
  8968. m_host.AddScriptLPS(1);
  8969. UUID key;
  8970. ILandObject land = World.LandChannel.GetLandObject(m_host.AbsolutePosition);
  8971. if (World.Permissions.CanEditParcelProperties(m_host.OwnerID, land, GroupPowers.LandManageBanned))
  8972. {
  8973. if (UUID.TryParse(avatar, out key))
  8974. {
  8975. int idx = land.LandData.ParcelAccessList.FindIndex(
  8976. delegate(LandAccessEntry e)
  8977. {
  8978. if (e.AgentID == key && e.Flags == AccessList.Ban)
  8979. return true;
  8980. return false;
  8981. });
  8982. if (idx != -1)
  8983. {
  8984. land.LandData.ParcelAccessList.RemoveAt(idx);
  8985. World.EventManager.TriggerLandObjectUpdated((uint)land.LandData.LocalID, land);
  8986. }
  8987. }
  8988. }
  8989. ScriptSleep(100);
  8990. }
  8991. public void llSetCameraParams(LSL_List rules)
  8992. {
  8993. m_host.AddScriptLPS(1);
  8994. // the object we are in
  8995. UUID objectID = m_host.ParentUUID;
  8996. if (objectID == UUID.Zero)
  8997. return;
  8998. // we need the permission first, to know which avatar we want to set the camera for
  8999. UUID agentID = m_item.PermsGranter;
  9000. if (agentID == UUID.Zero)
  9001. return;
  9002. if ((m_item.PermsMask & ScriptBaseClass.PERMISSION_CONTROL_CAMERA) == 0)
  9003. return;
  9004. ScenePresence presence = World.GetScenePresence(agentID);
  9005. // we are not interested in child-agents
  9006. if (presence.IsChildAgent) return;
  9007. SortedDictionary<int, float> parameters = new SortedDictionary<int, float>();
  9008. object[] data = rules.Data;
  9009. for (int i = 0; i < data.Length; ++i) {
  9010. int type = Convert.ToInt32(data[i++].ToString());
  9011. if (i >= data.Length) break; // odd number of entries => ignore the last
  9012. // some special cases: Vector parameters are split into 3 float parameters (with type+1, type+2, type+3)
  9013. switch (type) {
  9014. case ScriptBaseClass.CAMERA_FOCUS:
  9015. case ScriptBaseClass.CAMERA_FOCUS_OFFSET:
  9016. case ScriptBaseClass.CAMERA_POSITION:
  9017. LSL_Vector v = (LSL_Vector)data[i];
  9018. parameters.Add(type + 1, (float)v.x);
  9019. parameters.Add(type + 2, (float)v.y);
  9020. parameters.Add(type + 3, (float)v.z);
  9021. break;
  9022. default:
  9023. // TODO: clean that up as soon as the implicit casts are in
  9024. if (data[i] is LSL_Float)
  9025. parameters.Add(type, (float)((LSL_Float)data[i]).value);
  9026. else if (data[i] is LSL_Integer)
  9027. parameters.Add(type, (float)((LSL_Integer)data[i]).value);
  9028. else parameters.Add(type, Convert.ToSingle(data[i]));
  9029. break;
  9030. }
  9031. }
  9032. if (parameters.Count > 0) presence.ControllingClient.SendSetFollowCamProperties(objectID, parameters);
  9033. }
  9034. public void llClearCameraParams()
  9035. {
  9036. m_host.AddScriptLPS(1);
  9037. // the object we are in
  9038. UUID objectID = m_host.ParentUUID;
  9039. if (objectID == UUID.Zero)
  9040. return;
  9041. // we need the permission first, to know which avatar we want to clear the camera for
  9042. UUID agentID = m_item.PermsGranter;
  9043. if (agentID == UUID.Zero)
  9044. return;
  9045. if ((m_item.PermsMask & ScriptBaseClass.PERMISSION_CONTROL_CAMERA) == 0)
  9046. return;
  9047. ScenePresence presence = World.GetScenePresence(agentID);
  9048. // we are not interested in child-agents
  9049. if (presence.IsChildAgent)
  9050. return;
  9051. presence.ControllingClient.SendClearFollowCamProperties(objectID);
  9052. }
  9053. public LSL_Float llListStatistics(int operation, LSL_List src)
  9054. {
  9055. m_host.AddScriptLPS(1);
  9056. switch (operation)
  9057. {
  9058. case ScriptBaseClass.LIST_STAT_RANGE:
  9059. return src.Range();
  9060. case ScriptBaseClass.LIST_STAT_MIN:
  9061. return src.Min();
  9062. case ScriptBaseClass.LIST_STAT_MAX:
  9063. return src.Max();
  9064. case ScriptBaseClass.LIST_STAT_MEAN:
  9065. return src.Mean();
  9066. case ScriptBaseClass.LIST_STAT_MEDIAN:
  9067. return LSL_List.ToDoubleList(src).Median();
  9068. case ScriptBaseClass.LIST_STAT_NUM_COUNT:
  9069. return src.NumericLength();
  9070. case ScriptBaseClass.LIST_STAT_STD_DEV:
  9071. return src.StdDev();
  9072. case ScriptBaseClass.LIST_STAT_SUM:
  9073. return src.Sum();
  9074. case ScriptBaseClass.LIST_STAT_SUM_SQUARES:
  9075. return src.SumSqrs();
  9076. case ScriptBaseClass.LIST_STAT_GEOMETRIC_MEAN:
  9077. return src.GeometricMean();
  9078. case ScriptBaseClass.LIST_STAT_HARMONIC_MEAN:
  9079. return src.HarmonicMean();
  9080. default:
  9081. return 0.0;
  9082. }
  9083. }
  9084. public LSL_Integer llGetUnixTime()
  9085. {
  9086. m_host.AddScriptLPS(1);
  9087. return Util.UnixTimeSinceEpoch();
  9088. }
  9089. public LSL_Integer llGetParcelFlags(LSL_Vector pos)
  9090. {
  9091. m_host.AddScriptLPS(1);
  9092. return (int)World.LandChannel.GetLandObject((float)pos.x, (float)pos.y).LandData.Flags;
  9093. }
  9094. public LSL_Integer llGetRegionFlags()
  9095. {
  9096. m_host.AddScriptLPS(1);
  9097. IEstateModule estate = World.RequestModuleInterface<IEstateModule>();
  9098. if (estate == null)
  9099. return 67108864;
  9100. return (int)estate.GetRegionFlags();
  9101. }
  9102. public LSL_String llXorBase64StringsCorrect(string str1, string str2)
  9103. {
  9104. m_host.AddScriptLPS(1);
  9105. string ret = String.Empty;
  9106. string src1 = llBase64ToString(str1);
  9107. string src2 = llBase64ToString(str2);
  9108. int c = 0;
  9109. for (int i = 0; i < src1.Length; i++)
  9110. {
  9111. ret += (char) (src1[i] ^ src2[c]);
  9112. c++;
  9113. if (c >= src2.Length)
  9114. c = 0;
  9115. }
  9116. return llStringToBase64(ret);
  9117. }
  9118. public LSL_String llHTTPRequest(string url, LSL_List parameters, string body)
  9119. {
  9120. // Partial implementation: support for parameter flags needed
  9121. // see http://wiki.secondlife.com/wiki/LlHTTPRequest
  9122. // parameter flags support are implemented in ScriptsHttpRequests.cs
  9123. // in StartHttpRequest
  9124. m_host.AddScriptLPS(1);
  9125. IHttpRequestModule httpScriptMod =
  9126. m_ScriptEngine.World.RequestModuleInterface<IHttpRequestModule>();
  9127. List<string> param = new List<string>();
  9128. bool ok;
  9129. Int32 flag;
  9130. for (int i = 0; i < parameters.Data.Length; i += 2)
  9131. {
  9132. ok = Int32.TryParse(parameters.Data[i].ToString(), out flag);
  9133. if (!ok || flag < 0 ||
  9134. flag > (int)HttpRequestConstants.HTTP_PRAGMA_NO_CACHE)
  9135. {
  9136. Error("llHTTPRequest", "Parameter " + i.ToString() + " is an invalid flag");
  9137. }
  9138. param.Add(parameters.Data[i].ToString()); //Add parameter flag
  9139. if (flag != (int)HttpRequestConstants.HTTP_CUSTOM_HEADER)
  9140. {
  9141. param.Add(parameters.Data[i+1].ToString()); //Add parameter value
  9142. }
  9143. else
  9144. {
  9145. //Parameters are in pairs and custom header takes
  9146. //arguments in pairs so adjust for header marker.
  9147. ++i;
  9148. //Maximum of 8 headers are allowed based on the
  9149. //Second Life documentation for llHTTPRequest.
  9150. for (int count = 1; count <= 8; ++count)
  9151. {
  9152. //Enough parameters remaining for (another) header?
  9153. if (parameters.Data.Length - i < 2)
  9154. {
  9155. //There must be at least one name/value pair for custom header
  9156. if (count == 1)
  9157. Error("llHTTPRequest", "Missing name/value for custom header at parameter " + i.ToString());
  9158. break;
  9159. }
  9160. if (HttpStandardHeaders.Contains(parameters.Data[i].ToString(), StringComparer.OrdinalIgnoreCase))
  9161. Error("llHTTPRequest", "Name is invalid as a custom header at parameter " + i.ToString());
  9162. param.Add(parameters.Data[i].ToString());
  9163. param.Add(parameters.Data[i+1].ToString());
  9164. //Have we reached the end of the list of headers?
  9165. //End is marked by a string with a single digit.
  9166. if (i+2 >= parameters.Data.Length ||
  9167. Char.IsDigit(parameters.Data[i].ToString()[0]))
  9168. {
  9169. break;
  9170. }
  9171. i += 2;
  9172. }
  9173. }
  9174. }
  9175. Vector3 position = m_host.AbsolutePosition;
  9176. Vector3 velocity = m_host.Velocity;
  9177. Quaternion rotation = m_host.RotationOffset;
  9178. string ownerName = String.Empty;
  9179. ScenePresence scenePresence = World.GetScenePresence(m_host.OwnerID);
  9180. if (scenePresence == null)
  9181. ownerName = resolveName(m_host.OwnerID);
  9182. else
  9183. ownerName = scenePresence.Name;
  9184. RegionInfo regionInfo = World.RegionInfo;
  9185. Dictionary<string, string> httpHeaders = new Dictionary<string, string>();
  9186. string shard = "OpenSim";
  9187. IConfigSource config = m_ScriptEngine.ConfigSource;
  9188. if (config.Configs["Network"] != null)
  9189. {
  9190. shard = config.Configs["Network"].GetString("shard", shard);
  9191. }
  9192. httpHeaders["X-SecondLife-Shard"] = shard;
  9193. httpHeaders["X-SecondLife-Object-Name"] = m_host.Name;
  9194. httpHeaders["X-SecondLife-Object-Key"] = m_host.UUID.ToString();
  9195. httpHeaders["X-SecondLife-Region"] = string.Format("{0} ({1}, {2})", regionInfo.RegionName, regionInfo.RegionLocX, regionInfo.RegionLocY);
  9196. httpHeaders["X-SecondLife-Local-Position"] = string.Format("({0:0.000000}, {1:0.000000}, {2:0.000000})", position.X, position.Y, position.Z);
  9197. httpHeaders["X-SecondLife-Local-Velocity"] = string.Format("({0:0.000000}, {1:0.000000}, {2:0.000000})", velocity.X, velocity.Y, velocity.Z);
  9198. 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);
  9199. httpHeaders["X-SecondLife-Owner-Name"] = ownerName;
  9200. httpHeaders["X-SecondLife-Owner-Key"] = m_host.OwnerID.ToString();
  9201. string userAgent = config.Configs["Network"].GetString("user_agent", null);
  9202. if (userAgent != null)
  9203. httpHeaders["User-Agent"] = userAgent;
  9204. string authregex = @"^(https?:\/\/)(\w+):(\w+)@(.*)$";
  9205. Regex r = new Regex(authregex);
  9206. int[] gnums = r.GetGroupNumbers();
  9207. Match m = r.Match(url);
  9208. if (m.Success) {
  9209. for (int i = 1; i < gnums.Length; i++) {
  9210. //System.Text.RegularExpressions.Group g = m.Groups[gnums[i]];
  9211. //CaptureCollection cc = g.Captures;
  9212. }
  9213. if (m.Groups.Count == 5) {
  9214. httpHeaders["Authorization"] = String.Format("Basic {0}", Convert.ToBase64String(System.Text.ASCIIEncoding.ASCII.GetBytes(m.Groups[2].ToString() + ":" + m.Groups[3].ToString())));
  9215. url = m.Groups[1].ToString() + m.Groups[4].ToString();
  9216. }
  9217. }
  9218. UUID reqID
  9219. = httpScriptMod.StartHttpRequest(m_host.LocalId, m_item.ItemID, url, param, httpHeaders, body);
  9220. if (reqID != UUID.Zero)
  9221. return reqID.ToString();
  9222. else
  9223. return null;
  9224. }
  9225. public void llHTTPResponse(LSL_Key id, int status, string body)
  9226. {
  9227. // Partial implementation: support for parameter flags needed
  9228. // see http://wiki.secondlife.com/wiki/llHTTPResponse
  9229. m_host.AddScriptLPS(1);
  9230. if (m_UrlModule != null)
  9231. m_UrlModule.HttpResponse(new UUID(id), status,body);
  9232. }
  9233. public void llResetLandBanList()
  9234. {
  9235. m_host.AddScriptLPS(1);
  9236. LandData land = World.LandChannel.GetLandObject(m_host.AbsolutePosition).LandData;
  9237. if (land.OwnerID == m_host.OwnerID)
  9238. {
  9239. foreach (LandAccessEntry entry in land.ParcelAccessList)
  9240. {
  9241. if (entry.Flags == AccessList.Ban)
  9242. {
  9243. land.ParcelAccessList.Remove(entry);
  9244. }
  9245. }
  9246. }
  9247. ScriptSleep(100);
  9248. }
  9249. public void llResetLandPassList()
  9250. {
  9251. m_host.AddScriptLPS(1);
  9252. LandData land = World.LandChannel.GetLandObject(m_host.AbsolutePosition).LandData;
  9253. if (land.OwnerID == m_host.OwnerID)
  9254. {
  9255. foreach (LandAccessEntry entry in land.ParcelAccessList)
  9256. {
  9257. if (entry.Flags == AccessList.Access)
  9258. {
  9259. land.ParcelAccessList.Remove(entry);
  9260. }
  9261. }
  9262. }
  9263. ScriptSleep(100);
  9264. }
  9265. public LSL_Integer llGetParcelPrimCount(LSL_Vector pos, int category, int sim_wide)
  9266. {
  9267. m_host.AddScriptLPS(1);
  9268. ILandObject lo = World.LandChannel.GetLandObject((float)pos.x, (float)pos.y);
  9269. if (lo == null)
  9270. return 0;
  9271. IPrimCounts pc = lo.PrimCounts;
  9272. if (sim_wide != ScriptBaseClass.FALSE)
  9273. {
  9274. if (category == ScriptBaseClass.PARCEL_COUNT_TOTAL)
  9275. {
  9276. return pc.Simulator;
  9277. }
  9278. else
  9279. {
  9280. // counts not implemented yet
  9281. return 0;
  9282. }
  9283. }
  9284. else
  9285. {
  9286. if (category == ScriptBaseClass.PARCEL_COUNT_TOTAL)
  9287. return pc.Total;
  9288. else if (category == ScriptBaseClass.PARCEL_COUNT_OWNER)
  9289. return pc.Owner;
  9290. else if (category == ScriptBaseClass.PARCEL_COUNT_GROUP)
  9291. return pc.Group;
  9292. else if (category == ScriptBaseClass.PARCEL_COUNT_OTHER)
  9293. return pc.Others;
  9294. else if (category == ScriptBaseClass.PARCEL_COUNT_SELECTED)
  9295. return pc.Selected;
  9296. else if (category == ScriptBaseClass.PARCEL_COUNT_TEMP)
  9297. return 0; // counts not implemented yet
  9298. }
  9299. return 0;
  9300. }
  9301. public LSL_List llGetParcelPrimOwners(LSL_Vector pos)
  9302. {
  9303. m_host.AddScriptLPS(1);
  9304. LandObject land = (LandObject)World.LandChannel.GetLandObject((float)pos.x, (float)pos.y);
  9305. LSL_List ret = new LSL_List();
  9306. if (land != null)
  9307. {
  9308. foreach (KeyValuePair<UUID, int> detectedParams in land.GetLandObjectOwners())
  9309. {
  9310. ret.Add(new LSL_String(detectedParams.Key.ToString()));
  9311. ret.Add(new LSL_Integer(detectedParams.Value));
  9312. }
  9313. }
  9314. ScriptSleep(2000);
  9315. return ret;
  9316. }
  9317. public LSL_Integer llGetObjectPrimCount(string object_id)
  9318. {
  9319. m_host.AddScriptLPS(1);
  9320. SceneObjectPart part = World.GetSceneObjectPart(new UUID(object_id));
  9321. if (part == null)
  9322. {
  9323. return 0;
  9324. }
  9325. else
  9326. {
  9327. return part.ParentGroup.PrimCount;
  9328. }
  9329. }
  9330. public LSL_Integer llGetParcelMaxPrims(LSL_Vector pos, int sim_wide)
  9331. {
  9332. m_host.AddScriptLPS(1);
  9333. ILandObject lo = World.LandChannel.GetLandObject((float)pos.x, (float)pos.y);
  9334. if (lo == null)
  9335. return 0;
  9336. if (sim_wide != 0)
  9337. return lo.GetSimulatorMaxPrimCount();
  9338. else
  9339. return lo.GetParcelMaxPrimCount();
  9340. }
  9341. public LSL_List llGetParcelDetails(LSL_Vector pos, LSL_List param)
  9342. {
  9343. m_host.AddScriptLPS(1);
  9344. LandData land = World.GetLandData(pos);
  9345. if (land == null)
  9346. {
  9347. return new LSL_List(0);
  9348. }
  9349. LSL_List ret = new LSL_List();
  9350. foreach (object o in param.Data)
  9351. {
  9352. switch (o.ToString())
  9353. {
  9354. case "0":
  9355. ret.Add(new LSL_String(land.Name));
  9356. break;
  9357. case "1":
  9358. ret.Add(new LSL_String(land.Description));
  9359. break;
  9360. case "2":
  9361. ret.Add(new LSL_Key(land.OwnerID.ToString()));
  9362. break;
  9363. case "3":
  9364. ret.Add(new LSL_Key(land.GroupID.ToString()));
  9365. break;
  9366. case "4":
  9367. ret.Add(new LSL_Integer(land.Area));
  9368. break;
  9369. case "5":
  9370. ret.Add(new LSL_Key(land.GlobalID.ToString()));
  9371. break;
  9372. default:
  9373. ret.Add(new LSL_Integer(0));
  9374. break;
  9375. }
  9376. }
  9377. return ret;
  9378. }
  9379. public LSL_String llStringTrim(string src, int type)
  9380. {
  9381. m_host.AddScriptLPS(1);
  9382. if (type == (int)ScriptBaseClass.STRING_TRIM_HEAD) { return src.TrimStart(); }
  9383. if (type == (int)ScriptBaseClass.STRING_TRIM_TAIL) { return src.TrimEnd(); }
  9384. if (type == (int)ScriptBaseClass.STRING_TRIM) { return src.Trim(); }
  9385. return src;
  9386. }
  9387. public LSL_List llGetObjectDetails(string id, LSL_List args)
  9388. {
  9389. m_host.AddScriptLPS(1);
  9390. LSL_List ret = new LSL_List();
  9391. UUID key = new UUID();
  9392. if (UUID.TryParse(id, out key))
  9393. {
  9394. ScenePresence av = World.GetScenePresence(key);
  9395. if (av != null)
  9396. {
  9397. foreach (object o in args.Data)
  9398. {
  9399. switch (int.Parse(o.ToString()))
  9400. {
  9401. case ScriptBaseClass.OBJECT_NAME:
  9402. ret.Add(new LSL_String(av.Firstname + " " + av.Lastname));
  9403. break;
  9404. case ScriptBaseClass.OBJECT_DESC:
  9405. ret.Add(new LSL_String(""));
  9406. break;
  9407. case ScriptBaseClass.OBJECT_POS:
  9408. ret.Add(new LSL_Vector((double)av.AbsolutePosition.X, (double)av.AbsolutePosition.Y, (double)av.AbsolutePosition.Z));
  9409. break;
  9410. case ScriptBaseClass.OBJECT_ROT:
  9411. ret.Add(new LSL_Rotation(av.GetWorldRotation()));
  9412. break;
  9413. case ScriptBaseClass.OBJECT_VELOCITY:
  9414. ret.Add(new LSL_Vector(av.Velocity.X, av.Velocity.Y, av.Velocity.Z));
  9415. break;
  9416. case ScriptBaseClass.OBJECT_OWNER:
  9417. ret.Add(new LSL_String(id));
  9418. break;
  9419. case ScriptBaseClass.OBJECT_GROUP:
  9420. ret.Add(new LSL_String(UUID.Zero.ToString()));
  9421. break;
  9422. case ScriptBaseClass.OBJECT_CREATOR:
  9423. ret.Add(new LSL_String(UUID.Zero.ToString()));
  9424. break;
  9425. // For the following 8 see the Object version below
  9426. case ScriptBaseClass.OBJECT_RUNNING_SCRIPT_COUNT:
  9427. ret.Add(new LSL_Integer(av.RunningScriptCount()));
  9428. break;
  9429. case ScriptBaseClass.OBJECT_TOTAL_SCRIPT_COUNT:
  9430. ret.Add(new LSL_Integer(av.ScriptCount()));
  9431. break;
  9432. case ScriptBaseClass.OBJECT_SCRIPT_MEMORY:
  9433. ret.Add(new LSL_Integer(av.RunningScriptCount() * 16384));
  9434. break;
  9435. case ScriptBaseClass.OBJECT_SCRIPT_TIME:
  9436. ret.Add(new LSL_Float(av.ScriptExecutionTime() / 1000.0f));
  9437. break;
  9438. case ScriptBaseClass.OBJECT_PRIM_EQUIVALENCE:
  9439. ret.Add(new LSL_Integer(1));
  9440. break;
  9441. case ScriptBaseClass.OBJECT_SERVER_COST:
  9442. ret.Add(new LSL_Float(0));
  9443. break;
  9444. case ScriptBaseClass.OBJECT_STREAMING_COST:
  9445. ret.Add(new LSL_Float(0));
  9446. break;
  9447. case ScriptBaseClass.OBJECT_PHYSICS_COST:
  9448. ret.Add(new LSL_Float(0));
  9449. break;
  9450. case ScriptBaseClass.OBJECT_CHARACTER_TIME: // Pathfinding
  9451. ret.Add(new LSL_Float(0));
  9452. break;
  9453. case ScriptBaseClass.OBJECT_ROOT:
  9454. SceneObjectPart p = av.ParentPart;
  9455. if (p != null)
  9456. {
  9457. ret.Add(new LSL_String(p.ParentGroup.RootPart.UUID.ToString()));
  9458. }
  9459. else
  9460. {
  9461. ret.Add(new LSL_String(id));
  9462. }
  9463. break;
  9464. case ScriptBaseClass.OBJECT_ATTACHED_POINT:
  9465. ret.Add(new LSL_Integer(0));
  9466. break;
  9467. case ScriptBaseClass.OBJECT_PATHFINDING_TYPE: // Pathfinding
  9468. ret.Add(new LSL_Integer(ScriptBaseClass.OPT_AVATAR));
  9469. break;
  9470. case ScriptBaseClass.OBJECT_PHYSICS:
  9471. ret.Add(new LSL_Integer(0));
  9472. break;
  9473. case ScriptBaseClass.OBJECT_PHANTOM:
  9474. ret.Add(new LSL_Integer(0));
  9475. break;
  9476. case ScriptBaseClass.OBJECT_TEMP_ON_REZ:
  9477. ret.Add(new LSL_Integer(0));
  9478. break;
  9479. default:
  9480. // Invalid or unhandled constant.
  9481. ret.Add(new LSL_Integer(ScriptBaseClass.OBJECT_UNKNOWN_DETAIL));
  9482. break;
  9483. }
  9484. }
  9485. return ret;
  9486. }
  9487. SceneObjectPart obj = World.GetSceneObjectPart(key);
  9488. if (obj != null)
  9489. {
  9490. foreach (object o in args.Data)
  9491. {
  9492. switch (int.Parse(o.ToString()))
  9493. {
  9494. case ScriptBaseClass.OBJECT_NAME:
  9495. ret.Add(new LSL_String(obj.Name));
  9496. break;
  9497. case ScriptBaseClass.OBJECT_DESC:
  9498. ret.Add(new LSL_String(obj.Description));
  9499. break;
  9500. case ScriptBaseClass.OBJECT_POS:
  9501. ret.Add(new LSL_Vector(obj.AbsolutePosition.X, obj.AbsolutePosition.Y, obj.AbsolutePosition.Z));
  9502. break;
  9503. case ScriptBaseClass.OBJECT_ROT:
  9504. {
  9505. Quaternion rot = Quaternion.Identity;
  9506. if (obj.ParentGroup.RootPart == obj)
  9507. rot = obj.ParentGroup.GroupRotation;
  9508. else
  9509. rot = obj.GetWorldRotation();
  9510. LSL_Rotation objrot = new LSL_Rotation(rot);
  9511. ret.Add(objrot);
  9512. }
  9513. break;
  9514. case ScriptBaseClass.OBJECT_VELOCITY:
  9515. ret.Add(new LSL_Vector(obj.Velocity));
  9516. break;
  9517. case ScriptBaseClass.OBJECT_OWNER:
  9518. ret.Add(new LSL_String(obj.OwnerID.ToString()));
  9519. break;
  9520. case ScriptBaseClass.OBJECT_GROUP:
  9521. ret.Add(new LSL_String(obj.GroupID.ToString()));
  9522. break;
  9523. case ScriptBaseClass.OBJECT_CREATOR:
  9524. ret.Add(new LSL_String(obj.CreatorID.ToString()));
  9525. break;
  9526. case ScriptBaseClass.OBJECT_RUNNING_SCRIPT_COUNT:
  9527. ret.Add(new LSL_Integer(obj.ParentGroup.RunningScriptCount()));
  9528. break;
  9529. case ScriptBaseClass.OBJECT_TOTAL_SCRIPT_COUNT:
  9530. ret.Add(new LSL_Integer(obj.ParentGroup.ScriptCount()));
  9531. break;
  9532. case ScriptBaseClass.OBJECT_SCRIPT_MEMORY:
  9533. // The value returned in SL for mono scripts is 65536 * number of active scripts
  9534. // and 16384 * number of active scripts for LSO. since llGetFreememory
  9535. // is coded to give the LSO value use it here
  9536. ret.Add(new LSL_Integer(obj.ParentGroup.RunningScriptCount() * 16384));
  9537. break;
  9538. case ScriptBaseClass.OBJECT_SCRIPT_TIME:
  9539. // Average cpu time in seconds per simulator frame expended on all scripts in the object
  9540. ret.Add(new LSL_Float(obj.ParentGroup.ScriptExecutionTime() / 1000.0f));
  9541. break;
  9542. case ScriptBaseClass.OBJECT_PRIM_EQUIVALENCE:
  9543. // according to the SL wiki A prim or linkset will have prim
  9544. // equivalent of the number of prims in a linkset if it does not
  9545. // contain a mesh anywhere in the link set or is not a normal prim
  9546. // The value returned in SL for normal prims is prim count
  9547. ret.Add(new LSL_Integer(obj.ParentGroup.PrimCount));
  9548. break;
  9549. // The following 3 costs I have intentionaly coded to return zero. They are part of
  9550. // "Land Impact" calculations. These calculations are probably not applicable
  9551. // to OpenSim and are not yet complete in SL
  9552. case ScriptBaseClass.OBJECT_SERVER_COST:
  9553. // The linden calculation is here
  9554. // http://wiki.secondlife.com/wiki/Mesh/Mesh_Server_Weight
  9555. // The value returned in SL for normal prims looks like the prim count
  9556. ret.Add(new LSL_Float(0));
  9557. break;
  9558. case ScriptBaseClass.OBJECT_STREAMING_COST:
  9559. // The linden calculation is here
  9560. // http://wiki.secondlife.com/wiki/Mesh/Mesh_Streaming_Cost
  9561. // The value returned in SL for normal prims looks like the prim count * 0.06
  9562. ret.Add(new LSL_Float(0));
  9563. break;
  9564. case ScriptBaseClass.OBJECT_PHYSICS_COST:
  9565. // The linden calculation is here
  9566. // http://wiki.secondlife.com/wiki/Mesh/Mesh_physics
  9567. // The value returned in SL for normal prims looks like the prim count
  9568. ret.Add(new LSL_Float(0));
  9569. break;
  9570. case ScriptBaseClass.OBJECT_CHARACTER_TIME: // Pathfinding
  9571. ret.Add(new LSL_Float(0));
  9572. break;
  9573. case ScriptBaseClass.OBJECT_ROOT:
  9574. ret.Add(new LSL_String(obj.ParentGroup.RootPart.UUID.ToString()));
  9575. break;
  9576. case ScriptBaseClass.OBJECT_ATTACHED_POINT:
  9577. ret.Add(new LSL_Integer(obj.ParentGroup.AttachmentPoint));
  9578. break;
  9579. case ScriptBaseClass.OBJECT_PATHFINDING_TYPE:
  9580. byte pcode = obj.Shape.PCode;
  9581. if (obj.ParentGroup.AttachmentPoint != 0
  9582. || pcode == (byte)PCode.Grass
  9583. || pcode == (byte)PCode.Tree
  9584. || pcode == (byte)PCode.NewTree)
  9585. {
  9586. ret.Add(new LSL_Integer(ScriptBaseClass.OPT_OTHER));
  9587. }
  9588. else
  9589. {
  9590. ret.Add(new LSL_Integer(ScriptBaseClass.OPT_LEGACY_LINKSET));
  9591. }
  9592. break;
  9593. case ScriptBaseClass.OBJECT_PHYSICS:
  9594. if (obj.ParentGroup.AttachmentPoint != 0)
  9595. {
  9596. ret.Add(new LSL_Integer(0)); // Always false if attached
  9597. }
  9598. else
  9599. {
  9600. ret.Add(new LSL_Integer(obj.ParentGroup.UsesPhysics ? 1 : 0));
  9601. }
  9602. break;
  9603. case ScriptBaseClass.OBJECT_PHANTOM:
  9604. if (obj.ParentGroup.AttachmentPoint != 0)
  9605. {
  9606. ret.Add(new LSL_Integer(0)); // Always false if attached
  9607. }
  9608. else
  9609. {
  9610. ret.Add(new LSL_Integer(obj.ParentGroup.IsPhantom ? 1 : 0));
  9611. }
  9612. break;
  9613. case ScriptBaseClass.OBJECT_TEMP_ON_REZ:
  9614. ret.Add(new LSL_Integer(obj.ParentGroup.IsTemporary ? 1 : 0));
  9615. break;
  9616. default:
  9617. // Invalid or unhandled constant.
  9618. ret.Add(new LSL_Integer(ScriptBaseClass.OBJECT_UNKNOWN_DETAIL));
  9619. break;
  9620. }
  9621. }
  9622. return ret;
  9623. }
  9624. }
  9625. return new LSL_List();
  9626. }
  9627. internal UUID GetScriptByName(string name)
  9628. {
  9629. TaskInventoryItem item = m_host.Inventory.GetInventoryItem(name);
  9630. if (item == null || item.Type != 10)
  9631. return UUID.Zero;
  9632. return item.ItemID;
  9633. }
  9634. /// <summary>
  9635. /// Reports the script error in the viewer's Script Warning/Error dialog and shouts it on the debug channel.
  9636. /// </summary>
  9637. /// <param name="command">The name of the command that generated the error.</param>
  9638. /// <param name="message">The error message to report to the user.</param>
  9639. internal void Error(string command, string message)
  9640. {
  9641. string text = command + ": " + message;
  9642. if (text.Length > 1023)
  9643. {
  9644. text = text.Substring(0, 1023);
  9645. }
  9646. World.SimChat(Utils.StringToBytes(text), ChatTypeEnum.DebugChannel, ScriptBaseClass.DEBUG_CHANNEL,
  9647. m_host.ParentGroup.RootPart.AbsolutePosition, m_host.Name, m_host.UUID, false);
  9648. IWorldComm wComm = m_ScriptEngine.World.RequestModuleInterface<IWorldComm>();
  9649. if (wComm != null)
  9650. {
  9651. wComm.DeliverMessage(ChatTypeEnum.Shout, ScriptBaseClass.DEBUG_CHANNEL, m_host.Name, m_host.UUID, text);
  9652. }
  9653. }
  9654. /// <summary>
  9655. /// Reports that the command is not implemented as a script error.
  9656. /// </summary>
  9657. /// <param name="command">The name of the command that is not implemented.</param>
  9658. /// <param name="message">Additional information to report to the user. (Optional)</param>
  9659. internal void NotImplemented(string command, string message = "")
  9660. {
  9661. if (throwErrorOnNotImplemented)
  9662. {
  9663. if (message != "")
  9664. {
  9665. message = " - " + message;
  9666. }
  9667. throw new NotImplementedException("Command not implemented: " + command + message);
  9668. }
  9669. else
  9670. {
  9671. string text = "Command not implemented";
  9672. if (message != "")
  9673. {
  9674. text = text + " - " + message;
  9675. }
  9676. Error(command, text);
  9677. }
  9678. }
  9679. /// <summary>
  9680. /// Reports that the command is deprecated as a script error.
  9681. /// </summary>
  9682. /// <param name="command">The name of the command that is deprecated.</param>
  9683. /// <param name="message">Additional information to report to the user. (Optional)</param>
  9684. internal void Deprecated(string command, string message = "")
  9685. {
  9686. string text = "Command deprecated";
  9687. if (message != "")
  9688. {
  9689. text = text + " - " + message;
  9690. }
  9691. Error(command, text);
  9692. }
  9693. public delegate void AssetRequestCallback(UUID assetID, AssetBase asset);
  9694. protected void WithNotecard(UUID assetID, AssetRequestCallback cb)
  9695. {
  9696. World.AssetService.Get(assetID.ToString(), this,
  9697. delegate(string i, object sender, AssetBase a)
  9698. {
  9699. UUID uuid = UUID.Zero;
  9700. UUID.TryParse(i, out uuid);
  9701. cb(uuid, a);
  9702. });
  9703. }
  9704. public LSL_String llGetNumberOfNotecardLines(string name)
  9705. {
  9706. m_host.AddScriptLPS(1);
  9707. UUID assetID = UUID.Zero;
  9708. if (!UUID.TryParse(name, out assetID))
  9709. {
  9710. TaskInventoryItem item = m_host.Inventory.GetInventoryItem(name);
  9711. if (item != null && item.Type == 7)
  9712. assetID = item.AssetID;
  9713. }
  9714. if (assetID == UUID.Zero)
  9715. {
  9716. // => complain loudly, as specified by the LSL docs
  9717. Error("llGetNumberOfNotecardLines", "Can't find notecard '" + name + "'");
  9718. return UUID.Zero.ToString();
  9719. }
  9720. string reqIdentifier = UUID.Random().ToString();
  9721. // was: UUID tid = tid = AsyncCommands.
  9722. UUID tid = AsyncCommands.DataserverPlugin.RegisterRequest(m_host.LocalId, m_item.ItemID, reqIdentifier);
  9723. if (NotecardCache.IsCached(assetID))
  9724. {
  9725. AsyncCommands.DataserverPlugin.DataserverReply(reqIdentifier, NotecardCache.GetLines(assetID).ToString());
  9726. ScriptSleep(100);
  9727. return tid.ToString();
  9728. }
  9729. WithNotecard(assetID, delegate (UUID id, AssetBase a)
  9730. {
  9731. if (a == null || a.Type != 7)
  9732. {
  9733. Error("llGetNumberOfNotecardLines", "Can't find notecard '" + name + "'");
  9734. return;
  9735. }
  9736. string data = Encoding.UTF8.GetString(a.Data);
  9737. //m_log.Debug(data);
  9738. NotecardCache.Cache(id, data);
  9739. AsyncCommands.DataserverPlugin.DataserverReply(reqIdentifier, NotecardCache.GetLines(id).ToString());
  9740. });
  9741. ScriptSleep(100);
  9742. return tid.ToString();
  9743. }
  9744. public LSL_String llGetNotecardLine(string name, int line)
  9745. {
  9746. m_host.AddScriptLPS(1);
  9747. UUID assetID = UUID.Zero;
  9748. if (!UUID.TryParse(name, out assetID))
  9749. {
  9750. TaskInventoryItem item = m_host.Inventory.GetInventoryItem(name);
  9751. if (item != null && item.Type == 7)
  9752. assetID = item.AssetID;
  9753. }
  9754. if (assetID == UUID.Zero)
  9755. {
  9756. // => complain loudly, as specified by the LSL docs
  9757. Error("llGetNotecardLine", "Can't find notecard '" + name + "'");
  9758. return UUID.Zero.ToString();
  9759. }
  9760. string reqIdentifier = UUID.Random().ToString();
  9761. // was: UUID tid = tid = AsyncCommands.
  9762. UUID tid = AsyncCommands.DataserverPlugin.RegisterRequest(m_host.LocalId, m_item.ItemID, reqIdentifier);
  9763. if (NotecardCache.IsCached(assetID))
  9764. {
  9765. AsyncCommands.DataserverPlugin.DataserverReply(
  9766. reqIdentifier, NotecardCache.GetLine(assetID, line, m_notecardLineReadCharsMax));
  9767. ScriptSleep(100);
  9768. return tid.ToString();
  9769. }
  9770. WithNotecard(assetID, delegate (UUID id, AssetBase a)
  9771. {
  9772. if (a == null || a.Type != 7)
  9773. {
  9774. Error("llGetNotecardLine", "Can't find notecard '" + name + "'");
  9775. return;
  9776. }
  9777. string data = Encoding.UTF8.GetString(a.Data);
  9778. //m_log.Debug(data);
  9779. NotecardCache.Cache(id, data);
  9780. AsyncCommands.DataserverPlugin.DataserverReply(
  9781. reqIdentifier, NotecardCache.GetLine(assetID, line, m_notecardLineReadCharsMax));
  9782. });
  9783. ScriptSleep(100);
  9784. return tid.ToString();
  9785. }
  9786. public void SetPrimitiveParamsEx(LSL_Key prim, LSL_List rules, string originFunc)
  9787. {
  9788. SceneObjectPart obj = World.GetSceneObjectPart(new UUID(prim));
  9789. if (obj == null)
  9790. return;
  9791. if (obj.OwnerID != m_host.OwnerID)
  9792. return;
  9793. uint rulesParsed = 0;
  9794. LSL_List remaining = SetPrimParams(obj, rules, originFunc, ref rulesParsed);
  9795. while ((object)remaining != null && remaining.Length > 2)
  9796. {
  9797. LSL_Integer newLink = remaining.GetLSLIntegerItem(0);
  9798. LSL_List newrules = remaining.GetSublist(1, -1);
  9799. foreach(SceneObjectPart part in GetLinkParts(obj, newLink)){
  9800. remaining = SetPrimParams(part, newrules, originFunc, ref rulesParsed);
  9801. }
  9802. }
  9803. }
  9804. public LSL_List GetPrimitiveParamsEx(LSL_Key prim, LSL_List rules)
  9805. {
  9806. SceneObjectPart obj = World.GetSceneObjectPart(new UUID(prim));
  9807. LSL_List result = new LSL_List();
  9808. if (obj != null && obj.OwnerID == m_host.OwnerID)
  9809. {
  9810. LSL_List remaining = GetPrimParams(obj, rules, ref result);
  9811. while (remaining != null && remaining.Length > 2)
  9812. {
  9813. int linknumber = remaining.GetLSLIntegerItem(0);
  9814. rules = remaining.GetSublist(1, -1);
  9815. List<SceneObjectPart> parts = GetLinkParts(linknumber);
  9816. foreach (SceneObjectPart part in parts)
  9817. remaining = GetPrimParams(part, rules, ref result);
  9818. }
  9819. }
  9820. return result;
  9821. }
  9822. public void print(string str)
  9823. {
  9824. // yes, this is a real LSL function. See: http://wiki.secondlife.com/wiki/Print
  9825. IOSSL_Api ossl = (IOSSL_Api)m_ScriptEngine.GetApi(m_item.ItemID, "OSSL");
  9826. if (ossl != null)
  9827. {
  9828. ossl.CheckThreatLevel(ThreatLevel.High, "print");
  9829. m_log.Info("LSL print():" + str);
  9830. }
  9831. }
  9832. private string Name2Username(string name)
  9833. {
  9834. string[] parts = name.Split(new char[] {' '});
  9835. if (parts.Length < 2)
  9836. return name.ToLower();
  9837. if (parts[1] == "Resident")
  9838. return parts[0].ToLower();
  9839. return name.Replace(" ", ".").ToLower();
  9840. }
  9841. public LSL_String llGetUsername(string id)
  9842. {
  9843. return Name2Username(llKey2Name(id));
  9844. }
  9845. public LSL_String llRequestUsername(string id)
  9846. {
  9847. UUID rq = UUID.Random();
  9848. AsyncCommands.DataserverPlugin.RegisterRequest(m_host.LocalId, m_item.ItemID, rq.ToString());
  9849. AsyncCommands.DataserverPlugin.DataserverReply(rq.ToString(), Name2Username(llKey2Name(id)));
  9850. return rq.ToString();
  9851. }
  9852. public LSL_String llGetDisplayName(string id)
  9853. {
  9854. return llKey2Name(id);
  9855. }
  9856. public LSL_String llRequestDisplayName(string id)
  9857. {
  9858. UUID rq = UUID.Random();
  9859. AsyncCommands.DataserverPlugin.RegisterRequest(m_host.LocalId, m_item.ItemID, rq.ToString());
  9860. AsyncCommands.DataserverPlugin.DataserverReply(rq.ToString(), llKey2Name(id));
  9861. return rq.ToString();
  9862. }
  9863. private struct Tri
  9864. {
  9865. public Vector3 p1;
  9866. public Vector3 p2;
  9867. public Vector3 p3;
  9868. }
  9869. private bool InBoundingBox(ScenePresence avatar, Vector3 point)
  9870. {
  9871. float height = avatar.Appearance.AvatarHeight;
  9872. Vector3 b1 = avatar.AbsolutePosition + new Vector3(-0.22f, -0.22f, -height/2);
  9873. Vector3 b2 = avatar.AbsolutePosition + new Vector3(0.22f, 0.22f, height/2);
  9874. if (point.X > b1.X && point.X < b2.X &&
  9875. point.Y > b1.Y && point.Y < b2.Y &&
  9876. point.Z > b1.Z && point.Z < b2.Z)
  9877. return true;
  9878. return false;
  9879. }
  9880. private ContactResult[] AvatarIntersection(Vector3 rayStart, Vector3 rayEnd)
  9881. {
  9882. List<ContactResult> contacts = new List<ContactResult>();
  9883. Vector3 ab = rayEnd - rayStart;
  9884. World.ForEachScenePresence(delegate(ScenePresence sp)
  9885. {
  9886. Vector3 ac = sp.AbsolutePosition - rayStart;
  9887. // Vector3 bc = sp.AbsolutePosition - rayEnd;
  9888. double d = Math.Abs(Vector3.Mag(Vector3.Cross(ab, ac)) / Vector3.Distance(rayStart, rayEnd));
  9889. if (d > 1.5)
  9890. return;
  9891. double d2 = Vector3.Dot(Vector3.Negate(ab), ac);
  9892. if (d2 > 0)
  9893. return;
  9894. double dp = Math.Sqrt(Vector3.Mag(ac) * Vector3.Mag(ac) - d * d);
  9895. Vector3 p = rayStart + Vector3.Divide(Vector3.Multiply(ab, (float)dp), (float)Vector3.Mag(ab));
  9896. if (!InBoundingBox(sp, p))
  9897. return;
  9898. ContactResult result = new ContactResult ();
  9899. result.ConsumerID = sp.LocalId;
  9900. result.Depth = Vector3.Distance(rayStart, p);
  9901. result.Normal = Vector3.Zero;
  9902. result.Pos = p;
  9903. contacts.Add(result);
  9904. });
  9905. return contacts.ToArray();
  9906. }
  9907. private ContactResult[] ObjectIntersection(Vector3 rayStart, Vector3 rayEnd, bool includePhysical, bool includeNonPhysical, bool includePhantom)
  9908. {
  9909. Ray ray = new Ray(rayStart, Vector3.Normalize(rayEnd - rayStart));
  9910. List<ContactResult> contacts = new List<ContactResult>();
  9911. Vector3 ab = rayEnd - rayStart;
  9912. World.ForEachSOG(delegate(SceneObjectGroup group)
  9913. {
  9914. if (m_host.ParentGroup == group)
  9915. return;
  9916. if (group.IsAttachment)
  9917. return;
  9918. if (group.RootPart.PhysActor == null)
  9919. {
  9920. if (!includePhantom)
  9921. return;
  9922. }
  9923. else
  9924. {
  9925. if (group.RootPart.PhysActor.IsPhysical)
  9926. {
  9927. if (!includePhysical)
  9928. return;
  9929. }
  9930. else
  9931. {
  9932. if (!includeNonPhysical)
  9933. return;
  9934. }
  9935. }
  9936. // Find the radius ouside of which we don't even need to hit test
  9937. float minX;
  9938. float maxX;
  9939. float minY;
  9940. float maxY;
  9941. float minZ;
  9942. float maxZ;
  9943. float radius = 0.0f;
  9944. group.GetAxisAlignedBoundingBoxRaw(out minX, out maxX, out minY, out maxY, out minZ, out maxZ);
  9945. if (Math.Abs(minX) > radius)
  9946. radius = Math.Abs(minX);
  9947. if (Math.Abs(minY) > radius)
  9948. radius = Math.Abs(minY);
  9949. if (Math.Abs(minZ) > radius)
  9950. radius = Math.Abs(minZ);
  9951. if (Math.Abs(maxX) > radius)
  9952. radius = Math.Abs(maxX);
  9953. if (Math.Abs(maxY) > radius)
  9954. radius = Math.Abs(maxY);
  9955. if (Math.Abs(maxZ) > radius)
  9956. radius = Math.Abs(maxZ);
  9957. radius = radius*1.413f;
  9958. Vector3 ac = group.AbsolutePosition - rayStart;
  9959. // Vector3 bc = group.AbsolutePosition - rayEnd;
  9960. double d = Math.Abs(Vector3.Mag(Vector3.Cross(ab, ac)) / Vector3.Distance(rayStart, rayEnd));
  9961. // Too far off ray, don't bother
  9962. if (d > radius)
  9963. return;
  9964. // Behind ray, drop
  9965. double d2 = Vector3.Dot(Vector3.Negate(ab), ac);
  9966. if (d2 > 0)
  9967. return;
  9968. ray = new Ray(rayStart, Vector3.Normalize(rayEnd - rayStart));
  9969. EntityIntersection intersection = group.TestIntersection(ray, true, false);
  9970. // Miss.
  9971. if (!intersection.HitTF)
  9972. return;
  9973. Vector3 b1 = group.AbsolutePosition + new Vector3(minX, minY, minZ);
  9974. Vector3 b2 = group.AbsolutePosition + new Vector3(maxX, maxY, maxZ);
  9975. //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);
  9976. if (!(intersection.ipoint.X >= b1.X && intersection.ipoint.X <= b2.X &&
  9977. intersection.ipoint.Y >= b1.Y && intersection.ipoint.Y <= b2.Y &&
  9978. intersection.ipoint.Z >= b1.Z && intersection.ipoint.Z <= b2.Z))
  9979. return;
  9980. ContactResult result = new ContactResult ();
  9981. result.ConsumerID = group.LocalId;
  9982. result.Depth = intersection.distance;
  9983. result.Normal = intersection.normal;
  9984. result.Pos = intersection.ipoint;
  9985. contacts.Add(result);
  9986. });
  9987. return contacts.ToArray();
  9988. }
  9989. private ContactResult? GroundIntersection(Vector3 rayStart, Vector3 rayEnd)
  9990. {
  9991. double[,] heightfield = World.Heightmap.GetDoubles();
  9992. List<ContactResult> contacts = new List<ContactResult>();
  9993. double min = 2048.0;
  9994. double max = 0.0;
  9995. // Find the min and max of the heightfield
  9996. for (int x = 0 ; x < World.Heightmap.Width ; x++)
  9997. {
  9998. for (int y = 0 ; y < World.Heightmap.Height ; y++)
  9999. {
  10000. if (heightfield[x, y] > max)
  10001. max = heightfield[x, y];
  10002. if (heightfield[x, y] < min)
  10003. min = heightfield[x, y];
  10004. }
  10005. }
  10006. // A ray extends past rayEnd, but doesn't go back before
  10007. // rayStart. If the start is above the highest point of the ground
  10008. // and the ray goes up, we can't hit the ground. Ever.
  10009. if (rayStart.Z > max && rayEnd.Z >= rayStart.Z)
  10010. return null;
  10011. // Same for going down
  10012. if (rayStart.Z < min && rayEnd.Z <= rayStart.Z)
  10013. return null;
  10014. List<Tri> trilist = new List<Tri>();
  10015. // Create our triangle list
  10016. for (int x = 1 ; x < World.Heightmap.Width ; x++)
  10017. {
  10018. for (int y = 1 ; y < World.Heightmap.Height ; y++)
  10019. {
  10020. Tri t1 = new Tri();
  10021. Tri t2 = new Tri();
  10022. Vector3 p1 = new Vector3(x-1, y-1, (float)heightfield[x-1, y-1]);
  10023. Vector3 p2 = new Vector3(x, y-1, (float)heightfield[x, y-1]);
  10024. Vector3 p3 = new Vector3(x, y, (float)heightfield[x, y]);
  10025. Vector3 p4 = new Vector3(x-1, y, (float)heightfield[x-1, y]);
  10026. t1.p1 = p1;
  10027. t1.p2 = p2;
  10028. t1.p3 = p3;
  10029. t2.p1 = p3;
  10030. t2.p2 = p4;
  10031. t2.p3 = p1;
  10032. trilist.Add(t1);
  10033. trilist.Add(t2);
  10034. }
  10035. }
  10036. // Ray direction
  10037. Vector3 rayDirection = rayEnd - rayStart;
  10038. foreach (Tri t in trilist)
  10039. {
  10040. // Compute triangle plane normal and edges
  10041. Vector3 u = t.p2 - t.p1;
  10042. Vector3 v = t.p3 - t.p1;
  10043. Vector3 n = Vector3.Cross(u, v);
  10044. if (n == Vector3.Zero)
  10045. continue;
  10046. Vector3 w0 = rayStart - t.p1;
  10047. double a = -Vector3.Dot(n, w0);
  10048. double b = Vector3.Dot(n, rayDirection);
  10049. // Not intersecting the plane, or in plane (same thing)
  10050. // Ignoring this MAY cause the ground to not be detected
  10051. // sometimes
  10052. if (Math.Abs(b) < 0.000001)
  10053. continue;
  10054. double r = a / b;
  10055. // ray points away from plane
  10056. if (r < 0.0)
  10057. continue;
  10058. Vector3 ip = rayStart + Vector3.Multiply(rayDirection, (float)r);
  10059. float uu = Vector3.Dot(u, u);
  10060. float uv = Vector3.Dot(u, v);
  10061. float vv = Vector3.Dot(v, v);
  10062. Vector3 w = ip - t.p1;
  10063. float wu = Vector3.Dot(w, u);
  10064. float wv = Vector3.Dot(w, v);
  10065. float d = uv * uv - uu * vv;
  10066. float cs = (uv * wv - vv * wu) / d;
  10067. if (cs < 0 || cs > 1.0)
  10068. continue;
  10069. float ct = (uv * wu - uu * wv) / d;
  10070. if (ct < 0 || (cs + ct) > 1.0)
  10071. continue;
  10072. // Add contact point
  10073. ContactResult result = new ContactResult ();
  10074. result.ConsumerID = 0;
  10075. result.Depth = Vector3.Distance(rayStart, ip);
  10076. result.Normal = n;
  10077. result.Pos = ip;
  10078. contacts.Add(result);
  10079. }
  10080. if (contacts.Count == 0)
  10081. return null;
  10082. contacts.Sort(delegate(ContactResult a, ContactResult b)
  10083. {
  10084. return (int)(a.Depth - b.Depth);
  10085. });
  10086. return contacts[0];
  10087. }
  10088. public LSL_List llCastRay(LSL_Vector start, LSL_Vector end, LSL_List options)
  10089. {
  10090. LSL_List list = new LSL_List();
  10091. m_host.AddScriptLPS(1);
  10092. Vector3 rayStart = start;
  10093. Vector3 rayEnd = end;
  10094. Vector3 dir = rayEnd - rayStart;
  10095. float dist = Vector3.Mag(dir);
  10096. int count = 1;
  10097. bool detectPhantom = false;
  10098. int dataFlags = 0;
  10099. int rejectTypes = 0;
  10100. for (int i = 0; i < options.Length; i += 2)
  10101. {
  10102. if (options.GetLSLIntegerItem(i) == ScriptBaseClass.RC_MAX_HITS)
  10103. count = options.GetLSLIntegerItem(i + 1);
  10104. else if (options.GetLSLIntegerItem(i) == ScriptBaseClass.RC_DETECT_PHANTOM)
  10105. detectPhantom = (options.GetLSLIntegerItem(i + 1) > 0);
  10106. else if (options.GetLSLIntegerItem(i) == ScriptBaseClass.RC_DATA_FLAGS)
  10107. dataFlags = options.GetLSLIntegerItem(i + 1);
  10108. else if (options.GetLSLIntegerItem(i) == ScriptBaseClass.RC_REJECT_TYPES)
  10109. rejectTypes = options.GetLSLIntegerItem(i + 1);
  10110. }
  10111. if (count > 16)
  10112. count = 16;
  10113. List<ContactResult> results = new List<ContactResult>();
  10114. bool checkTerrain = !((rejectTypes & ScriptBaseClass.RC_REJECT_LAND) == ScriptBaseClass.RC_REJECT_LAND);
  10115. bool checkAgents = !((rejectTypes & ScriptBaseClass.RC_REJECT_AGENTS) == ScriptBaseClass.RC_REJECT_AGENTS);
  10116. bool checkNonPhysical = !((rejectTypes & ScriptBaseClass.RC_REJECT_NONPHYSICAL) == ScriptBaseClass.RC_REJECT_NONPHYSICAL);
  10117. bool checkPhysical = !((rejectTypes & ScriptBaseClass.RC_REJECT_PHYSICAL) == ScriptBaseClass.RC_REJECT_PHYSICAL);
  10118. if (World.SupportsRayCastFiltered())
  10119. {
  10120. if (dist == 0)
  10121. return list;
  10122. RayFilterFlags rayfilter = RayFilterFlags.ClosestAndBackCull;
  10123. if (checkTerrain)
  10124. rayfilter |= RayFilterFlags.land;
  10125. // if (checkAgents)
  10126. // rayfilter |= RayFilterFlags.agent;
  10127. if (checkPhysical)
  10128. rayfilter |= RayFilterFlags.physical;
  10129. if (checkNonPhysical)
  10130. rayfilter |= RayFilterFlags.nonphysical;
  10131. if (detectPhantom)
  10132. rayfilter |= RayFilterFlags.LSLPhantom;
  10133. Vector3 direction = dir * ( 1/dist);
  10134. if(rayfilter == 0)
  10135. {
  10136. list.Add(new LSL_Integer(0));
  10137. return list;
  10138. }
  10139. // get some more contacts to sort ???
  10140. int physcount = 4 * count;
  10141. if (physcount > 20)
  10142. physcount = 20;
  10143. object physresults;
  10144. physresults = World.RayCastFiltered(rayStart, direction, dist, physcount, rayfilter);
  10145. if (physresults == null)
  10146. {
  10147. list.Add(new LSL_Integer(-3)); // timeout error
  10148. return list;
  10149. }
  10150. results = (List<ContactResult>)physresults;
  10151. // for now physics doesn't detect sitted avatars so do it outside physics
  10152. if (checkAgents)
  10153. {
  10154. ContactResult[] agentHits = AvatarIntersection(rayStart, rayEnd);
  10155. foreach (ContactResult r in agentHits)
  10156. results.Add(r);
  10157. }
  10158. // TODO: Replace this with a better solution. ObjectIntersection can only
  10159. // detect nonphysical phantoms. They are detected by virtue of being
  10160. // nonphysical (e.g. no PhysActor) so will not conflict with detecting
  10161. // physicsl phantoms as done by the physics scene
  10162. // We don't want anything else but phantoms here.
  10163. if (detectPhantom)
  10164. {
  10165. ContactResult[] objectHits = ObjectIntersection(rayStart, rayEnd, false, false, true);
  10166. foreach (ContactResult r in objectHits)
  10167. results.Add(r);
  10168. }
  10169. }
  10170. else
  10171. {
  10172. if (checkAgents)
  10173. {
  10174. ContactResult[] agentHits = AvatarIntersection(rayStart, rayEnd);
  10175. foreach (ContactResult r in agentHits)
  10176. results.Add(r);
  10177. }
  10178. if (checkPhysical || checkNonPhysical || detectPhantom)
  10179. {
  10180. ContactResult[] objectHits = ObjectIntersection(rayStart, rayEnd, checkPhysical, checkNonPhysical, detectPhantom);
  10181. for (int iter = 0; iter < objectHits.Length; iter++)
  10182. {
  10183. // Redistance the Depth because the Scene RayCaster returns distance from center to make the rezzing code simpler.
  10184. objectHits[iter].Depth = Vector3.Distance(objectHits[iter].Pos, rayStart);
  10185. results.Add(objectHits[iter]);
  10186. }
  10187. }
  10188. }
  10189. if (checkTerrain)
  10190. {
  10191. ContactResult? groundContact = GroundIntersection(rayStart, rayEnd);
  10192. if (groundContact != null)
  10193. results.Add((ContactResult)groundContact);
  10194. }
  10195. results.Sort(delegate(ContactResult a, ContactResult b)
  10196. {
  10197. return a.Depth.CompareTo(b.Depth);
  10198. });
  10199. int values = 0;
  10200. SceneObjectGroup thisgrp = m_host.ParentGroup;
  10201. foreach (ContactResult result in results)
  10202. {
  10203. if (result.Depth > dist)
  10204. continue;
  10205. // physics ray can return colisions with host prim
  10206. if (m_host.LocalId == result.ConsumerID)
  10207. continue;
  10208. UUID itemID = UUID.Zero;
  10209. int linkNum = 0;
  10210. SceneObjectPart part = World.GetSceneObjectPart(result.ConsumerID);
  10211. // It's a prim!
  10212. if (part != null)
  10213. {
  10214. // dont detect members of same object ???
  10215. if (part.ParentGroup == thisgrp)
  10216. continue;
  10217. if ((dataFlags & ScriptBaseClass.RC_GET_ROOT_KEY) == ScriptBaseClass.RC_GET_ROOT_KEY)
  10218. itemID = part.ParentGroup.UUID;
  10219. else
  10220. itemID = part.UUID;
  10221. linkNum = part.LinkNum;
  10222. }
  10223. else
  10224. {
  10225. ScenePresence sp = World.GetScenePresence(result.ConsumerID);
  10226. /// It it a boy? a girl?
  10227. if (sp != null)
  10228. itemID = sp.UUID;
  10229. }
  10230. list.Add(new LSL_String(itemID.ToString()));
  10231. list.Add(new LSL_String(result.Pos.ToString()));
  10232. if ((dataFlags & ScriptBaseClass.RC_GET_LINK_NUM) == ScriptBaseClass.RC_GET_LINK_NUM)
  10233. list.Add(new LSL_Integer(linkNum));
  10234. if ((dataFlags & ScriptBaseClass.RC_GET_NORMAL) == ScriptBaseClass.RC_GET_NORMAL)
  10235. list.Add(new LSL_Vector(result.Normal));
  10236. values++;
  10237. if (values >= count)
  10238. break;
  10239. }
  10240. list.Add(new LSL_Integer(values));
  10241. return list;
  10242. }
  10243. public LSL_Integer llManageEstateAccess(int action, string avatar)
  10244. {
  10245. m_host.AddScriptLPS(1);
  10246. EstateSettings estate = World.RegionInfo.EstateSettings;
  10247. bool isAccount = false;
  10248. bool isGroup = false;
  10249. if (!estate.IsEstateOwner(m_host.OwnerID) || !estate.IsEstateManagerOrOwner(m_host.OwnerID))
  10250. return 0;
  10251. UUID id = new UUID();
  10252. if (!UUID.TryParse(avatar, out id))
  10253. return 0;
  10254. UserAccount account = World.UserAccountService.GetUserAccount(World.RegionInfo.ScopeID, id);
  10255. isAccount = account != null ? true : false;
  10256. if (!isAccount)
  10257. {
  10258. IGroupsModule groups = World.RequestModuleInterface<IGroupsModule>();
  10259. if (groups != null)
  10260. {
  10261. GroupRecord group = groups.GetGroupRecord(id);
  10262. isGroup = group != null ? true : false;
  10263. if (!isGroup)
  10264. return 0;
  10265. }
  10266. else
  10267. return 0;
  10268. }
  10269. switch (action)
  10270. {
  10271. case ScriptBaseClass.ESTATE_ACCESS_ALLOWED_AGENT_ADD:
  10272. if (!isAccount) return 0;
  10273. if (estate.HasAccess(id)) return 1;
  10274. if (estate.IsBanned(id))
  10275. estate.RemoveBan(id);
  10276. estate.AddEstateUser(id);
  10277. break;
  10278. case ScriptBaseClass.ESTATE_ACCESS_ALLOWED_AGENT_REMOVE:
  10279. if (!isAccount || !estate.HasAccess(id)) return 0;
  10280. estate.RemoveEstateUser(id);
  10281. break;
  10282. case ScriptBaseClass.ESTATE_ACCESS_ALLOWED_GROUP_ADD:
  10283. if (!isGroup) return 0;
  10284. if (estate.GroupAccess(id)) return 1;
  10285. estate.AddEstateGroup(id);
  10286. break;
  10287. case ScriptBaseClass.ESTATE_ACCESS_ALLOWED_GROUP_REMOVE:
  10288. if (!isGroup || !estate.GroupAccess(id)) return 0;
  10289. estate.RemoveEstateGroup(id);
  10290. break;
  10291. case ScriptBaseClass.ESTATE_ACCESS_BANNED_AGENT_ADD:
  10292. if (!isAccount) return 0;
  10293. if (estate.IsBanned(id)) return 1;
  10294. EstateBan ban = new EstateBan();
  10295. ban.EstateID = estate.EstateID;
  10296. ban.BannedUserID = id;
  10297. estate.AddBan(ban);
  10298. break;
  10299. case ScriptBaseClass.ESTATE_ACCESS_BANNED_AGENT_REMOVE:
  10300. if (!isAccount || !estate.IsBanned(id)) return 0;
  10301. estate.RemoveBan(id);
  10302. break;
  10303. default: return 0;
  10304. }
  10305. return 1;
  10306. }
  10307. public LSL_Integer llGetMemoryLimit()
  10308. {
  10309. m_host.AddScriptLPS(1);
  10310. // The value returned for LSO scripts in SL
  10311. return 16384;
  10312. }
  10313. public LSL_Integer llSetMemoryLimit(LSL_Integer limit)
  10314. {
  10315. m_host.AddScriptLPS(1);
  10316. // Treat as an LSO script
  10317. return ScriptBaseClass.FALSE;
  10318. }
  10319. public LSL_Integer llGetSPMaxMemory()
  10320. {
  10321. m_host.AddScriptLPS(1);
  10322. // The value returned for LSO scripts in SL
  10323. return 16384;
  10324. }
  10325. public virtual LSL_Integer llGetUsedMemory()
  10326. {
  10327. m_host.AddScriptLPS(1);
  10328. // The value returned for LSO scripts in SL
  10329. return 16384;
  10330. }
  10331. public void llScriptProfiler(LSL_Integer flags)
  10332. {
  10333. m_host.AddScriptLPS(1);
  10334. // This does nothing for LSO scripts in SL
  10335. }
  10336. #region Not Implemented
  10337. //
  10338. // Listing the unimplemented lsl functions here, please move
  10339. // them from this region as they are completed
  10340. //
  10341. public void llGetEnv(LSL_String name)
  10342. {
  10343. m_host.AddScriptLPS(1);
  10344. NotImplemented("llGetEnv");
  10345. }
  10346. public void llSetSoundQueueing(int queue)
  10347. {
  10348. m_host.AddScriptLPS(1);
  10349. if (m_SoundModule != null)
  10350. m_SoundModule.SetSoundQueueing(m_host.UUID, queue == ScriptBaseClass.TRUE.value);
  10351. }
  10352. public void llCollisionSprite(string impact_sprite)
  10353. {
  10354. m_host.AddScriptLPS(1);
  10355. NotImplemented("llCollisionSprite");
  10356. }
  10357. public void llGodLikeRezObject(string inventory, LSL_Vector pos)
  10358. {
  10359. m_host.AddScriptLPS(1);
  10360. NotImplemented("llGodLikeRezObject");
  10361. }
  10362. public LSL_String llTransferLindenDollars(string destination, int amount)
  10363. {
  10364. UUID txn = UUID.Random();
  10365. Util.FireAndForget(delegate(object x)
  10366. {
  10367. int replycode = 0;
  10368. string replydata = destination + "," + amount.ToString();
  10369. try
  10370. {
  10371. TaskInventoryItem item = m_item;
  10372. if (item == null)
  10373. {
  10374. replydata = "SERVICE_ERROR";
  10375. return;
  10376. }
  10377. m_host.AddScriptLPS(1);
  10378. if (item.PermsGranter == UUID.Zero)
  10379. {
  10380. replydata = "MISSING_PERMISSION_DEBIT";
  10381. return;
  10382. }
  10383. if ((item.PermsMask & ScriptBaseClass.PERMISSION_DEBIT) == 0)
  10384. {
  10385. replydata = "MISSING_PERMISSION_DEBIT";
  10386. return;
  10387. }
  10388. UUID toID = new UUID();
  10389. if (!UUID.TryParse(destination, out toID))
  10390. {
  10391. replydata = "INVALID_AGENT";
  10392. return;
  10393. }
  10394. IMoneyModule money = World.RequestModuleInterface<IMoneyModule>();
  10395. if (money == null)
  10396. {
  10397. replydata = "TRANSFERS_DISABLED";
  10398. return;
  10399. }
  10400. bool result = money.ObjectGiveMoney(
  10401. m_host.ParentGroup.RootPart.UUID, m_host.ParentGroup.RootPart.OwnerID, toID, amount);
  10402. if (result)
  10403. {
  10404. replycode = 1;
  10405. return;
  10406. }
  10407. replydata = "LINDENDOLLAR_INSUFFICIENTFUNDS";
  10408. }
  10409. finally
  10410. {
  10411. m_ScriptEngine.PostScriptEvent(m_item.ItemID, new EventParams(
  10412. "transaction_result", new Object[] {
  10413. new LSL_String(txn.ToString()),
  10414. new LSL_Integer(replycode),
  10415. new LSL_String(replydata) },
  10416. new DetectParams[0]));
  10417. }
  10418. });
  10419. return txn.ToString();
  10420. }
  10421. #endregion
  10422. }
  10423. public class NotecardCache
  10424. {
  10425. protected class Notecard
  10426. {
  10427. public string[] text;
  10428. public DateTime lastRef;
  10429. }
  10430. protected static Dictionary<UUID, Notecard> m_Notecards =
  10431. new Dictionary<UUID, Notecard>();
  10432. public static void Cache(UUID assetID, string text)
  10433. {
  10434. CheckCache();
  10435. lock (m_Notecards)
  10436. {
  10437. if (m_Notecards.ContainsKey(assetID))
  10438. return;
  10439. Notecard nc = new Notecard();
  10440. nc.lastRef = DateTime.Now;
  10441. nc.text = SLUtil.ParseNotecardToList(text).ToArray();
  10442. m_Notecards[assetID] = nc;
  10443. }
  10444. }
  10445. public static bool IsCached(UUID assetID)
  10446. {
  10447. lock (m_Notecards)
  10448. {
  10449. return m_Notecards.ContainsKey(assetID);
  10450. }
  10451. }
  10452. public static int GetLines(UUID assetID)
  10453. {
  10454. if (!IsCached(assetID))
  10455. return -1;
  10456. lock (m_Notecards)
  10457. {
  10458. m_Notecards[assetID].lastRef = DateTime.Now;
  10459. return m_Notecards[assetID].text.Length;
  10460. }
  10461. }
  10462. /// <summary>
  10463. /// Get a notecard line.
  10464. /// </summary>
  10465. /// <param name="assetID"></param>
  10466. /// <param name="lineNumber">Lines start at index 0</param>
  10467. /// <returns></returns>
  10468. public static string GetLine(UUID assetID, int lineNumber)
  10469. {
  10470. if (lineNumber < 0)
  10471. return "";
  10472. string data;
  10473. if (!IsCached(assetID))
  10474. return "";
  10475. lock (m_Notecards)
  10476. {
  10477. m_Notecards[assetID].lastRef = DateTime.Now;
  10478. if (lineNumber >= m_Notecards[assetID].text.Length)
  10479. return "\n\n\n";
  10480. data = m_Notecards[assetID].text[lineNumber];
  10481. return data;
  10482. }
  10483. }
  10484. /// <summary>
  10485. /// Get a notecard line.
  10486. /// </summary>
  10487. /// <param name="assetID"></param>
  10488. /// <param name="lineNumber">Lines start at index 0</param>
  10489. /// <param name="maxLength">
  10490. /// Maximum length of the returned line.
  10491. /// </param>
  10492. /// <returns>
  10493. /// If the line length is longer than <paramref name="maxLength"/>,
  10494. /// the return string will be truncated.
  10495. /// </returns>
  10496. public static string GetLine(UUID assetID, int lineNumber, int maxLength)
  10497. {
  10498. string line = GetLine(assetID, lineNumber);
  10499. if (line.Length > maxLength)
  10500. line = line.Substring(0, maxLength);
  10501. return line;
  10502. }
  10503. public static void CheckCache()
  10504. {
  10505. lock (m_Notecards)
  10506. {
  10507. foreach (UUID key in new List<UUID>(m_Notecards.Keys))
  10508. {
  10509. Notecard nc = m_Notecards[key];
  10510. if (nc.lastRef.AddSeconds(30) < DateTime.Now)
  10511. m_Notecards.Remove(key);
  10512. }
  10513. }
  10514. }
  10515. }
  10516. }