LSL_BuiltIn_Commands.cs 251 KB

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