LSL_Api.cs 456 KB

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