ClientView.cs 233 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926
  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.Generic;
  29. using System.Net;
  30. using System.Net.Sockets;
  31. using System.Reflection;
  32. using System.Text;
  33. using System.Threading;
  34. using System.Timers;
  35. using Axiom.Math;
  36. using libsecondlife;
  37. using libsecondlife.Packets;
  38. using log4net;
  39. using OpenSim.Framework;
  40. using OpenSim.Framework.Communications.Cache;
  41. using OpenSim.Region.Environment.Scenes;
  42. using Timer=System.Timers.Timer;
  43. namespace OpenSim.Region.ClientStack
  44. {
  45. public delegate bool PacketMethod(IClientAPI simClient, Packet packet);
  46. /// <summary>
  47. /// Handles new client connections
  48. /// Constructor takes a single Packet and authenticates everything
  49. /// </summary>
  50. public class ClientView : IClientAPI
  51. {
  52. private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
  53. // ~ClientView()
  54. // {
  55. // m_log.Info("[CLIENTVIEW]: Destructor called");
  56. // }
  57. /* static variables */
  58. public static TerrainManager TerrainManager;
  59. public delegate bool SynchronizeClientHandler(IScene scene, Packet packet, LLUUID agentID, ThrottleOutPacketType throttlePacketType);
  60. public static SynchronizeClientHandler SynchronizeClient = null;
  61. /* private variables */
  62. private readonly LLUUID m_sessionId;
  63. private LLUUID m_secureSessionId = LLUUID.Zero;
  64. //private AgentAssetUpload UploadAssets;
  65. private int m_debug = 0;
  66. private readonly AssetCache m_assetCache;
  67. // private InventoryCache m_inventoryCache;
  68. private int m_cachedTextureSerial = 0;
  69. private Timer m_clientPingTimer;
  70. private bool m_clientBlocked = false;
  71. private int m_packetsReceived = 0;
  72. private int m_lastPacketsReceivedSentToScene = 0;
  73. private int m_unAckedBytes = 0;
  74. private int m_packetsSent = 0;
  75. private int m_lastPacketsSentSentToScene = 0;
  76. private int m_probesWithNoIngressPackets = 0;
  77. private int m_lastPacketsReceived = 0;
  78. private byte[] ZeroOutBuffer = new byte[4096];
  79. private readonly LLUUID m_agentId;
  80. private readonly uint m_circuitCode;
  81. private int m_moneyBalance;
  82. private int m_animationSequenceNumber = 1;
  83. private byte[] m_channelVersion = Helpers.StringToField("OpenSimulator 0.5"); // Dummy value needed by libSL
  84. /* protected variables */
  85. protected static Dictionary<PacketType, PacketMethod> PacketHandlers =
  86. new Dictionary<PacketType, PacketMethod>(); //Global/static handlers for all clients
  87. protected Dictionary<PacketType, PacketMethod> m_packetHandlers = new Dictionary<PacketType, PacketMethod>();
  88. protected IScene m_scene;
  89. protected AgentCircuitManager m_authenticateSessionsHandler;
  90. protected PacketQueue m_packetQueue;
  91. protected Dictionary<uint, uint> m_pendingAcks = new Dictionary<uint, uint>();
  92. protected Dictionary<uint, Packet> m_needAck = new Dictionary<uint, Packet>();
  93. protected Timer m_ackTimer;
  94. protected uint m_sequence = 0;
  95. protected object m_sequenceLock = new object();
  96. protected const int MAX_APPENDED_ACKS = 10;
  97. protected const int RESEND_TIMEOUT = 4000;
  98. protected const int MAX_SEQUENCE = 0xFFFFFF;
  99. protected PacketServer m_networkServer;
  100. /* public variables */
  101. protected string m_firstName;
  102. protected string m_lastName;
  103. protected Thread m_clientThread;
  104. protected LLVector3 m_startpos;
  105. protected EndPoint m_userEndPoint;
  106. protected EndPoint m_proxyEndPoint;
  107. /* Instantiated Designated Event Delegates */
  108. //- used so we don't create new objects for each incoming packet and then toss it out later */
  109. private RequestAvatarProperties handlerRequestAvatarProperties = null; //OnRequestAvatarProperties;
  110. private UpdateAvatarProperties handlerUpdateAvatarProperties = null; // OnUpdateAvatarProperties;
  111. private ChatFromViewer handlerChatFromViewer = null; //OnChatFromViewer;
  112. private ChatFromViewer handlerChatFromViewer2 = null; //OnChatFromViewer;
  113. private ImprovedInstantMessage handlerInstantMessage = null; //OnInstantMessage;
  114. private FriendActionDelegate handlerApproveFriendRequest = null; //OnApproveFriendRequest;
  115. private FriendshipTermination handlerTerminateFriendship = null; //OnTerminateFriendship;
  116. private RezObject handlerRezObject = null; //OnRezObject;
  117. private GenericCall4 handlerDeRezObject = null; //OnDeRezObject;
  118. private ModifyTerrain handlerModifyTerrain = null;
  119. private Action<IClientAPI> handlerRegionHandShakeReply = null; //OnRegionHandShakeReply;
  120. private GenericCall2 handlerRequestWearables = null; //OnRequestWearables;
  121. private Action<IClientAPI> handlerRequestAvatarsData = null; //OnRequestAvatarsData;
  122. private SetAppearance handlerSetAppearance = null; //OnSetAppearance;
  123. private AvatarNowWearing handlerAvatarNowWearing = null; //OnAvatarNowWearing;
  124. private RezSingleAttachmentFromInv handlerRezSingleAttachment = null; //OnRezSingleAttachmentFromInv;
  125. private UUIDNameRequest handlerDetachAttachmentIntoInv = null; // Detach attachment!
  126. private ObjectAttach handlerObjectAttach = null; //OnObjectAttach;
  127. private SetAlwaysRun handlerSetAlwaysRun = null; //OnSetAlwaysRun;
  128. private GenericCall2 handlerCompleteMovementToRegion = null; //OnCompleteMovementToRegion;
  129. private UpdateAgent handlerAgentUpdate = null; //OnAgentUpdate;
  130. private StartAnim handlerStartAnim = null;
  131. private StopAnim handlerStopAnim = null;
  132. private AgentRequestSit handlerAgentRequestSit = null; //OnAgentRequestSit;
  133. private AgentSit handlerAgentSit = null; //OnAgentSit;
  134. private AvatarPickerRequest handlerAvatarPickerRequest = null; //OnAvatarPickerRequest;
  135. private FetchInventory handlerAgentDataUpdateRequest = null; //OnAgentDataUpdateRequest;
  136. private FetchInventory handlerUserInfoRequest = null; //OnUserInfoRequest;
  137. private TeleportLocationRequest handlerSetStartLocationRequest = null; //OnSetStartLocationRequest;
  138. private TeleportLandmarkRequest handlerTeleportLandmarkRequest = null; //OnTeleportLandmarkRequest;
  139. private LinkObjects handlerLinkObjects = null; //OnLinkObjects;
  140. private DelinkObjects handlerDelinkObjects = null; //OnDelinkObjects;
  141. private AddNewPrim handlerAddPrim = null; //OnAddPrim;
  142. private UpdateShape handlerUpdatePrimShape = null; //null;
  143. private ObjectExtraParams handlerUpdateExtraParams = null; //OnUpdateExtraParams;
  144. private ObjectDuplicate handlerObjectDuplicate = null;
  145. private ObjectDuplicateOnRay handlerObjectDuplicateOnRay = null;
  146. private ObjectSelect handlerObjectSelect = null;
  147. private ObjectDeselect handlerObjectDeselect = null;
  148. private ObjectIncludeInSearch handlerObjectIncludeInSearch = null;
  149. private UpdatePrimFlags handlerUpdatePrimFlags = null; //OnUpdatePrimFlags;
  150. private UpdatePrimTexture handlerUpdatePrimTexture = null;
  151. private UpdateVector handlerGrabObject = null; //OnGrabObject;
  152. private MoveObject handlerGrabUpdate = null; //OnGrabUpdate;
  153. private ObjectSelect handlerDeGrabObject = null; //OnDeGrabObject;
  154. private GenericCall7 handlerObjectDescription = null;
  155. private GenericCall7 handlerObjectName = null;
  156. private ObjectPermissions handlerObjectPermissions = null;
  157. private RequestObjectPropertiesFamily handlerRequestObjectPropertiesFamily = null; //OnRequestObjectPropertiesFamily;
  158. private TextureRequest handlerTextureRequest = null;
  159. private UDPAssetUploadRequest handlerAssetUploadRequest = null; //OnAssetUploadRequest;
  160. private RequestXfer handlerRequestXfer = null; //OnRequestXfer;
  161. private XferReceive handlerXferReceive = null; //OnXferReceive;
  162. private ConfirmXfer handlerConfirmXfer = null; //OnConfirmXfer;
  163. private CreateInventoryFolder handlerCreateInventoryFolder = null; //OnCreateNewInventoryFolder;
  164. private UpdateInventoryFolder handlerUpdateInventoryFolder = null;
  165. private MoveInventoryFolder handlerMoveInventoryFolder = null;
  166. private CreateNewInventoryItem handlerCreateNewInventoryItem = null; //OnCreateNewInventoryItem;
  167. private FetchInventory handlerFetchInventory = null;
  168. private FetchInventoryDescendents handlerFetchInventoryDescendents = null; //OnFetchInventoryDescendents;
  169. private PurgeInventoryDescendents handlerPurgeInventoryDescendents = null; //OnPurgeInventoryDescendents;
  170. private UpdateInventoryItem handlerUpdateInventoryItem = null;
  171. private CopyInventoryItem handlerCopyInventoryItem = null;
  172. private MoveInventoryItem handlerMoveInventoryItem = null;
  173. private RemoveInventoryItem handlerRemoveInventoryItem = null;
  174. private RemoveInventoryFolder handlerRemoveInventoryFolder = null;
  175. private RequestTaskInventory handlerRequestTaskInventory = null; //OnRequestTaskInventory;
  176. private UpdateTaskInventory handlerUpdateTaskInventory = null; //OnUpdateTaskInventory;
  177. private MoveTaskInventory handlerMoveTaskItem = null;
  178. private RemoveTaskInventory handlerRemoveTaskItem = null; //OnRemoveTaskItem;
  179. private RezScript handlerRezScript = null; //OnRezScript;
  180. private RequestMapBlocks handlerRequestMapBlocks = null; //OnRequestMapBlocks;
  181. private RequestMapName handlerMapNameRequest = null; //OnMapNameRequest;
  182. private TeleportLocationRequest handlerTeleportLocationRequest = null; //OnTeleportLocationRequest;
  183. private MoneyBalanceRequest handlerMoneyBalanceRequest = null; //OnMoneyBalanceRequest;
  184. private UUIDNameRequest handlerNameRequest = null;
  185. private ParcelAccessListRequest handlerParcelAccessListRequest = null; //OnParcelAccessListRequest;
  186. private ParcelAccessListUpdateRequest handlerParcelAccessListUpdateRequest = null; //OnParcelAccessListUpdateRequest;
  187. private ParcelPropertiesRequest handlerParcelPropertiesRequest = null; //OnParcelPropertiesRequest;
  188. private ParcelDivideRequest handlerParcelDivideRequest = null; //OnParcelDivideRequest;
  189. private ParcelJoinRequest handlerParcelJoinRequest = null; //OnParcelJoinRequest;
  190. private ParcelPropertiesUpdateRequest handlerParcelPropertiesUpdateRequest = null; //OnParcelPropertiesUpdateRequest;
  191. private ParcelSelectObjects handlerParcelSelectObjects = null; //OnParcelSelectObjects;
  192. private ParcelObjectOwnerRequest handlerParcelObjectOwnerRequest = null; //OnParcelObjectOwnerRequest;
  193. private EstateOwnerMessageRequest handlerEstateOwnerMessage = null; //OnEstateOwnerMessage;
  194. private RegionInfoRequest handlerRegionInfoRequest = null; //OnRegionInfoRequest;
  195. private EstateCovenantRequest handlerEstateCovenantRequest = null; //OnEstateCovenantRequest;
  196. private RequestGodlikePowers handlerReqGodlikePowers = null; //OnRequestGodlikePowers;
  197. private GodKickUser handlerGodKickUser = null; //OnGodKickUser;
  198. private ViewerEffectEventHandler handlerViewerEffect = null; //OnViewerEffect;
  199. private Action<IClientAPI> handlerLogout = null; //OnLogout;
  200. private MoneyTransferRequest handlerMoneyTransferRequest = null; //OnMoneyTransferRequest;
  201. private ParcelBuy handlerParcelBuy = null;
  202. private EconomyDataRequest handlerEconomoyDataRequest = null;
  203. private UpdateVector handlerUpdatePrimSinglePosition = null; //OnUpdatePrimSinglePosition;
  204. private UpdatePrimSingleRotation handlerUpdatePrimSingleRotation = null; //OnUpdatePrimSingleRotation;
  205. private UpdateVector handlerUpdatePrimScale = null; //OnUpdatePrimScale;
  206. private UpdateVector handlerUpdatePrimGroupScale = null; //OnUpdateGroupScale;
  207. private UpdateVector handlerUpdateVector = null; //OnUpdatePrimGroupPosition;
  208. private UpdatePrimRotation handlerUpdatePrimRotation = null; //OnUpdatePrimGroupRotation;
  209. private UpdatePrimGroupRotation handlerUpdatePrimGroupRotation = null; //OnUpdatePrimGroupMouseRotation;
  210. private PacketStats handlerPacketStats = null; // OnPacketStats;#
  211. private RequestAsset handlerRequestAsset = null; // OnRequestAsset;
  212. private UUIDNameRequest handlerTeleportHomeRequest = null;
  213. private ScriptAnswer handlerScriptAnswer = null;
  214. private RequestPayPrice handlerRequestPayPrice = null;
  215. private ObjectDeselect handlerObjectDetach = null;
  216. private AgentSit handlerOnUndo = null;
  217. /* Properties */
  218. public LLUUID SecureSessionId
  219. {
  220. get { return m_secureSessionId; }
  221. }
  222. public IScene Scene
  223. {
  224. get { return m_scene; }
  225. }
  226. public LLUUID SessionId
  227. {
  228. get { return m_sessionId; }
  229. }
  230. public LLVector3 StartPos
  231. {
  232. get { return m_startpos; }
  233. set { m_startpos = value; }
  234. }
  235. public LLUUID AgentId
  236. {
  237. get { return m_agentId; }
  238. }
  239. /// <summary>
  240. /// This is a utility method used by single states to not duplicate kicks and blue card of death messages.
  241. /// </summary>
  242. public bool ChildAgentStatus()
  243. {
  244. return m_scene.PresenceChildStatus(AgentId);
  245. }
  246. /// <summary>
  247. /// First name of the agent/avatar represented by the client
  248. /// </summary>
  249. public string FirstName
  250. {
  251. get { return m_firstName; }
  252. }
  253. /// <summary>
  254. /// Last name of the agent/avatar represented by the client
  255. /// </summary>
  256. public string LastName
  257. {
  258. get { return m_lastName; }
  259. }
  260. /// <summary>
  261. /// Full name of the client (first name and last name)
  262. /// </summary>
  263. public string Name
  264. {
  265. get { return FirstName + " " + LastName; }
  266. }
  267. public uint CircuitCode
  268. {
  269. get { return m_circuitCode; }
  270. }
  271. public int MoneyBalance
  272. {
  273. get { return m_moneyBalance; }
  274. }
  275. public int NextAnimationSequenceNumber
  276. {
  277. get { return m_animationSequenceNumber++; }
  278. }
  279. /* METHODS */
  280. public ClientView(EndPoint remoteEP, IScene scene, AssetCache assetCache, PacketServer packServer,
  281. AgentCircuitManager authenSessions, LLUUID agentId, LLUUID sessionId, uint circuitCode, EndPoint proxyEP)
  282. {
  283. m_moneyBalance = 1000;
  284. m_channelVersion = Helpers.StringToField(scene.GetSimulatorVersion());
  285. m_scene = scene;
  286. m_assetCache = assetCache;
  287. m_networkServer = packServer;
  288. // m_inventoryCache = inventoryCache;
  289. m_authenticateSessionsHandler = authenSessions;
  290. m_log.Info("[CLIENT]: Started up new client thread to handle incoming request");
  291. m_agentId = agentId;
  292. m_sessionId = sessionId;
  293. m_circuitCode = circuitCode;
  294. m_userEndPoint = remoteEP;
  295. m_proxyEndPoint = proxyEP;
  296. m_startpos = m_authenticateSessionsHandler.GetPosition(circuitCode);
  297. // While working on this, the BlockingQueue had me fooled for a bit.
  298. // The Blocking queue causes the thread to stop until there's something
  299. // in it to process. It's an on-purpose threadlock though because
  300. // without it, the clientloop will suck up all sim resources.
  301. m_packetQueue = new PacketQueue(agentId);
  302. RegisterLocalPacketHandlers();
  303. m_clientThread = new Thread(new ThreadStart(AuthUser));
  304. m_clientThread.Name = "ClientThread";
  305. m_clientThread.IsBackground = true;
  306. m_clientThread.Start();
  307. ThreadTracker.Add(m_clientThread);
  308. }
  309. public void SetDebug(int newDebug)
  310. {
  311. m_debug = newDebug;
  312. }
  313. # region Client Methods
  314. private void CloseCleanup(bool shutdownCircuit)
  315. {
  316. m_scene.RemoveClient(AgentId);
  317. //m_log.InfoFormat("[CLIENTVIEW] Memory pre GC {0}", System.GC.GetTotalMemory(false));
  318. //m_log.InfoFormat("[CLIENTVIEW] Memory post GC {0}", System.GC.GetTotalMemory(true));
  319. // Send the STOP packet
  320. DisableSimulatorPacket disable = (DisableSimulatorPacket)PacketPool.Instance.GetPacket(PacketType.DisableSimulator);
  321. OutPacket(disable, ThrottleOutPacketType.Unknown);
  322. m_packetQueue.Close();
  323. Thread.Sleep(2000);
  324. // Shut down timers
  325. m_ackTimer.Stop();
  326. m_clientPingTimer.Stop();
  327. // This is just to give the client a reasonable chance of
  328. // flushing out all it's packets. There should probably
  329. // be a better mechanism here
  330. // We can't reach into other scenes and close the connection
  331. // We need to do this over grid communications
  332. //m_scene.CloseAllAgents(CircuitCode);
  333. // If we're not shutting down the circuit, then this is the last time we'll go here.
  334. // If we are shutting down the circuit, the UDP Server will come back here with
  335. // ShutDownCircuit = false
  336. if (!(shutdownCircuit))
  337. {
  338. GC.Collect();
  339. m_clientThread.Abort();
  340. }
  341. }
  342. /// <summary>
  343. /// Close down the client view. This *must* be the last method called, since the last #
  344. /// statement of CloseCleanup() aborts the thread.
  345. /// </summary>
  346. /// <param name="shutdownCircuit"></param>
  347. public void Close(bool shutdownCircuit)
  348. {
  349. // Pull Client out of Region
  350. m_log.Info("[CLIENT]: Close has been called");
  351. m_packetQueue.Flush();
  352. //raiseevent on the packet server to Shutdown the circuit
  353. if (shutdownCircuit)
  354. {
  355. OnConnectionClosed(this);
  356. }
  357. CloseCleanup(shutdownCircuit);
  358. }
  359. public void Kick(string message)
  360. {
  361. if (!ChildAgentStatus())
  362. {
  363. KickUserPacket kupack = (KickUserPacket)PacketPool.Instance.GetPacket(PacketType.KickUser);
  364. kupack.UserInfo.AgentID = AgentId;
  365. kupack.UserInfo.SessionID = SessionId;
  366. kupack.TargetBlock.TargetIP = (uint)0;
  367. kupack.TargetBlock.TargetPort = (ushort)0;
  368. kupack.UserInfo.Reason = Helpers.StringToField(message);
  369. OutPacket(kupack, ThrottleOutPacketType.Task);
  370. }
  371. }
  372. public void Stop()
  373. {
  374. // Shut down timers
  375. m_ackTimer.Stop();
  376. m_clientPingTimer.Stop();
  377. }
  378. public void Restart()
  379. {
  380. // re-construct
  381. m_pendingAcks = new Dictionary<uint, uint>();
  382. m_needAck = new Dictionary<uint, Packet>();
  383. m_sequence += 1000000;
  384. m_ackTimer = new Timer(750);
  385. m_ackTimer.Elapsed += new ElapsedEventHandler(AckTimer_Elapsed);
  386. m_ackTimer.Start();
  387. m_clientPingTimer = new Timer(5000);
  388. m_clientPingTimer.Elapsed += new ElapsedEventHandler(CheckClientConnectivity);
  389. m_clientPingTimer.Enabled = true;
  390. }
  391. public void Terminate()
  392. {
  393. // disable blocking queue
  394. m_packetQueue.Enqueue(null);
  395. // wait for thread stoped
  396. m_clientThread.Join();
  397. // delete circuit code
  398. m_networkServer.CloseClient(this);
  399. }
  400. #endregion
  401. # region Packet Handling
  402. public static bool AddPacketHandler(PacketType packetType, PacketMethod handler)
  403. {
  404. bool result = false;
  405. lock (PacketHandlers)
  406. {
  407. if (!PacketHandlers.ContainsKey(packetType))
  408. {
  409. PacketHandlers.Add(packetType, handler);
  410. result = true;
  411. }
  412. }
  413. return result;
  414. }
  415. public bool AddLocalPacketHandler(PacketType packetType, PacketMethod handler)
  416. {
  417. bool result = false;
  418. lock (m_packetHandlers)
  419. {
  420. if (!m_packetHandlers.ContainsKey(packetType))
  421. {
  422. m_packetHandlers.Add(packetType, handler);
  423. result = true;
  424. }
  425. }
  426. return result;
  427. }
  428. /// <summary>
  429. /// Try to process a packet using registered packet handlers
  430. /// </summary>
  431. /// <param name="packet"></param>
  432. /// <returns>True if a handler was found which successfully processed the packet.</returns>
  433. protected virtual bool ProcessPacketMethod(Packet packet)
  434. {
  435. bool result = false;
  436. bool found = false;
  437. PacketMethod method;
  438. if (m_packetHandlers.TryGetValue(packet.Type, out method))
  439. {
  440. //there is a local handler for this packet type
  441. result = method(this, packet);
  442. }
  443. else
  444. {
  445. //there is not a local handler so see if there is a Global handler
  446. lock (PacketHandlers)
  447. {
  448. found = PacketHandlers.TryGetValue(packet.Type, out method);
  449. }
  450. if (found)
  451. {
  452. result = method(this, packet);
  453. }
  454. }
  455. return result;
  456. }
  457. protected void DebugPacket(string direction, Packet packet)
  458. {
  459. if (m_debug > 0)
  460. {
  461. string info = String.Empty;
  462. if (m_debug < 255 && packet.Type == PacketType.AgentUpdate)
  463. return;
  464. if (m_debug < 254 && packet.Type == PacketType.ViewerEffect)
  465. return;
  466. if (m_debug < 253 && (
  467. packet.Type == PacketType.CompletePingCheck ||
  468. packet.Type == PacketType.StartPingCheck
  469. ))
  470. return;
  471. if (m_debug < 252 && packet.Type == PacketType.PacketAck)
  472. return;
  473. if (m_debug > 1)
  474. {
  475. info = packet.ToString();
  476. }
  477. else
  478. {
  479. info = packet.Type.ToString();
  480. }
  481. Console.WriteLine(m_circuitCode + ":" + direction + ": " + info);
  482. }
  483. }
  484. protected virtual void ClientLoop()
  485. {
  486. m_log.Info("[CLIENT]: Entered loop");
  487. while (true)
  488. {
  489. QueItem nextPacket = m_packetQueue.Dequeue();
  490. if (nextPacket == null)
  491. {
  492. break;
  493. }
  494. if (nextPacket.Incoming)
  495. {
  496. if (nextPacket.Packet.Type != PacketType.AgentUpdate)
  497. {
  498. m_packetsReceived++;
  499. }
  500. DebugPacket("IN", nextPacket.Packet);
  501. ProcessInPacket(nextPacket.Packet);
  502. }
  503. else
  504. {
  505. DebugPacket("OUT", nextPacket.Packet);
  506. ProcessOutPacket(nextPacket.Packet);
  507. }
  508. }
  509. }
  510. # endregion
  511. protected void CheckClientConnectivity(object sender, ElapsedEventArgs e)
  512. {
  513. if (m_packetsReceived == m_lastPacketsReceived)
  514. {
  515. m_probesWithNoIngressPackets++;
  516. if ((m_probesWithNoIngressPackets > 30 && !m_clientBlocked) || (m_probesWithNoIngressPackets > 90 && m_clientBlocked))
  517. {
  518. if (OnConnectionClosed != null)
  519. {
  520. OnConnectionClosed(this);
  521. }
  522. }
  523. else
  524. {
  525. // this will normally trigger at least one packet (ping response)
  526. SendStartPingCheck(0);
  527. }
  528. }
  529. else
  530. {
  531. // Something received in the meantime - we can reset the counters
  532. m_probesWithNoIngressPackets = 0;
  533. m_lastPacketsReceived = m_packetsReceived;
  534. }
  535. //SendPacketStats();
  536. }
  537. # region Setup
  538. protected virtual void InitNewClient()
  539. {
  540. //this.UploadAssets = new AgentAssetUpload(this, m_assetCache, m_inventoryCache);
  541. // Establish our two timers. We could probably get this down to one
  542. m_ackTimer = new Timer(750);
  543. m_ackTimer.Elapsed += new ElapsedEventHandler(AckTimer_Elapsed);
  544. m_ackTimer.Start();
  545. m_clientPingTimer = new Timer(5000);
  546. m_clientPingTimer.Elapsed += new ElapsedEventHandler(CheckClientConnectivity);
  547. m_clientPingTimer.Enabled = true;
  548. m_log.Info("[CLIENT]: Adding viewer agent to scene");
  549. m_scene.AddNewClient(this, true);
  550. }
  551. protected virtual void AuthUser()
  552. {
  553. // AuthenticateResponse sessionInfo = m_gridServer.AuthenticateSession(m_cirpack.m_circuitCode.m_sessionId, m_cirpack.m_circuitCode.ID, m_cirpack.m_circuitCode.Code);
  554. AuthenticateResponse sessionInfo =
  555. m_authenticateSessionsHandler.AuthenticateSession(m_sessionId, m_agentId,
  556. m_circuitCode);
  557. if (!sessionInfo.Authorised)
  558. {
  559. //session/circuit not authorised
  560. m_log.Info("[CLIENT]: New user request denied to " + m_userEndPoint.ToString());
  561. m_packetQueue.Close();
  562. m_clientThread.Abort();
  563. }
  564. else
  565. {
  566. m_log.Info("[CLIENT]: Got authenticated connection from " + m_userEndPoint.ToString());
  567. //session is authorised
  568. m_firstName = sessionInfo.LoginInfo.First;
  569. m_lastName = sessionInfo.LoginInfo.Last;
  570. if (sessionInfo.LoginInfo.SecureSession != LLUUID.Zero)
  571. {
  572. m_secureSessionId = sessionInfo.LoginInfo.SecureSession;
  573. }
  574. // This sets up all the timers
  575. InitNewClient();
  576. ClientLoop();
  577. }
  578. }
  579. # endregion
  580. // Previously ClientView.API partial class
  581. public event Action<IClientAPI> OnLogout;
  582. public event ObjectPermissions OnObjectPermissions;
  583. public event Action<IClientAPI> OnConnectionClosed;
  584. public event ViewerEffectEventHandler OnViewerEffect;
  585. public event ImprovedInstantMessage OnInstantMessage;
  586. public event ChatFromViewer OnChatFromViewer;
  587. public event TextureRequest OnRequestTexture;
  588. public event RezObject OnRezObject;
  589. public event GenericCall4 OnDeRezObject;
  590. public event ModifyTerrain OnModifyTerrain;
  591. public event Action<IClientAPI> OnRegionHandShakeReply;
  592. public event GenericCall2 OnRequestWearables;
  593. public event SetAppearance OnSetAppearance;
  594. public event AvatarNowWearing OnAvatarNowWearing;
  595. public event RezSingleAttachmentFromInv OnRezSingleAttachmentFromInv;
  596. public event UUIDNameRequest OnDetachAttachmentIntoInv;
  597. public event ObjectAttach OnObjectAttach;
  598. public event ObjectDeselect OnObjectDetach;
  599. public event GenericCall2 OnCompleteMovementToRegion;
  600. public event UpdateAgent OnAgentUpdate;
  601. public event AgentRequestSit OnAgentRequestSit;
  602. public event AgentSit OnAgentSit;
  603. public event AvatarPickerRequest OnAvatarPickerRequest;
  604. public event StartAnim OnStartAnim;
  605. public event StopAnim OnStopAnim;
  606. public event Action<IClientAPI> OnRequestAvatarsData;
  607. public event LinkObjects OnLinkObjects;
  608. public event DelinkObjects OnDelinkObjects;
  609. public event UpdateVector OnGrabObject;
  610. public event ObjectSelect OnDeGrabObject;
  611. public event ObjectDuplicate OnObjectDuplicate;
  612. public event ObjectDuplicateOnRay OnObjectDuplicateOnRay;
  613. public event MoveObject OnGrabUpdate;
  614. public event AddNewPrim OnAddPrim;
  615. public event RequestGodlikePowers OnRequestGodlikePowers;
  616. public event GodKickUser OnGodKickUser;
  617. public event ObjectExtraParams OnUpdateExtraParams;
  618. public event UpdateShape OnUpdatePrimShape;
  619. public event ObjectSelect OnObjectSelect;
  620. public event ObjectDeselect OnObjectDeselect;
  621. public event GenericCall7 OnObjectDescription;
  622. public event GenericCall7 OnObjectName;
  623. public event ObjectIncludeInSearch OnObjectIncludeInSearch;
  624. public event RequestObjectPropertiesFamily OnRequestObjectPropertiesFamily;
  625. public event UpdatePrimFlags OnUpdatePrimFlags;
  626. public event UpdatePrimTexture OnUpdatePrimTexture;
  627. public event UpdateVector OnUpdatePrimGroupPosition;
  628. public event UpdateVector OnUpdatePrimSinglePosition;
  629. public event UpdatePrimRotation OnUpdatePrimGroupRotation;
  630. public event UpdatePrimSingleRotation OnUpdatePrimSingleRotation;
  631. public event UpdatePrimGroupRotation OnUpdatePrimGroupMouseRotation;
  632. public event UpdateVector OnUpdatePrimScale;
  633. public event UpdateVector OnUpdatePrimGroupScale;
  634. public event StatusChange OnChildAgentStatus;
  635. public event GenericCall2 OnStopMovement;
  636. public event Action<LLUUID> OnRemoveAvatar;
  637. public event RequestMapBlocks OnRequestMapBlocks;
  638. public event RequestMapName OnMapNameRequest;
  639. public event TeleportLocationRequest OnTeleportLocationRequest;
  640. public event TeleportLandmarkRequest OnTeleportLandmarkRequest;
  641. public event DisconnectUser OnDisconnectUser;
  642. public event RequestAvatarProperties OnRequestAvatarProperties;
  643. public event SetAlwaysRun OnSetAlwaysRun;
  644. public event FetchInventory OnAgentDataUpdateRequest;
  645. public event FetchInventory OnUserInfoRequest;
  646. public event TeleportLocationRequest OnSetStartLocationRequest;
  647. public event UpdateAvatarProperties OnUpdateAvatarProperties;
  648. public event CreateNewInventoryItem OnCreateNewInventoryItem;
  649. public event CreateInventoryFolder OnCreateNewInventoryFolder;
  650. public event UpdateInventoryFolder OnUpdateInventoryFolder;
  651. public event MoveInventoryFolder OnMoveInventoryFolder;
  652. public event FetchInventoryDescendents OnFetchInventoryDescendents;
  653. public event PurgeInventoryDescendents OnPurgeInventoryDescendents;
  654. public event FetchInventory OnFetchInventory;
  655. public event RequestTaskInventory OnRequestTaskInventory;
  656. public event UpdateInventoryItem OnUpdateInventoryItem;
  657. public event CopyInventoryItem OnCopyInventoryItem;
  658. public event MoveInventoryItem OnMoveInventoryItem;
  659. public event RemoveInventoryItem OnRemoveInventoryItem;
  660. public event RemoveInventoryFolder OnRemoveInventoryFolder;
  661. public event UDPAssetUploadRequest OnAssetUploadRequest;
  662. public event XferReceive OnXferReceive;
  663. public event RequestXfer OnRequestXfer;
  664. public event ConfirmXfer OnConfirmXfer;
  665. public event RezScript OnRezScript;
  666. public event UpdateTaskInventory OnUpdateTaskInventory;
  667. public event MoveTaskInventory OnMoveTaskItem;
  668. public event RemoveTaskInventory OnRemoveTaskItem;
  669. public event RequestAsset OnRequestAsset;
  670. public event UUIDNameRequest OnNameFromUUIDRequest;
  671. public event ParcelAccessListRequest OnParcelAccessListRequest;
  672. public event ParcelAccessListUpdateRequest OnParcelAccessListUpdateRequest;
  673. public event ParcelPropertiesRequest OnParcelPropertiesRequest;
  674. public event ParcelDivideRequest OnParcelDivideRequest;
  675. public event ParcelJoinRequest OnParcelJoinRequest;
  676. public event ParcelPropertiesUpdateRequest OnParcelPropertiesUpdateRequest;
  677. public event ParcelSelectObjects OnParcelSelectObjects;
  678. public event ParcelObjectOwnerRequest OnParcelObjectOwnerRequest;
  679. public event EstateOwnerMessageRequest OnEstateOwnerMessage;
  680. public event RegionInfoRequest OnRegionInfoRequest;
  681. public event EstateCovenantRequest OnEstateCovenantRequest;
  682. public event FriendActionDelegate OnApproveFriendRequest;
  683. public event FriendActionDelegate OnDenyFriendRequest;
  684. public event FriendshipTermination OnTerminateFriendship;
  685. public event PacketStats OnPacketStats;
  686. public event MoneyTransferRequest OnMoneyTransferRequest;
  687. public event EconomyDataRequest OnEconomyDataRequest;
  688. public event MoneyBalanceRequest OnMoneyBalanceRequest;
  689. public event ParcelBuy OnParcelBuy;
  690. public event UUIDNameRequest OnTeleportHomeRequest;
  691. public event ScriptAnswer OnScriptAnswer;
  692. public event RequestPayPrice OnRequestPayPrice;
  693. public event AgentSit OnUndo;
  694. #region Scene/Avatar to Client
  695. /// <summary>
  696. ///
  697. /// </summary>
  698. /// <param name="regionInfo"></param>
  699. public void SendRegionHandshake(RegionInfo regionInfo)
  700. {
  701. RegionHandshakePacket handshake = (RegionHandshakePacket)PacketPool.Instance.GetPacket(PacketType.RegionHandshake);
  702. bool estatemanager = false;
  703. LLUUID[] EstateManagers = regionInfo.EstateSettings.estateManagers;
  704. for (int i = 0; i < EstateManagers.Length; i++)
  705. {
  706. if (EstateManagers[i] == AgentId)
  707. estatemanager = true;
  708. }
  709. handshake.RegionInfo.BillableFactor = regionInfo.EstateSettings.billableFactor;
  710. handshake.RegionInfo.IsEstateManager = estatemanager;
  711. handshake.RegionInfo.TerrainHeightRange00 = regionInfo.EstateSettings.terrainHeightRange0;
  712. handshake.RegionInfo.TerrainHeightRange01 = regionInfo.EstateSettings.terrainHeightRange1;
  713. handshake.RegionInfo.TerrainHeightRange10 = regionInfo.EstateSettings.terrainHeightRange2;
  714. handshake.RegionInfo.TerrainHeightRange11 = regionInfo.EstateSettings.terrainHeightRange3;
  715. handshake.RegionInfo.TerrainStartHeight00 = regionInfo.EstateSettings.terrainStartHeight0;
  716. handshake.RegionInfo.TerrainStartHeight01 = regionInfo.EstateSettings.terrainStartHeight1;
  717. handshake.RegionInfo.TerrainStartHeight10 = regionInfo.EstateSettings.terrainStartHeight2;
  718. handshake.RegionInfo.TerrainStartHeight11 = regionInfo.EstateSettings.terrainStartHeight3;
  719. handshake.RegionInfo.SimAccess = (byte)regionInfo.EstateSettings.simAccess;
  720. handshake.RegionInfo.WaterHeight = regionInfo.EstateSettings.waterHeight;
  721. handshake.RegionInfo.RegionFlags = (uint)regionInfo.EstateSettings.regionFlags;
  722. handshake.RegionInfo.SimName = Helpers.StringToField(regionInfo.RegionName);
  723. handshake.RegionInfo.SimOwner = regionInfo.MasterAvatarAssignedUUID;
  724. handshake.RegionInfo.TerrainBase0 = regionInfo.EstateSettings.terrainBase0;
  725. handshake.RegionInfo.TerrainBase1 = regionInfo.EstateSettings.terrainBase1;
  726. handshake.RegionInfo.TerrainBase2 = regionInfo.EstateSettings.terrainBase2;
  727. handshake.RegionInfo.TerrainBase3 = regionInfo.EstateSettings.terrainBase3;
  728. handshake.RegionInfo.TerrainDetail0 = regionInfo.EstateSettings.terrainDetail0;
  729. handshake.RegionInfo.TerrainDetail1 = regionInfo.EstateSettings.terrainDetail1;
  730. handshake.RegionInfo.TerrainDetail2 = regionInfo.EstateSettings.terrainDetail2;
  731. handshake.RegionInfo.TerrainDetail3 = regionInfo.EstateSettings.terrainDetail3;
  732. handshake.RegionInfo.CacheID = LLUUID.Random(); //I guess this is for the client to remember an old setting?
  733. OutPacket(handshake, ThrottleOutPacketType.Task);
  734. }
  735. /// <summary>
  736. ///
  737. /// </summary>
  738. /// <param name="regInfo"></param>
  739. public void MoveAgentIntoRegion(RegionInfo regInfo, LLVector3 pos, LLVector3 look)
  740. {
  741. AgentMovementCompletePacket mov = (AgentMovementCompletePacket)PacketPool.Instance.GetPacket(PacketType.AgentMovementComplete);
  742. mov.SimData.ChannelVersion = m_channelVersion;
  743. mov.AgentData.SessionID = m_sessionId;
  744. mov.AgentData.AgentID = AgentId;
  745. mov.Data.RegionHandle = regInfo.RegionHandle;
  746. mov.Data.Timestamp = 1172750370; // TODO - dynamicalise this
  747. if ((pos.X == 0) && (pos.Y == 0) && (pos.Z == 0))
  748. {
  749. mov.Data.Position = m_startpos;
  750. }
  751. else
  752. {
  753. mov.Data.Position = pos;
  754. }
  755. mov.Data.LookAt = look;
  756. // Hack to get this out immediately and skip the throttles
  757. OutPacket(mov, ThrottleOutPacketType.Unknown);
  758. }
  759. /// <summary>
  760. ///
  761. /// </summary>
  762. /// <param name="message"></param>
  763. /// <param name="type"></param>
  764. /// <param name="fromPos"></param>
  765. /// <param name="fromName"></param>
  766. /// <param name="fromAgentID"></param>
  767. public void SendChatMessage(string message, byte type, LLVector3 fromPos, string fromName, LLUUID fromAgentID)
  768. {
  769. SendChatMessage(Helpers.StringToField(message), type, fromPos, fromName, fromAgentID);
  770. }
  771. public void SendChatMessage(byte[] message, byte type, LLVector3 fromPos, string fromName, LLUUID fromAgentID)
  772. {
  773. ChatFromSimulatorPacket reply = (ChatFromSimulatorPacket)PacketPool.Instance.GetPacket(PacketType.ChatFromSimulator);
  774. reply.ChatData.Audible = 1;
  775. reply.ChatData.Message = message;
  776. reply.ChatData.ChatType = type;
  777. reply.ChatData.SourceType = 1;
  778. reply.ChatData.Position = fromPos;
  779. reply.ChatData.FromName = Helpers.StringToField(fromName);
  780. reply.ChatData.OwnerID = fromAgentID;
  781. reply.ChatData.SourceID = fromAgentID;
  782. OutPacket(reply, ThrottleOutPacketType.Task);
  783. }
  784. /// <summary>
  785. /// Send an instant message to this client
  786. /// </summary>
  787. /// <param name="message"></param>
  788. /// <param name="target"></param>
  789. public void SendInstantMessage(LLUUID fromAgent, LLUUID fromAgentSession, string message, LLUUID toAgent,
  790. LLUUID imSessionID, string fromName, byte dialog, uint timeStamp)
  791. {
  792. SendInstantMessage(
  793. fromAgent, fromAgentSession, message, toAgent,
  794. imSessionID, fromName, dialog, timeStamp, new byte[0]);
  795. }
  796. /// <summary>
  797. /// Send an instant message to this client
  798. /// </summary>
  799. /// <param name="message"></param>
  800. /// <param name="target"></param>
  801. public void SendInstantMessage(LLUUID fromAgent, LLUUID fromAgentSession, string message, LLUUID toAgent,
  802. LLUUID imSessionID, string fromName, byte dialog, uint timeStamp,
  803. byte[] binaryBucket)
  804. {
  805. ImprovedInstantMessagePacket msg
  806. = (ImprovedInstantMessagePacket)PacketPool.Instance.GetPacket(PacketType.ImprovedInstantMessage);
  807. msg.AgentData.AgentID = fromAgent;
  808. msg.AgentData.SessionID = fromAgentSession;
  809. msg.MessageBlock.FromAgentName = Helpers.StringToField(fromName);
  810. msg.MessageBlock.Dialog = dialog;
  811. msg.MessageBlock.FromGroup = false;
  812. msg.MessageBlock.ID = imSessionID;
  813. msg.MessageBlock.Offline = 0;
  814. msg.MessageBlock.ParentEstateID = 0;
  815. msg.MessageBlock.Position = new LLVector3();
  816. msg.MessageBlock.RegionID = LLUUID.Random();
  817. msg.MessageBlock.Timestamp = timeStamp;
  818. msg.MessageBlock.ToAgentID = toAgent;
  819. msg.MessageBlock.Message = Helpers.StringToField(message);
  820. msg.MessageBlock.BinaryBucket = binaryBucket;
  821. OutPacket(msg, ThrottleOutPacketType.Task);
  822. }
  823. /// <summary>
  824. /// Send the region heightmap to the client
  825. /// </summary>
  826. /// <param name="map">heightmap</param>
  827. public virtual void SendLayerData(float[] map)
  828. {
  829. try
  830. {
  831. int[] patches = new int[4];
  832. for (int y = 0; y < 16; y++)
  833. {
  834. for (int x = 0; x < 16; x += 4)
  835. {
  836. patches[0] = x + 0 + y * 16;
  837. patches[1] = x + 1 + y * 16;
  838. patches[2] = x + 2 + y * 16;
  839. patches[3] = x + 3 + y * 16;
  840. Packet layerpack = TerrainManager.CreateLandPacket(map, patches);
  841. OutPacket(layerpack, ThrottleOutPacketType.Land);
  842. }
  843. }
  844. }
  845. catch (Exception e)
  846. {
  847. m_log.Warn("[client]: " +
  848. "ClientView.API.cs: SendLayerData() - Failed with exception " + e.ToString());
  849. }
  850. }
  851. /// <summary>
  852. /// Sends a specified patch to a client
  853. /// </summary>
  854. /// <param name="px">Patch coordinate (x) 0..16</param>
  855. /// <param name="py">Patch coordinate (y) 0..16</param>
  856. /// <param name="map">heightmap</param>
  857. public void SendLayerData(int px, int py, float[] map)
  858. {
  859. try
  860. {
  861. int[] patches = new int[1];
  862. int patchx, patchy;
  863. patchx = px;
  864. patchy = py;
  865. patches[0] = patchx + 0 + patchy * 16;
  866. Packet layerpack = TerrainManager.CreateLandPacket(map, patches);
  867. OutPacket(layerpack, ThrottleOutPacketType.Land);
  868. }
  869. catch (Exception e)
  870. {
  871. m_log.Warn("[client]: " +
  872. "ClientView.API.cs: SendLayerData() - Failed with exception " + e.ToString());
  873. }
  874. }
  875. /// <summary>
  876. ///
  877. /// </summary>
  878. /// <param name="neighbourHandle"></param>
  879. /// <param name="neighbourIP"></param>
  880. /// <param name="neighbourPort"></param>
  881. public void InformClientOfNeighbour(ulong neighbourHandle, IPEndPoint neighbourEndPoint)
  882. {
  883. IPAddress neighbourIP = neighbourEndPoint.Address;
  884. ushort neighbourPort = (ushort)neighbourEndPoint.Port;
  885. EnableSimulatorPacket enablesimpacket = (EnableSimulatorPacket)PacketPool.Instance.GetPacket(PacketType.EnableSimulator);
  886. // TODO: don't create new blocks if recycling an old packet
  887. enablesimpacket.SimulatorInfo = new EnableSimulatorPacket.SimulatorInfoBlock();
  888. enablesimpacket.SimulatorInfo.Handle = neighbourHandle;
  889. byte[] byteIP = neighbourIP.GetAddressBytes();
  890. enablesimpacket.SimulatorInfo.IP = (uint)byteIP[3] << 24;
  891. enablesimpacket.SimulatorInfo.IP += (uint)byteIP[2] << 16;
  892. enablesimpacket.SimulatorInfo.IP += (uint)byteIP[1] << 8;
  893. enablesimpacket.SimulatorInfo.IP += (uint)byteIP[0];
  894. enablesimpacket.SimulatorInfo.Port = neighbourPort;
  895. OutPacket(enablesimpacket, ThrottleOutPacketType.Task);
  896. }
  897. /// <summary>
  898. ///
  899. /// </summary>
  900. /// <returns></returns>
  901. public AgentCircuitData RequestClientInfo()
  902. {
  903. AgentCircuitData agentData = new AgentCircuitData();
  904. agentData.AgentID = AgentId;
  905. agentData.SessionID = m_sessionId;
  906. agentData.SecureSessionID = SecureSessionId;
  907. agentData.circuitcode = m_circuitCode;
  908. agentData.child = false;
  909. agentData.firstname = m_firstName;
  910. agentData.lastname = m_lastName;
  911. agentData.CapsPath = m_scene.GetCapsPath(m_agentId);
  912. return agentData;
  913. }
  914. public void CrossRegion(ulong newRegionHandle, LLVector3 pos, LLVector3 lookAt, IPEndPoint externalIPEndPoint,
  915. string capsURL)
  916. {
  917. LLVector3 look = new LLVector3(lookAt.X * 10, lookAt.Y * 10, lookAt.Z * 10);
  918. //CrossedRegionPacket newSimPack = (CrossedRegionPacket)PacketPool.Instance.GetPacket(PacketType.CrossedRegion);
  919. CrossedRegionPacket newSimPack = new CrossedRegionPacket();
  920. // TODO: don't create new blocks if recycling an old packet
  921. newSimPack.AgentData = new CrossedRegionPacket.AgentDataBlock();
  922. newSimPack.AgentData.AgentID = AgentId;
  923. newSimPack.AgentData.SessionID = m_sessionId;
  924. newSimPack.Info = new CrossedRegionPacket.InfoBlock();
  925. newSimPack.Info.Position = pos;
  926. newSimPack.Info.LookAt = look;
  927. newSimPack.RegionData = new CrossedRegionPacket.RegionDataBlock();
  928. newSimPack.RegionData.RegionHandle = newRegionHandle;
  929. byte[] byteIP = externalIPEndPoint.Address.GetAddressBytes();
  930. newSimPack.RegionData.SimIP = (uint)byteIP[3] << 24;
  931. newSimPack.RegionData.SimIP += (uint)byteIP[2] << 16;
  932. newSimPack.RegionData.SimIP += (uint)byteIP[1] << 8;
  933. newSimPack.RegionData.SimIP += (uint)byteIP[0];
  934. newSimPack.RegionData.SimPort = (ushort)externalIPEndPoint.Port;
  935. newSimPack.RegionData.SeedCapability = Helpers.StringToField(capsURL);
  936. // Hack to get this out immediately and skip throttles
  937. OutPacket(newSimPack, ThrottleOutPacketType.Unknown);
  938. }
  939. public void SendMapBlock(List<MapBlockData> mapBlocks)
  940. {
  941. MapBlockReplyPacket mapReply = (MapBlockReplyPacket)PacketPool.Instance.GetPacket(PacketType.MapBlockReply);
  942. // TODO: don't create new blocks if recycling an old packet
  943. mapReply.AgentData.AgentID = AgentId;
  944. mapReply.Data = new MapBlockReplyPacket.DataBlock[mapBlocks.Count];
  945. mapReply.AgentData.Flags = 0;
  946. for (int i = 0; i < mapBlocks.Count; i++)
  947. {
  948. mapReply.Data[i] = new MapBlockReplyPacket.DataBlock();
  949. mapReply.Data[i].MapImageID = mapBlocks[i].MapImageId;
  950. mapReply.Data[i].X = mapBlocks[i].X;
  951. mapReply.Data[i].Y = mapBlocks[i].Y;
  952. mapReply.Data[i].WaterHeight = mapBlocks[i].WaterHeight;
  953. mapReply.Data[i].Name = Helpers.StringToField(mapBlocks[i].Name);
  954. mapReply.Data[i].RegionFlags = mapBlocks[i].RegionFlags;
  955. mapReply.Data[i].Access = mapBlocks[i].Access;
  956. mapReply.Data[i].Agents = mapBlocks[i].Agents;
  957. }
  958. OutPacket(mapReply, ThrottleOutPacketType.Land);
  959. }
  960. public void SendLocalTeleport(LLVector3 position, LLVector3 lookAt, uint flags)
  961. {
  962. TeleportLocalPacket tpLocal = (TeleportLocalPacket)PacketPool.Instance.GetPacket(PacketType.TeleportLocal);
  963. tpLocal.Info.AgentID = AgentId;
  964. tpLocal.Info.TeleportFlags = flags;
  965. tpLocal.Info.LocationID = 2;
  966. tpLocal.Info.LookAt = lookAt;
  967. tpLocal.Info.Position = position;
  968. // Hack to get this out immediately and skip throttles
  969. OutPacket(tpLocal, ThrottleOutPacketType.Unknown);
  970. }
  971. public void SendRegionTeleport(ulong regionHandle, byte simAccess, IPEndPoint newRegionEndPoint, uint locationID,
  972. uint flags, string capsURL)
  973. {
  974. //TeleportFinishPacket teleport = (TeleportFinishPacket)PacketPool.Instance.GetPacket(PacketType.TeleportFinish);
  975. TeleportFinishPacket teleport = new TeleportFinishPacket();
  976. teleport.Info.AgentID = AgentId;
  977. teleport.Info.RegionHandle = regionHandle;
  978. teleport.Info.SimAccess = simAccess;
  979. teleport.Info.SeedCapability = Helpers.StringToField(capsURL);
  980. IPAddress oIP = newRegionEndPoint.Address;
  981. byte[] byteIP = oIP.GetAddressBytes();
  982. uint ip = (uint)byteIP[3] << 24;
  983. ip += (uint)byteIP[2] << 16;
  984. ip += (uint)byteIP[1] << 8;
  985. ip += (uint)byteIP[0];
  986. teleport.Info.SimIP = ip;
  987. teleport.Info.SimPort = (ushort)newRegionEndPoint.Port;
  988. teleport.Info.LocationID = 4;
  989. teleport.Info.TeleportFlags = 1 << 4;
  990. // Hack to get this out immediately and skip throttles.
  991. OutPacket(teleport, ThrottleOutPacketType.Unknown);
  992. }
  993. /// <summary>
  994. ///
  995. /// </summary>
  996. public void SendTeleportFailed(string reason)
  997. {
  998. TeleportFailedPacket tpFailed = (TeleportFailedPacket)PacketPool.Instance.GetPacket(PacketType.TeleportFailed);
  999. tpFailed.Info.AgentID = AgentId;
  1000. tpFailed.Info.Reason = Helpers.StringToField(reason);
  1001. // Hack to get this out immediately and skip throttles
  1002. OutPacket(tpFailed, ThrottleOutPacketType.Unknown);
  1003. }
  1004. /// <summary>
  1005. ///
  1006. /// </summary>
  1007. public void SendTeleportLocationStart()
  1008. {
  1009. //TeleportStartPacket tpStart = (TeleportStartPacket)PacketPool.Instance.GetPacket(PacketType.TeleportStart);
  1010. TeleportStartPacket tpStart = new TeleportStartPacket();
  1011. tpStart.Info.TeleportFlags = 16; // Teleport via location
  1012. // Hack to get this out immediately and skip throttles
  1013. OutPacket(tpStart, ThrottleOutPacketType.Unknown);
  1014. }
  1015. public void SendMoneyBalance(LLUUID transaction, bool success, byte[] description, int balance)
  1016. {
  1017. MoneyBalanceReplyPacket money = (MoneyBalanceReplyPacket)PacketPool.Instance.GetPacket(PacketType.MoneyBalanceReply);
  1018. money.MoneyData.AgentID = AgentId;
  1019. money.MoneyData.TransactionID = transaction;
  1020. money.MoneyData.TransactionSuccess = success;
  1021. money.MoneyData.Description = description;
  1022. money.MoneyData.MoneyBalance = balance;
  1023. OutPacket(money, ThrottleOutPacketType.Task);
  1024. }
  1025. public void SendPayPrice(LLUUID objectID, int[] payPrice)
  1026. {
  1027. if(payPrice[0] == 0 &&
  1028. payPrice[1] == 0 &&
  1029. payPrice[2] == 0 &&
  1030. payPrice[3] == 0 &&
  1031. payPrice[4] == 0)
  1032. return;
  1033. PayPriceReplyPacket payPriceReply = (PayPriceReplyPacket)PacketPool.Instance.GetPacket(PacketType.PayPriceReply);
  1034. payPriceReply.ObjectData.ObjectID = objectID;
  1035. payPriceReply.ObjectData.DefaultPayPrice = payPrice[0];
  1036. payPriceReply.ButtonData=new PayPriceReplyPacket.ButtonDataBlock[4];
  1037. payPriceReply.ButtonData[0]=new PayPriceReplyPacket.ButtonDataBlock();
  1038. payPriceReply.ButtonData[0].PayButton = payPrice[1];
  1039. payPriceReply.ButtonData[1]=new PayPriceReplyPacket.ButtonDataBlock();
  1040. payPriceReply.ButtonData[1].PayButton = payPrice[2];
  1041. payPriceReply.ButtonData[2]=new PayPriceReplyPacket.ButtonDataBlock();
  1042. payPriceReply.ButtonData[2].PayButton = payPrice[3];
  1043. payPriceReply.ButtonData[3]=new PayPriceReplyPacket.ButtonDataBlock();
  1044. payPriceReply.ButtonData[3].PayButton = payPrice[4];
  1045. OutPacket(payPriceReply, ThrottleOutPacketType.Task);
  1046. }
  1047. public void SendStartPingCheck(byte seq)
  1048. {
  1049. StartPingCheckPacket pc = (StartPingCheckPacket)PacketPool.Instance.GetPacket(PacketType.StartPingCheck);
  1050. pc.PingID.PingID = seq;
  1051. pc.Header.Reliable = false;
  1052. OutPacket(pc, ThrottleOutPacketType.Unknown);
  1053. }
  1054. public void SendKillObject(ulong regionHandle, uint localID)
  1055. {
  1056. KillObjectPacket kill = (KillObjectPacket)PacketPool.Instance.GetPacket(PacketType.KillObject);
  1057. // TODO: don't create new blocks if recycling an old packet
  1058. kill.ObjectData = new KillObjectPacket.ObjectDataBlock[1];
  1059. kill.ObjectData[0] = new KillObjectPacket.ObjectDataBlock();
  1060. kill.ObjectData[0].ID = localID;
  1061. kill.Header.Reliable = false;
  1062. OutPacket(kill, ThrottleOutPacketType.Task);
  1063. }
  1064. /// <summary>
  1065. /// Send information about the items contained in a folder to the client.
  1066. ///
  1067. /// XXX This method needs some refactoring loving
  1068. /// </summary>
  1069. /// <param name="ownerID">The owner of the folder</param>
  1070. /// <param name="folderID">The id of the folder</param>
  1071. /// <param name="items">The items contained in the folder identified by folderID</param>
  1072. /// <param name="fetchFolders">Do we need to send folder information?</param>
  1073. /// <param name="fetchItems">Do we need to send item information?</param>
  1074. public void SendInventoryFolderDetails(LLUUID ownerID, LLUUID folderID, List<InventoryItemBase> items,
  1075. List<InventoryFolderBase> folders,
  1076. bool fetchFolders, bool fetchItems)
  1077. {
  1078. // An inventory descendents packet consists of a single agent section and an inventory details
  1079. // section for each inventory item. The size of each inventory item is approximately 550 bytes.
  1080. // In theory, UDP has a maximum packet size of 64k, so it should be possible to send descendent
  1081. // packets containing metadata for in excess of 100 items. But in practice, there may be other
  1082. // factors (e.g. firewalls) restraining the maximum UDP packet size. See,
  1083. //
  1084. // http://opensimulator.org/mantis/view.php?id=226
  1085. //
  1086. // for one example of this kind of thing. In fact, the Linden servers appear to only send about
  1087. // 6 to 7 items at a time, so let's stick with 6
  1088. int MAX_ITEMS_PER_PACKET = 6;
  1089. //Ckrinke This variable is not used, so comment out to remove the warning from the compiler (3-21-08)
  1090. //Ckrinke uint FULL_MASK_PERMISSIONS = 2147483647;
  1091. if (fetchItems)
  1092. {
  1093. InventoryDescendentsPacket descend = CreateInventoryDescendentsPacket(ownerID, folderID);
  1094. if (items.Count < MAX_ITEMS_PER_PACKET)
  1095. {
  1096. descend.ItemData = new InventoryDescendentsPacket.ItemDataBlock[items.Count];
  1097. descend.AgentData.Descendents = items.Count;
  1098. }
  1099. else
  1100. {
  1101. descend.ItemData = new InventoryDescendentsPacket.ItemDataBlock[MAX_ITEMS_PER_PACKET];
  1102. descend.AgentData.Descendents = MAX_ITEMS_PER_PACKET;
  1103. }
  1104. // Even if we aren't fetching the folders, we still need to include the folder count
  1105. // in the total number of descendents. Failure to do so will cause subtle bugs such
  1106. // as the failure of textures which haven't been expanded in inventory to show up
  1107. // in the texture prim edit selection panel.
  1108. if (!fetchFolders)
  1109. {
  1110. descend.AgentData.Descendents += folders.Count;
  1111. }
  1112. int count = 0;
  1113. int i = 0;
  1114. foreach (InventoryItemBase item in items)
  1115. {
  1116. descend.ItemData[i] = new InventoryDescendentsPacket.ItemDataBlock();
  1117. descend.ItemData[i].ItemID = item.ID;
  1118. descend.ItemData[i].AssetID = item.AssetID;
  1119. descend.ItemData[i].CreatorID = item.Creator;
  1120. descend.ItemData[i].BaseMask = item.BasePermissions;
  1121. descend.ItemData[i].Description = Helpers.StringToField(item.Description);
  1122. descend.ItemData[i].EveryoneMask = item.EveryOnePermissions;
  1123. descend.ItemData[i].OwnerMask = item.CurrentPermissions;
  1124. descend.ItemData[i].FolderID = item.Folder;
  1125. descend.ItemData[i].InvType = (sbyte)item.InvType;
  1126. descend.ItemData[i].Name = Helpers.StringToField(item.Name);
  1127. descend.ItemData[i].NextOwnerMask = item.NextPermissions;
  1128. descend.ItemData[i].OwnerID = item.Owner;
  1129. descend.ItemData[i].Type = (sbyte)item.AssetType;
  1130. //descend.ItemData[i].GroupID = new LLUUID("00000000-0000-0000-0000-000000000000");
  1131. descend.ItemData[i].GroupID = item.GroupID;
  1132. descend.ItemData[i].GroupOwned = item.GroupOwned;
  1133. descend.ItemData[i].GroupMask = 0;
  1134. descend.ItemData[i].CreationDate = item.CreationDate;
  1135. descend.ItemData[i].SalePrice = item.SalePrice;
  1136. descend.ItemData[i].SaleType = item.SaleType;
  1137. descend.ItemData[i].Flags = item.Flags;
  1138. descend.ItemData[i].CRC =
  1139. Helpers.InventoryCRC(descend.ItemData[i].CreationDate, descend.ItemData[i].SaleType,
  1140. descend.ItemData[i].InvType, descend.ItemData[i].Type,
  1141. descend.ItemData[i].AssetID, descend.ItemData[i].GroupID,
  1142. descend.ItemData[i].SalePrice,
  1143. descend.ItemData[i].OwnerID, descend.ItemData[i].CreatorID,
  1144. descend.ItemData[i].ItemID, descend.ItemData[i].FolderID,
  1145. descend.ItemData[i].EveryoneMask,
  1146. descend.ItemData[i].Flags, descend.ItemData[i].OwnerMask,
  1147. descend.ItemData[i].GroupMask, item.CurrentPermissions);
  1148. i++;
  1149. count++;
  1150. if (i == MAX_ITEMS_PER_PACKET)
  1151. {
  1152. OutPacket(descend, ThrottleOutPacketType.Asset);
  1153. if ((items.Count - count) > 0)
  1154. {
  1155. descend = CreateInventoryDescendentsPacket(ownerID, folderID);
  1156. if ((items.Count - count) < MAX_ITEMS_PER_PACKET)
  1157. {
  1158. descend.ItemData = new InventoryDescendentsPacket.ItemDataBlock[items.Count - count];
  1159. descend.AgentData.Descendents = items.Count - count;
  1160. }
  1161. else
  1162. {
  1163. descend.ItemData = new InventoryDescendentsPacket.ItemDataBlock[MAX_ITEMS_PER_PACKET];
  1164. descend.AgentData.Descendents = MAX_ITEMS_PER_PACKET;
  1165. }
  1166. i = 0;
  1167. }
  1168. }
  1169. }
  1170. if (i < MAX_ITEMS_PER_PACKET)
  1171. {
  1172. OutPacket(descend, ThrottleOutPacketType.Asset);
  1173. }
  1174. }
  1175. //send subfolders
  1176. if (fetchFolders)
  1177. {
  1178. InventoryDescendentsPacket descend = CreateInventoryDescendentsPacket(ownerID, folderID);
  1179. if (folders.Count < MAX_ITEMS_PER_PACKET)
  1180. {
  1181. descend.FolderData = new InventoryDescendentsPacket.FolderDataBlock[folders.Count];
  1182. descend.AgentData.Descendents = folders.Count;
  1183. }
  1184. else
  1185. {
  1186. descend.FolderData = new InventoryDescendentsPacket.FolderDataBlock[MAX_ITEMS_PER_PACKET];
  1187. descend.AgentData.Descendents = MAX_ITEMS_PER_PACKET;
  1188. }
  1189. // Not sure if this scenario ever actually occurs, but nonetheless we include the items
  1190. // count even if we're not sending item data for the same reasons as above.
  1191. if (!fetchItems)
  1192. {
  1193. descend.AgentData.Descendents += items.Count;
  1194. }
  1195. int i = 0;
  1196. int count = 0;
  1197. foreach (InventoryFolderBase folder in folders)
  1198. {
  1199. descend.FolderData[i] = new InventoryDescendentsPacket.FolderDataBlock();
  1200. descend.FolderData[i].FolderID = folder.ID;
  1201. descend.FolderData[i].Name = Helpers.StringToField(folder.Name);
  1202. descend.FolderData[i].ParentID = folder.ParentID;
  1203. descend.FolderData[i].Type = (sbyte) folder.Type;
  1204. i++;
  1205. count++;
  1206. if (i == MAX_ITEMS_PER_PACKET)
  1207. {
  1208. OutPacket(descend, ThrottleOutPacketType.Asset);
  1209. if ((folders.Count - count) > 0)
  1210. {
  1211. descend = CreateInventoryDescendentsPacket(ownerID, folderID);
  1212. if ((folders.Count - count) < MAX_ITEMS_PER_PACKET)
  1213. {
  1214. descend.FolderData =
  1215. new InventoryDescendentsPacket.FolderDataBlock[folders.Count - count];
  1216. descend.AgentData.Descendents = folders.Count - count;
  1217. }
  1218. else
  1219. {
  1220. descend.FolderData =
  1221. new InventoryDescendentsPacket.FolderDataBlock[MAX_ITEMS_PER_PACKET];
  1222. descend.AgentData.Descendents = MAX_ITEMS_PER_PACKET;
  1223. }
  1224. i = 0;
  1225. }
  1226. }
  1227. }
  1228. if (i < MAX_ITEMS_PER_PACKET)
  1229. {
  1230. OutPacket(descend, ThrottleOutPacketType.Asset);
  1231. }
  1232. }
  1233. }
  1234. private InventoryDescendentsPacket CreateInventoryDescendentsPacket(LLUUID ownerID, LLUUID folderID)
  1235. {
  1236. InventoryDescendentsPacket descend = (InventoryDescendentsPacket)PacketPool.Instance.GetPacket(PacketType.InventoryDescendents);
  1237. descend.AgentData.AgentID = AgentId;
  1238. descend.AgentData.OwnerID = ownerID;
  1239. descend.AgentData.FolderID = folderID;
  1240. descend.AgentData.Version = 1;
  1241. return descend;
  1242. }
  1243. public void SendInventoryItemDetails(LLUUID ownerID, InventoryItemBase item)
  1244. {
  1245. uint FULL_MASK_PERMISSIONS = (uint)PermissionMask.All;
  1246. FetchInventoryReplyPacket inventoryReply = (FetchInventoryReplyPacket)PacketPool.Instance.GetPacket(PacketType.FetchInventoryReply);
  1247. // TODO: don't create new blocks if recycling an old packet
  1248. inventoryReply.AgentData.AgentID = AgentId;
  1249. inventoryReply.InventoryData = new FetchInventoryReplyPacket.InventoryDataBlock[1];
  1250. inventoryReply.InventoryData[0] = new FetchInventoryReplyPacket.InventoryDataBlock();
  1251. inventoryReply.InventoryData[0].ItemID = item.ID;
  1252. inventoryReply.InventoryData[0].AssetID = item.AssetID;
  1253. inventoryReply.InventoryData[0].CreatorID = item.Creator;
  1254. inventoryReply.InventoryData[0].BaseMask = item.BasePermissions;
  1255. inventoryReply.InventoryData[0].CreationDate =
  1256. (int)(DateTime.UtcNow - new DateTime(1970, 1, 1)).TotalSeconds;
  1257. inventoryReply.InventoryData[0].Description = Helpers.StringToField(item.Description);
  1258. inventoryReply.InventoryData[0].EveryoneMask = item.EveryOnePermissions;
  1259. inventoryReply.InventoryData[0].FolderID = item.Folder;
  1260. inventoryReply.InventoryData[0].InvType = (sbyte)item.InvType;
  1261. inventoryReply.InventoryData[0].Name = Helpers.StringToField(item.Name);
  1262. inventoryReply.InventoryData[0].NextOwnerMask = item.NextPermissions;
  1263. inventoryReply.InventoryData[0].OwnerID = item.Owner;
  1264. inventoryReply.InventoryData[0].OwnerMask = item.CurrentPermissions;
  1265. inventoryReply.InventoryData[0].Type = (sbyte)item.AssetType;
  1266. //inventoryReply.InventoryData[0].GroupID = new LLUUID("00000000-0000-0000-0000-000000000000");
  1267. inventoryReply.InventoryData[0].GroupID = item.GroupID;
  1268. inventoryReply.InventoryData[0].GroupOwned = item.GroupOwned;
  1269. inventoryReply.InventoryData[0].GroupMask = 0;
  1270. inventoryReply.InventoryData[0].Flags = item.Flags;
  1271. inventoryReply.InventoryData[0].SalePrice = item.SalePrice;
  1272. inventoryReply.InventoryData[0].SaleType = item.SaleType;
  1273. inventoryReply.InventoryData[0].CRC =
  1274. Helpers.InventoryCRC(1000, 0, inventoryReply.InventoryData[0].InvType,
  1275. inventoryReply.InventoryData[0].Type, inventoryReply.InventoryData[0].AssetID,
  1276. inventoryReply.InventoryData[0].GroupID, 100,
  1277. inventoryReply.InventoryData[0].OwnerID, inventoryReply.InventoryData[0].CreatorID,
  1278. inventoryReply.InventoryData[0].ItemID, inventoryReply.InventoryData[0].FolderID,
  1279. FULL_MASK_PERMISSIONS, 1, FULL_MASK_PERMISSIONS, FULL_MASK_PERMISSIONS,
  1280. FULL_MASK_PERMISSIONS);
  1281. OutPacket(inventoryReply, ThrottleOutPacketType.Asset);
  1282. }
  1283. /// <see>IClientAPI.SendBulkUpdateInventory(InventoryItemBase)</see>
  1284. public void SendBulkUpdateInventory(InventoryItemBase item)
  1285. {
  1286. uint FULL_MASK_PERMISSIONS = (uint)PermissionMask.All;
  1287. BulkUpdateInventoryPacket bulkUpdate
  1288. = (BulkUpdateInventoryPacket)PacketPool.Instance.GetPacket(PacketType.BulkUpdateInventory);
  1289. bulkUpdate.AgentData.AgentID = AgentId;
  1290. bulkUpdate.AgentData.TransactionID = LLUUID.Random();
  1291. bulkUpdate.FolderData = new BulkUpdateInventoryPacket.FolderDataBlock[1];
  1292. bulkUpdate.FolderData[0] = new BulkUpdateInventoryPacket.FolderDataBlock();
  1293. bulkUpdate.FolderData[0].FolderID = LLUUID.Zero;
  1294. bulkUpdate.FolderData[0].ParentID = LLUUID.Zero;
  1295. bulkUpdate.FolderData[0].Type = -1;
  1296. bulkUpdate.FolderData[0].Name = new byte[0];
  1297. bulkUpdate.ItemData = new BulkUpdateInventoryPacket.ItemDataBlock[1];
  1298. bulkUpdate.ItemData[0] = new BulkUpdateInventoryPacket.ItemDataBlock();
  1299. bulkUpdate.ItemData[0].ItemID = item.ID;
  1300. bulkUpdate.ItemData[0].AssetID = item.AssetID;
  1301. bulkUpdate.ItemData[0].CreatorID = item.Creator;
  1302. bulkUpdate.ItemData[0].BaseMask = item.BasePermissions;
  1303. bulkUpdate.ItemData[0].CreationDate = 1000;
  1304. bulkUpdate.ItemData[0].Description = Helpers.StringToField(item.Description);
  1305. bulkUpdate.ItemData[0].EveryoneMask = item.EveryOnePermissions;
  1306. bulkUpdate.ItemData[0].FolderID = item.Folder;
  1307. bulkUpdate.ItemData[0].InvType = (sbyte)item.InvType;
  1308. bulkUpdate.ItemData[0].Name = Helpers.StringToField(item.Name);
  1309. bulkUpdate.ItemData[0].NextOwnerMask = item.NextPermissions;
  1310. bulkUpdate.ItemData[0].OwnerID = item.Owner;
  1311. bulkUpdate.ItemData[0].OwnerMask = item.CurrentPermissions;
  1312. bulkUpdate.ItemData[0].Type = (sbyte)item.AssetType;
  1313. //bulkUpdate.ItemData[0].GroupID = new LLUUID("00000000-0000-0000-0000-000000000000");
  1314. bulkUpdate.ItemData[0].GroupID = item.GroupID;
  1315. bulkUpdate.ItemData[0].GroupOwned = item.GroupOwned;
  1316. bulkUpdate.ItemData[0].GroupMask = 0;
  1317. bulkUpdate.ItemData[0].Flags = item.Flags;
  1318. bulkUpdate.ItemData[0].SalePrice = item.SalePrice;
  1319. bulkUpdate.ItemData[0].SaleType = item.SaleType;
  1320. bulkUpdate.ItemData[0].CRC =
  1321. Helpers.InventoryCRC(1000, 0, bulkUpdate.ItemData[0].InvType,
  1322. bulkUpdate.ItemData[0].Type, bulkUpdate.ItemData[0].AssetID,
  1323. bulkUpdate.ItemData[0].GroupID, 100,
  1324. bulkUpdate.ItemData[0].OwnerID, bulkUpdate.ItemData[0].CreatorID,
  1325. bulkUpdate.ItemData[0].ItemID, bulkUpdate.ItemData[0].FolderID,
  1326. FULL_MASK_PERMISSIONS, 1, FULL_MASK_PERMISSIONS, FULL_MASK_PERMISSIONS,
  1327. FULL_MASK_PERMISSIONS);
  1328. OutPacket(bulkUpdate, ThrottleOutPacketType.Asset);
  1329. }
  1330. /// <see>IClientAPI.SendInventoryItemCreateUpdate(InventoryItemBase)</see>
  1331. public void SendInventoryItemCreateUpdate(InventoryItemBase Item)
  1332. {
  1333. uint FULL_MASK_PERMISSIONS = (uint)PermissionMask.All;
  1334. UpdateCreateInventoryItemPacket InventoryReply
  1335. = (UpdateCreateInventoryItemPacket)PacketPool.Instance.GetPacket(
  1336. PacketType.UpdateCreateInventoryItem);
  1337. // TODO: don't create new blocks if recycling an old packet
  1338. InventoryReply.AgentData.AgentID = AgentId;
  1339. InventoryReply.AgentData.SimApproved = true;
  1340. InventoryReply.InventoryData = new UpdateCreateInventoryItemPacket.InventoryDataBlock[1];
  1341. InventoryReply.InventoryData[0] = new UpdateCreateInventoryItemPacket.InventoryDataBlock();
  1342. InventoryReply.InventoryData[0].ItemID = Item.ID;
  1343. InventoryReply.InventoryData[0].AssetID = Item.AssetID;
  1344. InventoryReply.InventoryData[0].CreatorID = Item.Creator;
  1345. InventoryReply.InventoryData[0].BaseMask = Item.BasePermissions;
  1346. InventoryReply.InventoryData[0].Description = Helpers.StringToField(Item.Description);
  1347. InventoryReply.InventoryData[0].EveryoneMask = Item.EveryOnePermissions;
  1348. InventoryReply.InventoryData[0].FolderID = Item.Folder;
  1349. InventoryReply.InventoryData[0].InvType = (sbyte)Item.InvType;
  1350. InventoryReply.InventoryData[0].Name = Helpers.StringToField(Item.Name);
  1351. InventoryReply.InventoryData[0].NextOwnerMask = Item.NextPermissions;
  1352. InventoryReply.InventoryData[0].OwnerID = Item.Owner;
  1353. InventoryReply.InventoryData[0].OwnerMask = Item.CurrentPermissions;
  1354. InventoryReply.InventoryData[0].Type = (sbyte)Item.AssetType;
  1355. //InventoryReply.InventoryData[0].GroupID = new LLUUID("00000000-0000-0000-0000-000000000000");
  1356. InventoryReply.InventoryData[0].GroupID = Item.GroupID;
  1357. InventoryReply.InventoryData[0].GroupOwned = Item.GroupOwned;
  1358. InventoryReply.InventoryData[0].GroupMask = 0;
  1359. InventoryReply.InventoryData[0].Flags = Item.Flags;
  1360. InventoryReply.InventoryData[0].SalePrice = Item.SalePrice;
  1361. InventoryReply.InventoryData[0].SaleType = Item.SaleType;
  1362. InventoryReply.InventoryData[0].CRC =
  1363. Helpers.InventoryCRC(1000, 0, InventoryReply.InventoryData[0].InvType,
  1364. InventoryReply.InventoryData[0].Type, InventoryReply.InventoryData[0].AssetID,
  1365. InventoryReply.InventoryData[0].GroupID, 100,
  1366. InventoryReply.InventoryData[0].OwnerID, InventoryReply.InventoryData[0].CreatorID,
  1367. InventoryReply.InventoryData[0].ItemID, InventoryReply.InventoryData[0].FolderID,
  1368. FULL_MASK_PERMISSIONS, 1, FULL_MASK_PERMISSIONS, FULL_MASK_PERMISSIONS,
  1369. FULL_MASK_PERMISSIONS);
  1370. OutPacket(InventoryReply, ThrottleOutPacketType.Asset);
  1371. }
  1372. public void SendRemoveInventoryItem(LLUUID itemID)
  1373. {
  1374. RemoveInventoryItemPacket remove = (RemoveInventoryItemPacket)PacketPool.Instance.GetPacket(PacketType.RemoveInventoryItem);
  1375. // TODO: don't create new blocks if recycling an old packet
  1376. remove.AgentData.AgentID = AgentId;
  1377. remove.AgentData.SessionID = m_sessionId;
  1378. remove.InventoryData = new RemoveInventoryItemPacket.InventoryDataBlock[1];
  1379. remove.InventoryData[0] = new RemoveInventoryItemPacket.InventoryDataBlock();
  1380. remove.InventoryData[0].ItemID = itemID;
  1381. OutPacket(remove, ThrottleOutPacketType.Asset);
  1382. }
  1383. public void SendTaskInventory(LLUUID taskID, short serial, byte[] fileName)
  1384. {
  1385. ReplyTaskInventoryPacket replytask = (ReplyTaskInventoryPacket)PacketPool.Instance.GetPacket(PacketType.ReplyTaskInventory);
  1386. replytask.InventoryData.TaskID = taskID;
  1387. replytask.InventoryData.Serial = serial;
  1388. replytask.InventoryData.Filename = fileName;
  1389. OutPacket(replytask, ThrottleOutPacketType.Asset);
  1390. }
  1391. public void SendXferPacket(ulong xferID, uint packet, byte[] data)
  1392. {
  1393. SendXferPacketPacket sendXfer = (SendXferPacketPacket)PacketPool.Instance.GetPacket(PacketType.SendXferPacket);
  1394. sendXfer.XferID.ID = xferID;
  1395. sendXfer.XferID.Packet = packet;
  1396. sendXfer.DataPacket.Data = data;
  1397. OutPacket(sendXfer, ThrottleOutPacketType.Task);
  1398. }
  1399. public void SendEconomyData(float EnergyEfficiency, int ObjectCapacity, int ObjectCount, int PriceEnergyUnit,
  1400. int PriceGroupCreate, int PriceObjectClaim, float PriceObjectRent, float PriceObjectScaleFactor,
  1401. int PriceParcelClaim, float PriceParcelClaimFactor, int PriceParcelRent, int PricePublicObjectDecay,
  1402. int PricePublicObjectDelete, int PriceRentLight, int PriceUpload, int TeleportMinPrice, float TeleportPriceExponent)
  1403. {
  1404. EconomyDataPacket economyData = (EconomyDataPacket)PacketPool.Instance.GetPacket(PacketType.EconomyData);
  1405. economyData.Info.EnergyEfficiency = EnergyEfficiency;
  1406. economyData.Info.ObjectCapacity = ObjectCapacity;
  1407. economyData.Info.ObjectCount = ObjectCount;
  1408. economyData.Info.PriceEnergyUnit = PriceEnergyUnit;
  1409. economyData.Info.PriceGroupCreate = PriceGroupCreate;
  1410. economyData.Info.PriceObjectClaim = PriceObjectClaim;
  1411. economyData.Info.PriceObjectRent = PriceObjectRent;
  1412. economyData.Info.PriceObjectScaleFactor = PriceObjectScaleFactor;
  1413. economyData.Info.PriceParcelClaim = PriceParcelClaim;
  1414. economyData.Info.PriceParcelClaimFactor = PriceParcelClaimFactor;
  1415. economyData.Info.PriceParcelRent = PriceParcelRent;
  1416. economyData.Info.PricePublicObjectDecay = PricePublicObjectDecay;
  1417. economyData.Info.PricePublicObjectDelete = PricePublicObjectDelete;
  1418. economyData.Info.PriceRentLight = PriceRentLight;
  1419. economyData.Info.PriceUpload = PriceUpload;
  1420. economyData.Info.TeleportMinPrice = TeleportMinPrice;
  1421. economyData.Info.TeleportPriceExponent = TeleportPriceExponent;
  1422. economyData.Header.Reliable = true;
  1423. OutPacket(economyData, ThrottleOutPacketType.Unknown);
  1424. }
  1425. public void SendAvatarPickerReply(AvatarPickerReplyPacket replyPacket)
  1426. {
  1427. OutPacket(replyPacket, ThrottleOutPacketType.Task);
  1428. }
  1429. public void SendAgentDataUpdate(LLUUID agentid, LLUUID activegroupid, string firstname, string lastname, ulong grouppowers, string groupname, string grouptitle)
  1430. {
  1431. AgentDataUpdatePacket sendAgentDataUpdate = (AgentDataUpdatePacket)PacketPool.Instance.GetPacket(PacketType.AgentDataUpdate);
  1432. sendAgentDataUpdate.AgentData.ActiveGroupID = activegroupid;
  1433. sendAgentDataUpdate.AgentData.AgentID = agentid;
  1434. sendAgentDataUpdate.AgentData.FirstName = Helpers.StringToField(firstname);
  1435. sendAgentDataUpdate.AgentData.GroupName = Helpers.StringToField(groupname);
  1436. sendAgentDataUpdate.AgentData.GroupPowers = grouppowers;
  1437. sendAgentDataUpdate.AgentData.GroupTitle = Helpers.StringToField(grouptitle);
  1438. sendAgentDataUpdate.AgentData.LastName = Helpers.StringToField(lastname);
  1439. OutPacket(sendAgentDataUpdate, ThrottleOutPacketType.Task);
  1440. }
  1441. /// <summary>
  1442. /// Send an alert message to the client. On the Linden client (tested 1.19.1.4), this pops up a brief duration
  1443. /// blue information box in the bottom right hand corner.
  1444. /// </summary>
  1445. /// <param name="message"></param>
  1446. public void SendAlertMessage(string message)
  1447. {
  1448. AlertMessagePacket alertPack = (AlertMessagePacket)PacketPool.Instance.GetPacket(PacketType.AlertMessage);
  1449. alertPack.AlertData.Message = Helpers.StringToField(message);
  1450. OutPacket(alertPack, ThrottleOutPacketType.Task);
  1451. }
  1452. /// <summary>
  1453. /// Send an agent alert message to the client.
  1454. /// </summary>
  1455. /// <param name="message"></param>
  1456. /// <param name="modal">On the linden client, if this true then it displays a one button text box placed in the
  1457. /// middle of the window. If false, the message is displayed in a brief duration blue information box (as for
  1458. /// the AlertMessage packet).</param>
  1459. public void SendAgentAlertMessage(string message, bool modal)
  1460. {
  1461. AgentAlertMessagePacket alertPack = (AgentAlertMessagePacket)PacketPool.Instance.GetPacket(PacketType.AgentAlertMessage);
  1462. alertPack.AgentData.AgentID = AgentId;
  1463. alertPack.AlertData.Message = Helpers.StringToField(message);
  1464. alertPack.AlertData.Modal = modal;
  1465. OutPacket(alertPack, ThrottleOutPacketType.Task);
  1466. }
  1467. public void SendLoadURL(string objectname, LLUUID objectID, LLUUID ownerID, bool groupOwned, string message,
  1468. string url)
  1469. {
  1470. LoadURLPacket loadURL = (LoadURLPacket)PacketPool.Instance.GetPacket(PacketType.LoadURL);
  1471. loadURL.Data.ObjectName = Helpers.StringToField(objectname);
  1472. loadURL.Data.ObjectID = objectID;
  1473. loadURL.Data.OwnerID = ownerID;
  1474. loadURL.Data.OwnerIsGroup = groupOwned;
  1475. loadURL.Data.Message = Helpers.StringToField(message);
  1476. loadURL.Data.URL = Helpers.StringToField(url);
  1477. OutPacket(loadURL, ThrottleOutPacketType.Task);
  1478. }
  1479. public void SendDialog(string objectname, LLUUID objectID, LLUUID ownerID, string msg, LLUUID textureID, int ch, string[] buttonlabels)
  1480. {
  1481. ScriptDialogPacket dialog = (ScriptDialogPacket)PacketPool.Instance.GetPacket(PacketType.ScriptDialog);
  1482. dialog.Data.ObjectID = objectID;
  1483. dialog.Data.ObjectName = Helpers.StringToField(objectname);
  1484. dialog.Data.FirstName = Helpers.StringToField(this.FirstName);
  1485. dialog.Data.LastName = Helpers.StringToField(this.LastName);
  1486. dialog.Data.Message = Helpers.StringToField(msg);
  1487. dialog.Data.ImageID = textureID;
  1488. dialog.Data.ChatChannel = ch;
  1489. ScriptDialogPacket.ButtonsBlock[] buttons = new ScriptDialogPacket.ButtonsBlock[buttonlabels.Length];
  1490. for (int i = 0; i < buttonlabels.Length; i++)
  1491. {
  1492. buttons[i] = new ScriptDialogPacket.ButtonsBlock();
  1493. buttons[i].ButtonLabel = Helpers.StringToField(buttonlabels[i]);
  1494. }
  1495. dialog.Buttons = buttons;
  1496. OutPacket(dialog, ThrottleOutPacketType.Task);
  1497. }
  1498. public void SendPreLoadSound(LLUUID objectID, LLUUID ownerID, LLUUID soundID)
  1499. {
  1500. PreloadSoundPacket preSound = (PreloadSoundPacket)PacketPool.Instance.GetPacket(PacketType.PreloadSound);
  1501. // TODO: don't create new blocks if recycling an old packet
  1502. preSound.DataBlock = new PreloadSoundPacket.DataBlockBlock[1];
  1503. preSound.DataBlock[0] = new PreloadSoundPacket.DataBlockBlock();
  1504. preSound.DataBlock[0].ObjectID = objectID;
  1505. preSound.DataBlock[0].OwnerID = ownerID;
  1506. preSound.DataBlock[0].SoundID = soundID;
  1507. OutPacket(preSound, ThrottleOutPacketType.Task);
  1508. }
  1509. public void SendPlayAttachedSound(LLUUID soundID, LLUUID objectID, LLUUID ownerID, float gain, byte flags)
  1510. {
  1511. AttachedSoundPacket sound = (AttachedSoundPacket)PacketPool.Instance.GetPacket(PacketType.AttachedSound);
  1512. sound.DataBlock.SoundID = soundID;
  1513. sound.DataBlock.ObjectID = objectID;
  1514. sound.DataBlock.OwnerID = ownerID;
  1515. sound.DataBlock.Gain = gain;
  1516. sound.DataBlock.Flags = flags;
  1517. OutPacket(sound, ThrottleOutPacketType.Task);
  1518. }
  1519. public void SendTriggeredSound(LLUUID soundID, LLUUID ownerID, LLUUID objectID, LLUUID parentID, ulong handle, LLVector3 position, float gain)
  1520. {
  1521. SoundTriggerPacket sound = (SoundTriggerPacket)PacketPool.Instance.GetPacket(PacketType.SoundTrigger);
  1522. sound.SoundData.SoundID = soundID;
  1523. sound.SoundData.OwnerID = ownerID;
  1524. sound.SoundData.ObjectID = objectID;
  1525. sound.SoundData.ParentID = parentID;
  1526. sound.SoundData.Handle = handle;
  1527. sound.SoundData.Position = position;
  1528. sound.SoundData.Gain = gain;
  1529. OutPacket(sound, ThrottleOutPacketType.Task);
  1530. }
  1531. public void SendAttachedSoundGainChange(LLUUID objectID, float gain)
  1532. {
  1533. AttachedSoundGainChangePacket sound = (AttachedSoundGainChangePacket)PacketPool.Instance.GetPacket(PacketType.AttachedSoundGainChange);
  1534. sound.DataBlock.ObjectID = objectID;
  1535. sound.DataBlock.Gain = gain;
  1536. OutPacket(sound, ThrottleOutPacketType.Task);
  1537. }
  1538. public void SendSunPos(LLVector3 sunPos, LLVector3 sunVel)
  1539. {
  1540. SimulatorViewerTimeMessagePacket viewertime = (SimulatorViewerTimeMessagePacket)PacketPool.Instance.GetPacket(PacketType.SimulatorViewerTimeMessage);
  1541. viewertime.TimeInfo.SunDirection = sunPos;
  1542. viewertime.TimeInfo.SunAngVelocity = sunVel;
  1543. viewertime.TimeInfo.UsecSinceStart = (ulong)Util.UnixTimeSinceEpoch();
  1544. viewertime.Header.Reliable = false;
  1545. OutPacket(viewertime, ThrottleOutPacketType.Task);
  1546. }
  1547. public void SendViewerTime(int phase)
  1548. {
  1549. Console.WriteLine("SunPhase: {0}", phase);
  1550. SimulatorViewerTimeMessagePacket viewertime = (SimulatorViewerTimeMessagePacket)PacketPool.Instance.GetPacket(PacketType.SimulatorViewerTimeMessage);
  1551. //viewertime.TimeInfo.SecPerDay = 86400;
  1552. //viewertime.TimeInfo.SecPerYear = 31536000;
  1553. viewertime.TimeInfo.SecPerDay = 1000;
  1554. viewertime.TimeInfo.SecPerYear = 365000;
  1555. viewertime.TimeInfo.SunPhase = 1;
  1556. int sunPhase = (phase + 2) / 2;
  1557. if ((sunPhase < 6) || (sunPhase > 36))
  1558. {
  1559. viewertime.TimeInfo.SunDirection = new LLVector3(0f, 0.8f, -0.8f);
  1560. Console.WriteLine("sending night");
  1561. }
  1562. else
  1563. {
  1564. if (sunPhase < 12)
  1565. {
  1566. sunPhase = 12;
  1567. }
  1568. sunPhase = sunPhase - 12;
  1569. float yValue = 0.1f * (sunPhase);
  1570. Console.WriteLine("Computed SunPhase: {0}, yValue: {1}", sunPhase, yValue);
  1571. if (yValue > 1.2f)
  1572. {
  1573. yValue = yValue - 1.2f;
  1574. }
  1575. yValue = Util.Clip(yValue, 0, 1);
  1576. if (sunPhase < 14)
  1577. {
  1578. yValue = 1 - yValue;
  1579. }
  1580. if (sunPhase < 12)
  1581. {
  1582. yValue *= -1;
  1583. }
  1584. viewertime.TimeInfo.SunDirection = new LLVector3(0f, yValue, 0.3f);
  1585. Console.WriteLine("sending sun update " + yValue);
  1586. }
  1587. viewertime.TimeInfo.SunAngVelocity = new LLVector3(0, 0.0f, 10.0f);
  1588. viewertime.TimeInfo.UsecSinceStart = (ulong)Util.UnixTimeSinceEpoch();
  1589. viewertime.Header.Reliable = false;
  1590. OutPacket(viewertime, ThrottleOutPacketType.Task);
  1591. }
  1592. public void SendAvatarProperties(LLUUID avatarID, string aboutText, string bornOn, string charterMember,
  1593. string flAbout, uint flags, LLUUID flImageID, LLUUID imageID, string profileURL,
  1594. LLUUID partnerID)
  1595. {
  1596. AvatarPropertiesReplyPacket avatarReply = (AvatarPropertiesReplyPacket)PacketPool.Instance.GetPacket(PacketType.AvatarPropertiesReply);
  1597. avatarReply.AgentData.AgentID = AgentId;
  1598. avatarReply.AgentData.AvatarID = avatarID;
  1599. if (aboutText != null)
  1600. avatarReply.PropertiesData.AboutText = Helpers.StringToField(aboutText);
  1601. else
  1602. avatarReply.PropertiesData.AboutText = Helpers.StringToField("");
  1603. avatarReply.PropertiesData.BornOn = Helpers.StringToField(bornOn);
  1604. avatarReply.PropertiesData.CharterMember = Helpers.StringToField(charterMember);
  1605. if (flAbout != null)
  1606. avatarReply.PropertiesData.FLAboutText = Helpers.StringToField(flAbout);
  1607. else
  1608. avatarReply.PropertiesData.FLAboutText = Helpers.StringToField("");
  1609. avatarReply.PropertiesData.Flags = 0;
  1610. avatarReply.PropertiesData.FLImageID = flImageID;
  1611. avatarReply.PropertiesData.ImageID = imageID;
  1612. avatarReply.PropertiesData.ProfileURL = Helpers.StringToField(profileURL);
  1613. avatarReply.PropertiesData.PartnerID = partnerID;
  1614. OutPacket(avatarReply, ThrottleOutPacketType.Task);
  1615. }
  1616. #endregion
  1617. #region Appearance/ Wearables Methods
  1618. /// <summary>
  1619. ///
  1620. /// </summary>
  1621. /// <param name="wearables"></param>
  1622. public void SendWearables(AvatarWearable[] wearables, int serial)
  1623. {
  1624. AgentWearablesUpdatePacket aw = (AgentWearablesUpdatePacket)PacketPool.Instance.GetPacket(PacketType.AgentWearablesUpdate);
  1625. aw.AgentData.AgentID = AgentId;
  1626. aw.AgentData.SerialNum = (uint)serial;
  1627. aw.AgentData.SessionID = m_sessionId;
  1628. // TODO: don't create new blocks if recycling an old packet
  1629. aw.WearableData = new AgentWearablesUpdatePacket.WearableDataBlock[13];
  1630. AgentWearablesUpdatePacket.WearableDataBlock awb;
  1631. for (int i = 0; i < wearables.Length; i++)
  1632. {
  1633. awb = new AgentWearablesUpdatePacket.WearableDataBlock();
  1634. awb.WearableType = (byte)i;
  1635. awb.AssetID = wearables[i].AssetID;
  1636. awb.ItemID = wearables[i].ItemID;
  1637. aw.WearableData[i] = awb;
  1638. }
  1639. OutPacket(aw, ThrottleOutPacketType.Task);
  1640. }
  1641. /// <summary>
  1642. ///
  1643. /// </summary>
  1644. /// <param name="agentID"></param>
  1645. /// <param name="visualParams"></param>
  1646. /// <param name="textureEntry"></param>
  1647. public void SendAppearance(LLUUID agentID, byte[] visualParams, byte[] textureEntry)
  1648. {
  1649. AvatarAppearancePacket avp = (AvatarAppearancePacket)PacketPool.Instance.GetPacket(PacketType.AvatarAppearance);
  1650. // TODO: don't create new blocks if recycling an old packet
  1651. avp.VisualParam = new AvatarAppearancePacket.VisualParamBlock[218];
  1652. avp.ObjectData.TextureEntry = textureEntry;
  1653. AvatarAppearancePacket.VisualParamBlock avblock = null;
  1654. for (int i = 0; i < visualParams.Length; i++)
  1655. {
  1656. avblock = new AvatarAppearancePacket.VisualParamBlock();
  1657. avblock.ParamValue = visualParams[i];
  1658. avp.VisualParam[i] = avblock;
  1659. }
  1660. avp.Sender.IsTrial = false;
  1661. avp.Sender.ID = agentID;
  1662. OutPacket(avp, ThrottleOutPacketType.Task);
  1663. }
  1664. public void SendAnimations(LLUUID[] animations, int[] seqs, LLUUID sourceAgentId)
  1665. {
  1666. AvatarAnimationPacket ani = (AvatarAnimationPacket)PacketPool.Instance.GetPacket(PacketType.AvatarAnimation);
  1667. // TODO: don't create new blocks if recycling an old packet
  1668. ani.AnimationSourceList = new AvatarAnimationPacket.AnimationSourceListBlock[1];
  1669. ani.AnimationSourceList[0] = new AvatarAnimationPacket.AnimationSourceListBlock();
  1670. ani.AnimationSourceList[0].ObjectID = sourceAgentId;
  1671. ani.Sender = new AvatarAnimationPacket.SenderBlock();
  1672. ani.Sender.ID = sourceAgentId;
  1673. ani.AnimationList = new AvatarAnimationPacket.AnimationListBlock[animations.Length];
  1674. for (int i = 0; i < animations.Length; ++i)
  1675. {
  1676. ani.AnimationList[i] = new AvatarAnimationPacket.AnimationListBlock();
  1677. ani.AnimationList[i].AnimID = animations[i];
  1678. ani.AnimationList[i].AnimSequenceID = seqs[i];
  1679. }
  1680. ani.Header.Reliable = false;
  1681. OutPacket(ani, ThrottleOutPacketType.Task);
  1682. }
  1683. #endregion
  1684. #region Avatar Packet/data sending Methods
  1685. /// <summary>
  1686. /// send a objectupdate packet with information about the clients avatar
  1687. /// </summary>
  1688. /// <param name="regionInfo"></param>
  1689. /// <param name="firstName"></param>
  1690. /// <param name="lastName"></param>
  1691. /// <param name="avatarID"></param>
  1692. /// <param name="avatarLocalID"></param>
  1693. /// <param name="Pos"></param>
  1694. public void SendAvatarData(ulong regionHandle, string firstName, string lastName, LLUUID avatarID,
  1695. uint avatarLocalID, LLVector3 Pos, byte[] textureEntry, uint parentID)
  1696. {
  1697. ObjectUpdatePacket objupdate = (ObjectUpdatePacket)PacketPool.Instance.GetPacket(PacketType.ObjectUpdate);
  1698. // TODO: don't create new blocks if recycling an old packet
  1699. objupdate.RegionData.RegionHandle = regionHandle;
  1700. objupdate.RegionData.TimeDilation = ushort.MaxValue;
  1701. objupdate.ObjectData = new ObjectUpdatePacket.ObjectDataBlock[1];
  1702. objupdate.ObjectData[0] = CreateDefaultAvatarPacket(textureEntry);
  1703. //give this avatar object a local id and assign the user a name
  1704. objupdate.ObjectData[0].ID = avatarLocalID;
  1705. objupdate.ObjectData[0].FullID = avatarID;
  1706. objupdate.ObjectData[0].ParentID = parentID;
  1707. objupdate.ObjectData[0].NameValue =
  1708. Helpers.StringToField("FirstName STRING RW SV " + firstName + "\nLastName STRING RW SV " + lastName);
  1709. LLVector3 pos2 = new LLVector3((float)Pos.X, (float)Pos.Y, (float)Pos.Z);
  1710. byte[] pb = pos2.GetBytes();
  1711. Array.Copy(pb, 0, objupdate.ObjectData[0].ObjectData, 16, pb.Length);
  1712. OutPacket(objupdate, ThrottleOutPacketType.Task);
  1713. }
  1714. /// <summary>
  1715. ///
  1716. /// </summary>
  1717. /// <param name="regionHandle"></param>
  1718. /// <param name="timeDilation"></param>
  1719. /// <param name="localID"></param>
  1720. /// <param name="position"></param>
  1721. /// <param name="velocity"></param>
  1722. public void SendAvatarTerseUpdate(ulong regionHandle, ushort timeDilation, uint localID, LLVector3 position,
  1723. LLVector3 velocity, LLQuaternion rotation)
  1724. {
  1725. ImprovedTerseObjectUpdatePacket.ObjectDataBlock terseBlock =
  1726. CreateAvatarImprovedBlock(localID, position, velocity, rotation);
  1727. ImprovedTerseObjectUpdatePacket terse = (ImprovedTerseObjectUpdatePacket)PacketPool.Instance.GetPacket(PacketType.ImprovedTerseObjectUpdate);
  1728. // TODO: don't create new blocks if recycling an old packet
  1729. terse.RegionData.RegionHandle = regionHandle;
  1730. terse.RegionData.TimeDilation = timeDilation;
  1731. terse.ObjectData = new ImprovedTerseObjectUpdatePacket.ObjectDataBlock[1];
  1732. terse.ObjectData[0] = terseBlock;
  1733. terse.Header.Reliable = false;
  1734. OutPacket(terse, ThrottleOutPacketType.Task);
  1735. }
  1736. public void SendCoarseLocationUpdate(List<LLVector3> CoarseLocations)
  1737. {
  1738. CoarseLocationUpdatePacket loc = (CoarseLocationUpdatePacket)PacketPool.Instance.GetPacket(PacketType.CoarseLocationUpdate);
  1739. // TODO: don't create new blocks if recycling an old packet
  1740. int total = CoarseLocations.Count;
  1741. CoarseLocationUpdatePacket.IndexBlock ib =
  1742. new CoarseLocationUpdatePacket.IndexBlock();
  1743. loc.Location = new CoarseLocationUpdatePacket.LocationBlock[total];
  1744. for (int i = 0; i < total; i++)
  1745. {
  1746. CoarseLocationUpdatePacket.LocationBlock lb =
  1747. new CoarseLocationUpdatePacket.LocationBlock();
  1748. lb.X = (byte)CoarseLocations[i].X;
  1749. lb.Y = (byte)CoarseLocations[i].Y;
  1750. lb.Z = (byte)(CoarseLocations[i].Z / 4);
  1751. loc.Location[i] = lb;
  1752. }
  1753. ib.You = -1;
  1754. ib.Prey = -1;
  1755. loc.Index = ib;
  1756. loc.Header.Reliable = false;
  1757. OutPacket(loc, ThrottleOutPacketType.Task);
  1758. }
  1759. #endregion
  1760. #region Primitive Packet/data Sending Methods
  1761. /// <summary>
  1762. ///
  1763. /// </summary>
  1764. /// <param name="localID"></param>
  1765. /// <param name="rotation"></param>
  1766. /// <param name="attachPoint"></param>
  1767. public void AttachObject(uint localID, LLQuaternion rotation, byte attachPoint)
  1768. {
  1769. ObjectAttachPacket attach = (ObjectAttachPacket)PacketPool.Instance.GetPacket(PacketType.ObjectAttach);
  1770. Console.WriteLine("Attach object!");
  1771. // TODO: don't create new blocks if recycling an old packet
  1772. attach.AgentData.AgentID = AgentId;
  1773. attach.AgentData.SessionID = m_sessionId;
  1774. attach.AgentData.AttachmentPoint = attachPoint;
  1775. attach.ObjectData = new ObjectAttachPacket.ObjectDataBlock[1];
  1776. attach.ObjectData[0] = new ObjectAttachPacket.ObjectDataBlock();
  1777. attach.ObjectData[0].ObjectLocalID = localID;
  1778. attach.ObjectData[0].Rotation = rotation;
  1779. OutPacket(attach, ThrottleOutPacketType.Task);
  1780. }
  1781. public void SendPrimitiveToClient(
  1782. ulong regionHandle, ushort timeDilation, uint localID, PrimitiveBaseShape primShape, LLVector3 pos,
  1783. uint flags,
  1784. LLUUID objectID, LLUUID ownerID, string text, byte[] color, uint parentID, byte[] particleSystem,
  1785. LLQuaternion rotation, byte clickAction)
  1786. {
  1787. byte[] textureanim = new byte[0];
  1788. SendPrimitiveToClient(regionHandle, timeDilation, localID, primShape, pos, flags,
  1789. objectID, ownerID, text, color, parentID, particleSystem,
  1790. rotation, clickAction, textureanim, false,(uint)0, LLUUID.Zero);
  1791. }
  1792. public void SendPrimitiveToClient(
  1793. ulong regionHandle, ushort timeDilation, uint localID, PrimitiveBaseShape primShape, LLVector3 pos,
  1794. uint flags,
  1795. LLUUID objectID, LLUUID ownerID, string text, byte[] color, uint parentID, byte[] particleSystem,
  1796. LLQuaternion rotation, byte clickAction, byte[] textureanim, bool attachment, uint AttachPoint, LLUUID AssetId)
  1797. {
  1798. ObjectUpdatePacket outPacket = (ObjectUpdatePacket)PacketPool.Instance.GetPacket(PacketType.ObjectUpdate);
  1799. // TODO: don't create new blocks if recycling an old packet
  1800. outPacket.RegionData.RegionHandle = regionHandle;
  1801. outPacket.RegionData.TimeDilation = timeDilation;
  1802. outPacket.ObjectData = new ObjectUpdatePacket.ObjectDataBlock[1];
  1803. outPacket.ObjectData[0] = CreatePrimUpdateBlock(primShape, flags);
  1804. outPacket.ObjectData[0].ID = localID;
  1805. outPacket.ObjectData[0].FullID = objectID;
  1806. outPacket.ObjectData[0].OwnerID = ownerID;
  1807. // Anything more than 255 will cause libsecondlife to barf
  1808. if (text.Length > 255)
  1809. {
  1810. text = text.Remove(255);
  1811. }
  1812. outPacket.ObjectData[0].Text = Helpers.StringToField(text);
  1813. outPacket.ObjectData[0].TextColor[0] = color[0];
  1814. outPacket.ObjectData[0].TextColor[1] = color[1];
  1815. outPacket.ObjectData[0].TextColor[2] = color[2];
  1816. outPacket.ObjectData[0].TextColor[3] = color[3];
  1817. outPacket.ObjectData[0].ParentID = parentID;
  1818. outPacket.ObjectData[0].PSBlock = particleSystem;
  1819. outPacket.ObjectData[0].ClickAction = clickAction;
  1820. //outPacket.ObjectData[0].Flags = 0;
  1821. if (attachment)
  1822. {
  1823. // Necessary???
  1824. outPacket.ObjectData[0].JointAxisOrAnchor = new LLVector3(0, 0, 2);
  1825. outPacket.ObjectData[0].JointPivot = new LLVector3(0, 0, 0);
  1826. // Item from inventory???
  1827. outPacket.ObjectData[0].NameValue =
  1828. Helpers.StringToField("AttachItemID STRING RW SV " + AssetId.UUID);
  1829. outPacket.ObjectData[0].State = (byte)((AttachPoint % 16) * 16 + (AttachPoint / 16));
  1830. }
  1831. // Sound Radius
  1832. outPacket.ObjectData[0].Radius = 20;
  1833. byte[] pb = pos.GetBytes();
  1834. Array.Copy(pb, 0, outPacket.ObjectData[0].ObjectData, 0, pb.Length);
  1835. byte[] rot = rotation.GetBytes();
  1836. Array.Copy(rot, 0, outPacket.ObjectData[0].ObjectData, 36, rot.Length);
  1837. if (textureanim.Length > 0)
  1838. {
  1839. outPacket.ObjectData[0].TextureAnim = textureanim;
  1840. }
  1841. OutPacket(outPacket, ThrottleOutPacketType.Task);
  1842. }
  1843. /// <summary>
  1844. ///
  1845. /// </summary>
  1846. /// <param name="regionHandle"></param>
  1847. /// <param name="timeDilation"></param>
  1848. /// <param name="localID"></param>
  1849. /// <param name="position"></param>
  1850. /// <param name="rotation"></param>
  1851. public void SendPrimTerseUpdate(ulong regionHandle, ushort timeDilation, uint localID, LLVector3 position,
  1852. LLQuaternion rotation, byte state, LLUUID AssetId)
  1853. {
  1854. LLVector3 velocity = new LLVector3(0f, 0f, 0f);
  1855. LLVector3 rotationalvelocity = new LLVector3(0f, 0f, 0f);
  1856. ImprovedTerseObjectUpdatePacket terse = (ImprovedTerseObjectUpdatePacket)PacketPool.Instance.GetPacket(PacketType.ImprovedTerseObjectUpdate);
  1857. // TODO: don't create new blocks if recycling an old packet
  1858. terse.RegionData.RegionHandle = regionHandle;
  1859. terse.RegionData.TimeDilation = timeDilation;
  1860. terse.ObjectData = new ImprovedTerseObjectUpdatePacket.ObjectDataBlock[1];
  1861. terse.ObjectData[0] = CreatePrimImprovedBlock(localID, position, rotation, velocity, rotationalvelocity, state); // AssetID should fall into here probably somehow...
  1862. terse.Header.Reliable = false;
  1863. OutPacket(terse, ThrottleOutPacketType.Task);
  1864. }
  1865. public void SendPrimTerseUpdate(ulong regionHandle, ushort timeDilation, uint localID, LLVector3 position,
  1866. LLQuaternion rotation, LLVector3 velocity, LLVector3 rotationalvelocity)
  1867. {
  1868. ImprovedTerseObjectUpdatePacket terse = (ImprovedTerseObjectUpdatePacket)PacketPool.Instance.GetPacket(PacketType.ImprovedTerseObjectUpdate);
  1869. // TODO: don't create new blocks if recycling an old packet
  1870. terse.RegionData.RegionHandle = regionHandle;
  1871. terse.RegionData.TimeDilation = timeDilation;
  1872. terse.ObjectData = new ImprovedTerseObjectUpdatePacket.ObjectDataBlock[1];
  1873. terse.ObjectData[0] = CreatePrimImprovedBlock(localID, position, rotation, velocity, rotationalvelocity, 0);
  1874. terse.Header.Reliable = false;
  1875. OutPacket(terse, ThrottleOutPacketType.Task);
  1876. }
  1877. #endregion
  1878. #region Helper Methods
  1879. protected ImprovedTerseObjectUpdatePacket.ObjectDataBlock CreateAvatarImprovedBlock(uint localID, LLVector3 pos,
  1880. LLVector3 velocity,
  1881. LLQuaternion rotation)
  1882. {
  1883. byte[] bytes = new byte[60];
  1884. int i = 0;
  1885. ImprovedTerseObjectUpdatePacket.ObjectDataBlock dat = new ImprovedTerseObjectUpdatePacket.ObjectDataBlock();
  1886. dat.TextureEntry = new byte[0]; // AvatarTemplate.TextureEntry;
  1887. uint ID = localID;
  1888. bytes[i++] = (byte)(ID % 256);
  1889. bytes[i++] = (byte)((ID >> 8) % 256);
  1890. bytes[i++] = (byte)((ID >> 16) % 256);
  1891. bytes[i++] = (byte)((ID >> 24) % 256);
  1892. bytes[i++] = 0;
  1893. bytes[i++] = 1;
  1894. i += 14;
  1895. bytes[i++] = 128;
  1896. bytes[i++] = 63;
  1897. byte[] pb = pos.GetBytes();
  1898. Array.Copy(pb, 0, bytes, i, pb.Length);
  1899. i += 12;
  1900. ushort InternVelocityX;
  1901. ushort InternVelocityY;
  1902. ushort InternVelocityZ;
  1903. Vector3 internDirec = new Vector3(0, 0, 0);
  1904. internDirec = new Vector3(velocity.X, velocity.Y, velocity.Z);
  1905. internDirec = internDirec / 128.0f;
  1906. internDirec.x += 1;
  1907. internDirec.y += 1;
  1908. internDirec.z += 1;
  1909. InternVelocityX = (ushort)(32768 * internDirec.x);
  1910. InternVelocityY = (ushort)(32768 * internDirec.y);
  1911. InternVelocityZ = (ushort)(32768 * internDirec.z);
  1912. ushort ac = 32767;
  1913. bytes[i++] = (byte)(InternVelocityX % 256);
  1914. bytes[i++] = (byte)((InternVelocityX >> 8) % 256);
  1915. bytes[i++] = (byte)(InternVelocityY % 256);
  1916. bytes[i++] = (byte)((InternVelocityY >> 8) % 256);
  1917. bytes[i++] = (byte)(InternVelocityZ % 256);
  1918. bytes[i++] = (byte)((InternVelocityZ >> 8) % 256);
  1919. //accel
  1920. bytes[i++] = (byte)(ac % 256);
  1921. bytes[i++] = (byte)((ac >> 8) % 256);
  1922. bytes[i++] = (byte)(ac % 256);
  1923. bytes[i++] = (byte)((ac >> 8) % 256);
  1924. bytes[i++] = (byte)(ac % 256);
  1925. bytes[i++] = (byte)((ac >> 8) % 256);
  1926. //rotation
  1927. ushort rw, rx, ry, rz;
  1928. rw = (ushort)(32768 * (rotation.W + 1));
  1929. rx = (ushort)(32768 * (rotation.X + 1));
  1930. ry = (ushort)(32768 * (rotation.Y + 1));
  1931. rz = (ushort)(32768 * (rotation.Z + 1));
  1932. //rot
  1933. bytes[i++] = (byte)(rx % 256);
  1934. bytes[i++] = (byte)((rx >> 8) % 256);
  1935. bytes[i++] = (byte)(ry % 256);
  1936. bytes[i++] = (byte)((ry >> 8) % 256);
  1937. bytes[i++] = (byte)(rz % 256);
  1938. bytes[i++] = (byte)((rz >> 8) % 256);
  1939. bytes[i++] = (byte)(rw % 256);
  1940. bytes[i++] = (byte)((rw >> 8) % 256);
  1941. //rotation vel
  1942. bytes[i++] = (byte)(ac % 256);
  1943. bytes[i++] = (byte)((ac >> 8) % 256);
  1944. bytes[i++] = (byte)(ac % 256);
  1945. bytes[i++] = (byte)((ac >> 8) % 256);
  1946. bytes[i++] = (byte)(ac % 256);
  1947. bytes[i++] = (byte)((ac >> 8) % 256);
  1948. dat.Data = bytes;
  1949. return (dat);
  1950. }
  1951. /// <summary>
  1952. ///
  1953. /// </summary>
  1954. /// <param name="localID"></param>
  1955. /// <param name="position"></param>
  1956. /// <param name="rotation"></param>
  1957. /// <returns></returns>
  1958. protected ImprovedTerseObjectUpdatePacket.ObjectDataBlock CreatePrimImprovedBlock(uint localID,
  1959. LLVector3 position,
  1960. LLQuaternion rotation,
  1961. LLVector3 velocity,
  1962. LLVector3 rotationalvelocity,
  1963. byte state)
  1964. {
  1965. uint ID = localID;
  1966. byte[] bytes = new byte[60];
  1967. int i = 0;
  1968. ImprovedTerseObjectUpdatePacket.ObjectDataBlock dat = new ImprovedTerseObjectUpdatePacket.ObjectDataBlock();
  1969. dat.TextureEntry = new byte[0];
  1970. bytes[i++] = (byte)(ID % 256);
  1971. bytes[i++] = (byte)((ID >> 8) % 256);
  1972. bytes[i++] = (byte)((ID >> 16) % 256);
  1973. bytes[i++] = (byte)((ID >> 24) % 256);
  1974. bytes[i++] = state;
  1975. bytes[i++] = 0;
  1976. byte[] pb = position.GetBytes();
  1977. Array.Copy(pb, 0, bytes, i, pb.Length);
  1978. i += 12;
  1979. ushort ac = 32767;
  1980. ushort velx, vely, velz;
  1981. Vector3 vel = new Vector3(velocity.X, velocity.Y, velocity.Z);
  1982. vel = vel / 128.0f;
  1983. vel.x += 1;
  1984. vel.y += 1;
  1985. vel.z += 1;
  1986. //vel
  1987. velx = (ushort)(32768 * (vel.x));
  1988. vely = (ushort)(32768 * (vel.y));
  1989. velz = (ushort)(32768 * (vel.z));
  1990. bytes[i++] = (byte)(velx % 256);
  1991. bytes[i++] = (byte)((velx >> 8) % 256);
  1992. bytes[i++] = (byte)(vely % 256);
  1993. bytes[i++] = (byte)((vely >> 8) % 256);
  1994. bytes[i++] = (byte)(velz % 256);
  1995. bytes[i++] = (byte)((velz >> 8) % 256);
  1996. //accel
  1997. bytes[i++] = (byte)(ac % 256);
  1998. bytes[i++] = (byte)((ac >> 8) % 256);
  1999. bytes[i++] = (byte)(ac % 256);
  2000. bytes[i++] = (byte)((ac >> 8) % 256);
  2001. bytes[i++] = (byte)(ac % 256);
  2002. bytes[i++] = (byte)((ac >> 8) % 256);
  2003. ushort rw, rx, ry, rz;
  2004. rw = (ushort)(32768 * (rotation.W + 1));
  2005. rx = (ushort)(32768 * (rotation.X + 1));
  2006. ry = (ushort)(32768 * (rotation.Y + 1));
  2007. rz = (ushort)(32768 * (rotation.Z + 1));
  2008. //rot
  2009. bytes[i++] = (byte)(rx % 256);
  2010. bytes[i++] = (byte)((rx >> 8) % 256);
  2011. bytes[i++] = (byte)(ry % 256);
  2012. bytes[i++] = (byte)((ry >> 8) % 256);
  2013. bytes[i++] = (byte)(rz % 256);
  2014. bytes[i++] = (byte)((rz >> 8) % 256);
  2015. bytes[i++] = (byte)(rw % 256);
  2016. bytes[i++] = (byte)((rw >> 8) % 256);
  2017. //rotation vel
  2018. ushort rvelx, rvely, rvelz;
  2019. Vector3 rvel = new Vector3(rotationalvelocity.X, rotationalvelocity.Y, rotationalvelocity.Z);
  2020. rvel = rvel / 128.0f;
  2021. rvel.x += 1;
  2022. rvel.y += 1;
  2023. rvel.z += 1;
  2024. //vel
  2025. rvelx = (ushort)(32768 * (rvel.x));
  2026. rvely = (ushort)(32768 * (rvel.y));
  2027. rvelz = (ushort)(32768 * (rvel.z));
  2028. bytes[i++] = (byte)(rvelx % 256);
  2029. bytes[i++] = (byte)((rvelx >> 8) % 256);
  2030. bytes[i++] = (byte)(rvely % 256);
  2031. bytes[i++] = (byte)((rvely >> 8) % 256);
  2032. bytes[i++] = (byte)(rvelz % 256);
  2033. bytes[i++] = (byte)((rvelz >> 8) % 256);
  2034. dat.Data = bytes;
  2035. return dat;
  2036. }
  2037. /// <summary>
  2038. /// Create the ObjectDataBlock for a ObjectUpdatePacket (for a Primitive)
  2039. /// </summary>
  2040. /// <param name="primData"></param>
  2041. /// <returns></returns>
  2042. protected ObjectUpdatePacket.ObjectDataBlock CreatePrimUpdateBlock(PrimitiveBaseShape primShape, uint flags)
  2043. {
  2044. ObjectUpdatePacket.ObjectDataBlock objupdate = new ObjectUpdatePacket.ObjectDataBlock();
  2045. SetDefaultPrimPacketValues(objupdate);
  2046. objupdate.UpdateFlags = flags;
  2047. SetPrimPacketShapeData(objupdate, primShape);
  2048. if ((primShape.PCode == (byte)PCode.NewTree) || (primShape.PCode == (byte)PCode.Tree) || (primShape.PCode == (byte)PCode.Grass))
  2049. {
  2050. objupdate.Data = new byte[1];
  2051. objupdate.Data[0] = primShape.State;
  2052. }
  2053. return objupdate;
  2054. }
  2055. protected void SetPrimPacketShapeData(ObjectUpdatePacket.ObjectDataBlock objectData, PrimitiveBaseShape primData)
  2056. {
  2057. objectData.TextureEntry = primData.TextureEntry;
  2058. objectData.PCode = primData.PCode;
  2059. objectData.State = primData.State;
  2060. objectData.PathBegin = primData.PathBegin;
  2061. objectData.PathEnd = primData.PathEnd;
  2062. objectData.PathScaleX = primData.PathScaleX;
  2063. objectData.PathScaleY = primData.PathScaleY;
  2064. objectData.PathShearX = primData.PathShearX;
  2065. objectData.PathShearY = primData.PathShearY;
  2066. objectData.PathSkew = primData.PathSkew;
  2067. objectData.ProfileBegin = primData.ProfileBegin;
  2068. objectData.ProfileEnd = primData.ProfileEnd;
  2069. objectData.Scale = primData.Scale;
  2070. objectData.PathCurve = primData.PathCurve;
  2071. objectData.ProfileCurve = primData.ProfileCurve;
  2072. objectData.ProfileHollow = primData.ProfileHollow;
  2073. objectData.PathRadiusOffset = primData.PathRadiusOffset;
  2074. objectData.PathRevolutions = primData.PathRevolutions;
  2075. objectData.PathTaperX = primData.PathTaperX;
  2076. objectData.PathTaperY = primData.PathTaperY;
  2077. objectData.PathTwist = primData.PathTwist;
  2078. objectData.PathTwistBegin = primData.PathTwistBegin;
  2079. objectData.ExtraParams = primData.ExtraParams;
  2080. }
  2081. /// <summary>
  2082. /// Set some default values in a ObjectUpdatePacket
  2083. /// </summary>
  2084. /// <param name="objdata"></param>
  2085. protected void SetDefaultPrimPacketValues(ObjectUpdatePacket.ObjectDataBlock objdata)
  2086. {
  2087. objdata.PSBlock = new byte[0];
  2088. objdata.ExtraParams = new byte[1];
  2089. objdata.MediaURL = new byte[0];
  2090. objdata.NameValue = new byte[0];
  2091. objdata.Text = new byte[0];
  2092. objdata.TextColor = new byte[4];
  2093. objdata.JointAxisOrAnchor = new LLVector3(0, 0, 0);
  2094. objdata.JointPivot = new LLVector3(0, 0, 0);
  2095. objdata.Material = 3;
  2096. objdata.TextureAnim = new byte[0];
  2097. objdata.Sound = LLUUID.Zero;
  2098. objdata.State = 0;
  2099. objdata.Data = new byte[0];
  2100. objdata.ObjectData = new byte[60];
  2101. objdata.ObjectData[46] = 128;
  2102. objdata.ObjectData[47] = 63;
  2103. }
  2104. /// <summary>
  2105. ///
  2106. /// </summary>
  2107. /// <returns></returns>
  2108. public ObjectUpdatePacket.ObjectDataBlock CreateDefaultAvatarPacket(byte[] textureEntry)
  2109. {
  2110. ObjectUpdatePacket.ObjectDataBlock objdata = new ObjectUpdatePacket.ObjectDataBlock();
  2111. // new libsecondlife.Packets.ObjectUpdatePacket.ObjectDataBlock(data1, ref i);
  2112. SetDefaultAvatarPacketValues(ref objdata);
  2113. objdata.UpdateFlags = 61 + (9 << 8) + (130 << 16) + (16 << 24);
  2114. objdata.PathCurve = 16;
  2115. objdata.ProfileCurve = 1;
  2116. objdata.PathScaleX = 100;
  2117. objdata.PathScaleY = 100;
  2118. objdata.ParentID = 0;
  2119. objdata.OwnerID = LLUUID.Zero;
  2120. objdata.Scale = new LLVector3(1, 1, 1);
  2121. objdata.PCode = (byte)PCode.Avatar;
  2122. if (textureEntry != null)
  2123. {
  2124. objdata.TextureEntry = textureEntry;
  2125. }
  2126. LLVector3 pos = new LLVector3(objdata.ObjectData, 16);
  2127. pos.X = 100f;
  2128. objdata.ID = 8880000;
  2129. objdata.NameValue = Helpers.StringToField("FirstName STRING RW SV Test \nLastName STRING RW SV User ");
  2130. //LLVector3 pos2 = new LLVector3(100f, 100f, 23f);
  2131. //objdata.FullID=user.AgentId;
  2132. byte[] pb = pos.GetBytes();
  2133. Array.Copy(pb, 0, objdata.ObjectData, 16, pb.Length);
  2134. return objdata;
  2135. }
  2136. /// <summary>
  2137. ///
  2138. /// </summary>
  2139. /// <param name="objdata"></param>
  2140. protected void SetDefaultAvatarPacketValues(ref ObjectUpdatePacket.ObjectDataBlock objdata)
  2141. {
  2142. objdata.PSBlock = new byte[0];
  2143. objdata.ExtraParams = new byte[1];
  2144. objdata.MediaURL = new byte[0];
  2145. objdata.NameValue = new byte[0];
  2146. objdata.Text = new byte[0];
  2147. objdata.TextColor = new byte[4];
  2148. objdata.JointAxisOrAnchor = new LLVector3(0, 0, 0);
  2149. objdata.JointPivot = new LLVector3(0, 0, 0);
  2150. objdata.Material = 4;
  2151. objdata.TextureAnim = new byte[0];
  2152. objdata.Sound = LLUUID.Zero;
  2153. LLObject.TextureEntry ntex = new LLObject.TextureEntry(new LLUUID("00000000-0000-0000-5005-000000000005"));
  2154. objdata.TextureEntry = ntex.ToBytes();
  2155. objdata.State = 0;
  2156. objdata.Data = new byte[0];
  2157. objdata.ObjectData = new byte[76];
  2158. objdata.ObjectData[15] = 128;
  2159. objdata.ObjectData[16] = 63;
  2160. objdata.ObjectData[56] = 128;
  2161. objdata.ObjectData[61] = 102;
  2162. objdata.ObjectData[62] = 40;
  2163. objdata.ObjectData[63] = 61;
  2164. objdata.ObjectData[64] = 189;
  2165. }
  2166. public void SendNameReply(LLUUID profileId, string firstname, string lastname)
  2167. {
  2168. UUIDNameReplyPacket packet = (UUIDNameReplyPacket)PacketPool.Instance.GetPacket(PacketType.UUIDNameReply);
  2169. // TODO: don't create new blocks if recycling an old packet
  2170. packet.UUIDNameBlock = new UUIDNameReplyPacket.UUIDNameBlockBlock[1];
  2171. packet.UUIDNameBlock[0] = new UUIDNameReplyPacket.UUIDNameBlockBlock();
  2172. packet.UUIDNameBlock[0].ID = profileId;
  2173. packet.UUIDNameBlock[0].FirstName = Helpers.StringToField(firstname);
  2174. packet.UUIDNameBlock[0].LastName = Helpers.StringToField(lastname);
  2175. OutPacket(packet, ThrottleOutPacketType.Task);
  2176. }
  2177. #endregion
  2178. protected virtual void RegisterLocalPacketHandlers()
  2179. {
  2180. AddLocalPacketHandler(PacketType.LogoutRequest, Logout);
  2181. AddLocalPacketHandler(PacketType.ViewerEffect, HandleViewerEffect);
  2182. AddLocalPacketHandler(PacketType.AgentCachedTexture, AgentTextureCached);
  2183. AddLocalPacketHandler(PacketType.MultipleObjectUpdate, MultipleObjUpdate);
  2184. AddLocalPacketHandler(PacketType.MoneyTransferRequest, HandleMoneyTransferRequest);
  2185. AddLocalPacketHandler(PacketType.ParcelBuy, HandleParcelBuyRequest);
  2186. }
  2187. private bool HandleMoneyTransferRequest(IClientAPI sender, Packet Pack)
  2188. {
  2189. MoneyTransferRequestPacket money = (MoneyTransferRequestPacket)Pack;
  2190. // validate the agent owns the agentID and sessionID
  2191. if (money.MoneyData.SourceID == sender.AgentId && money.AgentData.AgentID == sender.AgentId && money.AgentData.SessionID == sender.SessionId)
  2192. {
  2193. handlerMoneyTransferRequest = OnMoneyTransferRequest;
  2194. if (handlerMoneyTransferRequest != null)
  2195. {
  2196. handlerMoneyTransferRequest(money.MoneyData.SourceID, money.MoneyData.DestID,
  2197. money.MoneyData.Amount, money.MoneyData.TransactionType,
  2198. Util.FieldToString(money.MoneyData.Description));
  2199. }
  2200. return true;
  2201. }
  2202. else
  2203. {
  2204. return false;
  2205. }
  2206. }
  2207. private bool HandleParcelBuyRequest(IClientAPI sender, Packet Pack)
  2208. {
  2209. ParcelBuyPacket parcel = (ParcelBuyPacket)Pack;
  2210. if (parcel.AgentData.AgentID == AgentId && parcel.AgentData.SessionID == this.SessionId)
  2211. {
  2212. handlerParcelBuy = OnParcelBuy;
  2213. if (handlerParcelBuy != null)
  2214. {
  2215. handlerParcelBuy(parcel.AgentData.AgentID, parcel.Data.GroupID, parcel.Data.Final, parcel.Data.IsGroupOwned,
  2216. parcel.Data.RemoveContribution, parcel.Data.LocalID, parcel.ParcelData.Area, parcel.ParcelData.Price,
  2217. false);
  2218. }
  2219. return true;
  2220. }
  2221. else
  2222. {
  2223. return false;
  2224. }
  2225. }
  2226. private bool HandleViewerEffect(IClientAPI sender, Packet Pack)
  2227. {
  2228. ViewerEffectPacket viewer = (ViewerEffectPacket)Pack;
  2229. handlerViewerEffect = OnViewerEffect;
  2230. if (handlerViewerEffect != null)
  2231. {
  2232. handlerViewerEffect(sender, viewer.Effect);
  2233. }
  2234. return true;
  2235. }
  2236. public void SendScriptQuestion(LLUUID taskID, string taskName, string ownerName, LLUUID itemID, int question)
  2237. {
  2238. ScriptQuestionPacket scriptQuestion = (ScriptQuestionPacket)PacketPool.Instance.GetPacket(PacketType.ScriptQuestion);
  2239. scriptQuestion.Data = new ScriptQuestionPacket.DataBlock();
  2240. // TODO: don't create new blocks if recycling an old packet
  2241. scriptQuestion.Data.TaskID = taskID;
  2242. scriptQuestion.Data.ItemID = itemID;
  2243. scriptQuestion.Data.Questions = question;
  2244. scriptQuestion.Data.ObjectName = Helpers.StringToField(taskName);
  2245. scriptQuestion.Data.ObjectOwner = Helpers.StringToField(ownerName);
  2246. OutPacket(scriptQuestion, ThrottleOutPacketType.Task);
  2247. }
  2248. protected virtual bool Logout(IClientAPI client, Packet packet)
  2249. {
  2250. m_log.Info("[CLIENT]: Got a logout request");
  2251. handlerLogout = OnLogout;
  2252. if (handlerLogout != null)
  2253. {
  2254. handlerLogout(client);
  2255. }
  2256. return true;
  2257. }
  2258. /// <summary>
  2259. /// Send a response back to a client when it asks the asset server (via the region server) if it has
  2260. /// its appearance texture cached.
  2261. ///
  2262. /// At the moment, we always reply that there is no cached texture.
  2263. /// </summary>
  2264. /// <param name="simclient"></param>
  2265. /// <param name="packet"></param>
  2266. /// <returns></returns>
  2267. protected bool AgentTextureCached(IClientAPI simclient, Packet packet)
  2268. {
  2269. //Console.WriteLine("texture cached: " + packet.ToString());
  2270. AgentCachedTexturePacket cachedtex = (AgentCachedTexturePacket)packet;
  2271. AgentCachedTextureResponsePacket cachedresp = (AgentCachedTextureResponsePacket)PacketPool.Instance.GetPacket(PacketType.AgentCachedTextureResponse);
  2272. // TODO: don't create new blocks if recycling an old packet
  2273. cachedresp.AgentData.AgentID = AgentId;
  2274. cachedresp.AgentData.SessionID = m_sessionId;
  2275. cachedresp.AgentData.SerialNum = m_cachedTextureSerial;
  2276. m_cachedTextureSerial++;
  2277. cachedresp.WearableData =
  2278. new AgentCachedTextureResponsePacket.WearableDataBlock[cachedtex.WearableData.Length];
  2279. for (int i = 0; i < cachedtex.WearableData.Length; i++)
  2280. {
  2281. cachedresp.WearableData[i] = new AgentCachedTextureResponsePacket.WearableDataBlock();
  2282. cachedresp.WearableData[i].TextureIndex = cachedtex.WearableData[i].TextureIndex;
  2283. cachedresp.WearableData[i].TextureID = LLUUID.Zero;
  2284. cachedresp.WearableData[i].HostName = new byte[0];
  2285. }
  2286. // Temporarily throw these packets on to the wind queue, so we can identify whether these
  2287. // are somehow the source of the packet bloat.
  2288. OutPacket(cachedresp, ThrottleOutPacketType.Wind);
  2289. return true;
  2290. }
  2291. protected bool MultipleObjUpdate(IClientAPI simClient, Packet packet)
  2292. {
  2293. MultipleObjectUpdatePacket multipleupdate = (MultipleObjectUpdatePacket)packet;
  2294. // Console.WriteLine("new multi update packet " + multipleupdate.ToString());
  2295. Scene tScene = (Scene)m_scene;
  2296. for (int i = 0; i < multipleupdate.ObjectData.Length; i++)
  2297. {
  2298. MultipleObjectUpdatePacket.ObjectDataBlock block = multipleupdate.ObjectData[i];
  2299. // Can't act on Null Data
  2300. if (block.Data != null)
  2301. {
  2302. uint localId = block.ObjectLocalID;
  2303. SceneObjectPart part = tScene.GetSceneObjectPart(localId);
  2304. if (part == null)
  2305. {
  2306. // It's a ghost! tell the client to delete it from view.
  2307. simClient.SendKillObject(Scene.RegionInfo.RegionHandle,
  2308. localId);
  2309. }
  2310. else
  2311. {
  2312. LLUUID partId = part.UUID;
  2313. UpdatePrimRotation handlerUpdatePrimRotation = OnUpdatePrimGroupRotation;
  2314. UpdatePrimGroupRotation handlerUpdatePrimGroupRotation = OnUpdatePrimGroupMouseRotation;
  2315. switch (block.Type)
  2316. {
  2317. case 1:
  2318. LLVector3 pos1 = new LLVector3(block.Data, 0);
  2319. handlerUpdatePrimSinglePosition = OnUpdatePrimSinglePosition;
  2320. if (handlerUpdatePrimSinglePosition != null)
  2321. {
  2322. // Console.WriteLine("new movement position is " + pos.X + " , " + pos.Y + " , " + pos.Z);
  2323. handlerUpdatePrimSinglePosition(localId, pos1, this);
  2324. }
  2325. break;
  2326. case 2:
  2327. LLQuaternion rot1 = new LLQuaternion(block.Data, 0, true);
  2328. handlerUpdatePrimSingleRotation = OnUpdatePrimSingleRotation;
  2329. if (handlerUpdatePrimSingleRotation != null)
  2330. {
  2331. //Console.WriteLine("new tab rotation is " + rot.X + " , " + rot.Y + " , " + rot.Z + " , " + rot.W);
  2332. handlerUpdatePrimSingleRotation(localId, rot1, this);
  2333. }
  2334. break;
  2335. case 3:
  2336. LLQuaternion rot2 = new LLQuaternion(block.Data, 12, true);
  2337. handlerUpdatePrimSingleRotation = OnUpdatePrimSingleRotation;
  2338. if (handlerUpdatePrimSingleRotation != null)
  2339. {
  2340. //Console.WriteLine("new mouse rotation is " + rot.X + " , " + rot.Y + " , " + rot.Z + " , " + rot.W);
  2341. handlerUpdatePrimSingleRotation(localId, rot2, this);
  2342. }
  2343. break;
  2344. case 5:
  2345. LLVector3 scale1 = new LLVector3(block.Data, 12);
  2346. LLVector3 pos11 = new LLVector3(block.Data, 0);
  2347. handlerUpdatePrimScale = OnUpdatePrimScale;
  2348. if (handlerUpdatePrimScale != null)
  2349. {
  2350. // Console.WriteLine("new scale is " + scale.X + " , " + scale.Y + " , " + scale.Z);
  2351. handlerUpdatePrimScale(localId, scale1, this);
  2352. handlerUpdatePrimSinglePosition = OnUpdatePrimSinglePosition;
  2353. if (handlerUpdatePrimSinglePosition != null)
  2354. {
  2355. handlerUpdatePrimSinglePosition(localId, pos11, this);
  2356. }
  2357. }
  2358. break;
  2359. case 9:
  2360. LLVector3 pos2 = new LLVector3(block.Data, 0);
  2361. handlerUpdateVector = OnUpdatePrimGroupPosition;
  2362. if (handlerUpdateVector != null)
  2363. {
  2364. handlerUpdateVector(localId, pos2, this);
  2365. }
  2366. break;
  2367. case 10:
  2368. LLQuaternion rot3 = new LLQuaternion(block.Data, 0, true);
  2369. handlerUpdatePrimRotation = OnUpdatePrimGroupRotation;
  2370. if (handlerUpdatePrimRotation != null)
  2371. {
  2372. // Console.WriteLine("new rotation is " + rot.X + " , " + rot.Y + " , " + rot.Z + " , " + rot.W);
  2373. handlerUpdatePrimRotation(localId, rot3, this);
  2374. }
  2375. break;
  2376. case 11:
  2377. LLVector3 pos3 = new LLVector3(block.Data, 0);
  2378. LLQuaternion rot4 = new LLQuaternion(block.Data, 12, true);
  2379. handlerUpdatePrimGroupRotation = OnUpdatePrimGroupMouseRotation;
  2380. if (handlerUpdatePrimGroupRotation != null)
  2381. {
  2382. //Console.WriteLine("new rotation position is " + pos.X + " , " + pos.Y + " , " + pos.Z);
  2383. // Console.WriteLine("new rotation is " + rot.X + " , " + rot.Y + " , " + rot.Z + " , " + rot.W);
  2384. handlerUpdatePrimGroupRotation(localId, pos3, rot4, this);
  2385. }
  2386. break;
  2387. case 13:
  2388. LLVector3 scale2 = new LLVector3(block.Data, 12);
  2389. LLVector3 pos4 = new LLVector3(block.Data, 0);
  2390. handlerUpdatePrimScale = OnUpdatePrimScale;
  2391. if (handlerUpdatePrimScale != null)
  2392. {
  2393. //Console.WriteLine("new scale is " + scale.X + " , " + scale.Y + " , " + scale.Z);
  2394. handlerUpdatePrimScale(localId, scale2, this);
  2395. // Change the position based on scale (for bug number 246)
  2396. handlerUpdatePrimSinglePosition = OnUpdatePrimSinglePosition;
  2397. // Console.WriteLine("new movement position is " + pos.X + " , " + pos.Y + " , " + pos.Z);
  2398. if (handlerUpdatePrimSinglePosition != null)
  2399. {
  2400. handlerUpdatePrimSinglePosition(localId, pos4, this);
  2401. }
  2402. }
  2403. break;
  2404. case 29:
  2405. LLVector3 scale5 = new LLVector3(block.Data, 12);
  2406. LLVector3 pos5 = new LLVector3(block.Data, 0);
  2407. handlerUpdatePrimGroupScale = OnUpdatePrimGroupScale;
  2408. if (handlerUpdatePrimGroupScale != null)
  2409. {
  2410. // Console.WriteLine("new scale is " + scale.X + " , " + scale.Y + " , " + scale.Z );
  2411. handlerUpdatePrimGroupScale(localId, scale5, this);
  2412. handlerUpdateVector = OnUpdatePrimGroupPosition;
  2413. if (handlerUpdateVector != null)
  2414. {
  2415. handlerUpdateVector(localId, pos5, this);
  2416. }
  2417. }
  2418. break;
  2419. case 21:
  2420. LLVector3 scale6 = new LLVector3(block.Data, 12);
  2421. LLVector3 pos6 = new LLVector3(block.Data, 0);
  2422. handlerUpdatePrimScale = OnUpdatePrimScale;
  2423. if (handlerUpdatePrimScale != null)
  2424. {
  2425. // Console.WriteLine("new scale is " + scale.X + " , " + scale.Y + " , " + scale.Z);
  2426. handlerUpdatePrimScale(localId, scale6, this);
  2427. handlerUpdatePrimSinglePosition = OnUpdatePrimSinglePosition;
  2428. if (handlerUpdatePrimSinglePosition != null)
  2429. {
  2430. handlerUpdatePrimSinglePosition(localId, pos6, this);
  2431. }
  2432. }
  2433. break;
  2434. }
  2435. }
  2436. }
  2437. }
  2438. return true;
  2439. }
  2440. public void RequestMapLayer()
  2441. {
  2442. //should be getting the map layer from the grid server
  2443. //send a layer covering the 800,800 - 1200,1200 area (should be covering the requested area)
  2444. MapLayerReplyPacket mapReply = (MapLayerReplyPacket)PacketPool.Instance.GetPacket(PacketType.MapLayerReply);
  2445. // TODO: don't create new blocks if recycling an old packet
  2446. mapReply.AgentData.AgentID = AgentId;
  2447. mapReply.AgentData.Flags = 0;
  2448. mapReply.LayerData = new MapLayerReplyPacket.LayerDataBlock[1];
  2449. mapReply.LayerData[0] = new MapLayerReplyPacket.LayerDataBlock();
  2450. mapReply.LayerData[0].Bottom = 0;
  2451. mapReply.LayerData[0].Left = 0;
  2452. mapReply.LayerData[0].Top = 30000;
  2453. mapReply.LayerData[0].Right = 30000;
  2454. mapReply.LayerData[0].ImageID = new LLUUID("00000000-0000-1111-9999-000000000006");
  2455. OutPacket(mapReply, ThrottleOutPacketType.Land);
  2456. }
  2457. public void RequestMapBlocksX(int minX, int minY, int maxX, int maxY)
  2458. {
  2459. /*
  2460. IList simMapProfiles = m_gridServer.RequestMapBlocks(minX, minY, maxX, maxY);
  2461. MapBlockReplyPacket mbReply = new MapBlockReplyPacket();
  2462. mbReply.AgentData.AgentId = this.AgentId;
  2463. int len;
  2464. if (simMapProfiles == null)
  2465. len = 0;
  2466. else
  2467. len = simMapProfiles.Count;
  2468. mbReply.Data = new MapBlockReplyPacket.DataBlock[len];
  2469. int iii;
  2470. for (iii = 0; iii < len; iii++)
  2471. {
  2472. Hashtable mp = (Hashtable)simMapProfiles[iii];
  2473. mbReply.Data[iii] = new MapBlockReplyPacket.DataBlock();
  2474. mbReply.Data[iii].Name = System.Text.Encoding.UTF8.GetBytes((string)mp["name"]);
  2475. mbReply.Data[iii].Access = System.Convert.ToByte(mp["access"]);
  2476. mbReply.Data[iii].Agents = System.Convert.ToByte(mp["agents"]);
  2477. mbReply.Data[iii].MapImageID = new LLUUID((string)mp["map-image-id"]);
  2478. mbReply.Data[iii].RegionFlags = System.Convert.ToUInt32(mp["region-flags"]);
  2479. mbReply.Data[iii].WaterHeight = System.Convert.ToByte(mp["water-height"]);
  2480. mbReply.Data[iii].X = System.Convert.ToUInt16(mp["x"]);
  2481. mbReply.Data[iii].Y = System.Convert.ToUInt16(mp["y"]);
  2482. }
  2483. this.OutPacket(mbReply, ThrottleOutPacketType.Land);
  2484. */
  2485. }
  2486. public byte[] GetThrottlesPacked(float multiplier)
  2487. {
  2488. return m_packetQueue.GetThrottlesPacked(multiplier);
  2489. }
  2490. public void SetChildAgentThrottle(byte[] throttles)
  2491. {
  2492. m_packetQueue.SetThrottleFromClient(throttles);
  2493. }
  2494. // Previously ClientView.m_packetQueue
  2495. // A thread safe sequence number allocator.
  2496. protected uint NextSeqNum()
  2497. {
  2498. // Set the sequence number
  2499. uint seq = 1;
  2500. lock (m_sequenceLock)
  2501. {
  2502. if (m_sequence >= MAX_SEQUENCE)
  2503. {
  2504. m_sequence = 1;
  2505. }
  2506. else
  2507. {
  2508. m_sequence++;
  2509. }
  2510. seq = m_sequence;
  2511. }
  2512. return seq;
  2513. }
  2514. protected void AddAck(Packet Pack)
  2515. {
  2516. lock (m_needAck)
  2517. {
  2518. if (!m_needAck.ContainsKey(Pack.Header.Sequence))
  2519. {
  2520. try
  2521. {
  2522. m_needAck.Add(Pack.Header.Sequence, Pack);
  2523. m_unAckedBytes += Pack.ToBytes().Length;
  2524. }
  2525. catch (Exception) // HACKY
  2526. {
  2527. // Ignore
  2528. // Seems to throw a exception here occasionally
  2529. // of 'duplicate key' despite being locked.
  2530. // !?!?!?
  2531. }
  2532. }
  2533. else
  2534. {
  2535. // Client.Log("Attempted to add a duplicate sequence number (" +
  2536. // packet.Header.m_sequence + ") to the m_needAck dictionary for packet type " +
  2537. // packet.Type.ToString(), Helpers.LogLevel.Warning);
  2538. }
  2539. }
  2540. }
  2541. protected virtual void SetPendingAcks(ref Packet Pack)
  2542. {
  2543. // Append any ACKs that need to be sent out to this packet
  2544. lock (m_pendingAcks)
  2545. {
  2546. // TODO: If we are over MAX_APPENDED_ACKS we should drain off some of these
  2547. if (m_pendingAcks.Count > 0 && m_pendingAcks.Count < MAX_APPENDED_ACKS)
  2548. {
  2549. Pack.Header.AckList = new uint[m_pendingAcks.Count];
  2550. int i = 0;
  2551. foreach (uint ack in m_pendingAcks.Values)
  2552. {
  2553. Pack.Header.AckList[i] = ack;
  2554. i++;
  2555. }
  2556. m_pendingAcks.Clear();
  2557. Pack.Header.AppendedAcks = true;
  2558. }
  2559. }
  2560. }
  2561. protected virtual void ProcessOutPacket(Packet Pack)
  2562. {
  2563. // Keep track of when this packet was sent out
  2564. Pack.TickCount = System.Environment.TickCount;
  2565. if (!Pack.Header.Resent)
  2566. {
  2567. Pack.Header.Sequence = NextSeqNum();
  2568. if (Pack.Header.Reliable) //DIRTY HACK
  2569. {
  2570. AddAck(Pack); // this adds the need to ack this packet later
  2571. if (Pack.Type != PacketType.PacketAck && Pack.Type != PacketType.LogoutRequest)
  2572. {
  2573. SetPendingAcks(ref Pack);
  2574. }
  2575. }
  2576. }
  2577. // Actually make the byte array and send it
  2578. try
  2579. {
  2580. byte[] sendbuffer = Pack.ToBytes();
  2581. PacketPool.Instance.ReturnPacket(Pack);
  2582. if (Pack.Header.Zerocoded)
  2583. {
  2584. int packetsize = Helpers.ZeroEncode(sendbuffer, sendbuffer.Length, ZeroOutBuffer);
  2585. m_networkServer.SendPacketTo(ZeroOutBuffer, packetsize, SocketFlags.None, m_circuitCode);
  2586. }
  2587. else
  2588. {
  2589. //Need some extra space in case we need to add proxy information to the message later
  2590. Buffer.BlockCopy(sendbuffer, 0, ZeroOutBuffer, 0, sendbuffer.Length);
  2591. m_networkServer.SendPacketTo(ZeroOutBuffer, sendbuffer.Length, SocketFlags.None, m_circuitCode);
  2592. }
  2593. }
  2594. catch (Exception e)
  2595. {
  2596. m_log.Warn("[client]: " +
  2597. "ClientView.m_packetQueue.cs:ProcessOutPacket() - WARNING: Socket exception occurred on connection " +
  2598. m_userEndPoint.ToString() + " - killing thread");
  2599. m_log.Error(e.ToString());
  2600. Close(true);
  2601. }
  2602. }
  2603. public virtual void InPacket(Packet NewPack)
  2604. {
  2605. if (!m_packetProcessingEnabled && NewPack.Type != PacketType.LogoutRequest)
  2606. {
  2607. PacketPool.Instance.ReturnPacket(NewPack);
  2608. return;
  2609. }
  2610. // Handle appended ACKs
  2611. if (NewPack != null)
  2612. {
  2613. if (NewPack.Header.AppendedAcks)
  2614. {
  2615. lock (m_needAck)
  2616. {
  2617. foreach (uint ackedPacketId in NewPack.Header.AckList)
  2618. {
  2619. Packet ackedPacket;
  2620. if (m_needAck.TryGetValue(ackedPacketId, out ackedPacket))
  2621. {
  2622. m_unAckedBytes -= ackedPacket.ToBytes().Length;
  2623. m_needAck.Remove(ackedPacketId);
  2624. }
  2625. }
  2626. }
  2627. }
  2628. // Handle PacketAck packets
  2629. if (NewPack.Type == PacketType.PacketAck)
  2630. {
  2631. PacketAckPacket ackPacket = (PacketAckPacket)NewPack;
  2632. lock (m_needAck)
  2633. {
  2634. foreach (PacketAckPacket.PacketsBlock block in ackPacket.Packets)
  2635. {
  2636. uint ackedPackId = block.ID;
  2637. Packet ackedPacket;
  2638. if (m_needAck.TryGetValue(ackedPackId, out ackedPacket))
  2639. {
  2640. m_unAckedBytes -= ackedPacket.ToBytes().Length;
  2641. m_needAck.Remove(ackedPackId);
  2642. }
  2643. }
  2644. }
  2645. }
  2646. else if ((NewPack.Type == PacketType.StartPingCheck))
  2647. {
  2648. //reply to pingcheck
  2649. StartPingCheckPacket startPing = (StartPingCheckPacket)NewPack;
  2650. CompletePingCheckPacket endPing = (CompletePingCheckPacket)PacketPool.Instance.GetPacket(PacketType.CompletePingCheck);
  2651. endPing.PingID.PingID = startPing.PingID.PingID;
  2652. OutPacket(endPing, ThrottleOutPacketType.Task);
  2653. }
  2654. else
  2655. {
  2656. QueItem item = new QueItem();
  2657. item.Packet = NewPack;
  2658. item.Incoming = true;
  2659. m_packetQueue.Enqueue(item);
  2660. }
  2661. }
  2662. }
  2663. public virtual void OutPacket(Packet NewPack, ThrottleOutPacketType throttlePacketType)
  2664. {
  2665. if ((SynchronizeClient != null) && (!PacketProcessingEnabled))
  2666. {
  2667. // Sending packet to active client's server.
  2668. if (SynchronizeClient(m_scene, NewPack, m_agentId, throttlePacketType))
  2669. {
  2670. return;
  2671. }
  2672. }
  2673. QueItem item = new QueItem();
  2674. item.Packet = NewPack;
  2675. item.Incoming = false;
  2676. item.throttleType = throttlePacketType; // Packet throttle type
  2677. m_packetQueue.Enqueue(item);
  2678. m_packetsSent++;
  2679. }
  2680. # region Low Level Packet Methods
  2681. protected void ack_pack(Packet Pack)
  2682. {
  2683. if (Pack.Header.Reliable)
  2684. {
  2685. PacketAckPacket ack_it = (PacketAckPacket)PacketPool.Instance.GetPacket(PacketType.PacketAck);
  2686. // TODO: don't create new blocks if recycling an old packet
  2687. ack_it.Packets = new PacketAckPacket.PacketsBlock[1];
  2688. ack_it.Packets[0] = new PacketAckPacket.PacketsBlock();
  2689. ack_it.Packets[0].ID = Pack.Header.Sequence;
  2690. ack_it.Header.Reliable = false;
  2691. OutPacket(ack_it, ThrottleOutPacketType.Unknown);
  2692. }
  2693. /*
  2694. if (Pack.Header.Reliable)
  2695. {
  2696. lock (m_pendingAcks)
  2697. {
  2698. uint sequence = (uint)Pack.Header.m_sequence;
  2699. if (!m_pendingAcks.ContainsKey(sequence)) { m_pendingAcks[sequence] = sequence; }
  2700. }
  2701. }*/
  2702. }
  2703. protected void ResendUnacked()
  2704. {
  2705. int now = System.Environment.TickCount;
  2706. lock (m_needAck)
  2707. {
  2708. foreach (Packet packet in m_needAck.Values)
  2709. {
  2710. if ((now - packet.TickCount > RESEND_TIMEOUT) && (!packet.Header.Resent))
  2711. {
  2712. //m_log.Debug("[NETWORK]: Resending " + packet.Type.ToString() + " packet, " +
  2713. //(now - packet.TickCount) + "ms have passed");
  2714. packet.Header.Resent = true;
  2715. OutPacket(packet, ThrottleOutPacketType.Resend);
  2716. }
  2717. }
  2718. }
  2719. }
  2720. protected void SendAcks()
  2721. {
  2722. lock (m_pendingAcks)
  2723. {
  2724. if (m_pendingAcks.Count > 0)
  2725. {
  2726. if (m_pendingAcks.Count > 250)
  2727. {
  2728. // FIXME: Handle the odd case where we have too many pending ACKs queued up
  2729. m_log.Info("[NETWORK]: Too many ACKs queued up!");
  2730. return;
  2731. }
  2732. //m_log.Info("[NETWORK]: Sending PacketAck");
  2733. int i = 0;
  2734. PacketAckPacket acks = (PacketAckPacket)PacketPool.Instance.GetPacket(PacketType.PacketAck);
  2735. // TODO: don't create new blocks if recycling an old packet
  2736. acks.Packets = new PacketAckPacket.PacketsBlock[m_pendingAcks.Count];
  2737. foreach (uint ack in m_pendingAcks.Values)
  2738. {
  2739. acks.Packets[i] = new PacketAckPacket.PacketsBlock();
  2740. acks.Packets[i].ID = ack;
  2741. i++;
  2742. }
  2743. acks.Header.Reliable = false;
  2744. OutPacket(acks, ThrottleOutPacketType.Unknown);
  2745. m_pendingAcks.Clear();
  2746. }
  2747. }
  2748. }
  2749. protected void AckTimer_Elapsed(object sender, ElapsedEventArgs ea)
  2750. {
  2751. SendAcks();
  2752. ResendUnacked();
  2753. SendPacketStats();
  2754. }
  2755. protected void SendPacketStats()
  2756. {
  2757. handlerPacketStats = OnPacketStats;
  2758. if (handlerPacketStats != null)
  2759. {
  2760. handlerPacketStats(m_packetsReceived - m_lastPacketsReceivedSentToScene, m_packetsSent - m_lastPacketsSentSentToScene, m_unAckedBytes);
  2761. m_lastPacketsReceivedSentToScene = m_packetsReceived;
  2762. m_lastPacketsSentSentToScene = m_packetsSent;
  2763. }
  2764. }
  2765. #endregion
  2766. // Previously ClientView.ProcessPackets
  2767. public bool AddMoney(int debit)
  2768. {
  2769. if (m_moneyBalance + debit >= 0)
  2770. {
  2771. m_moneyBalance += debit;
  2772. SendMoneyBalance(LLUUID.Zero, true, Helpers.StringToField("Poof Poof!"), m_moneyBalance);
  2773. return true;
  2774. }
  2775. else
  2776. {
  2777. return false;
  2778. }
  2779. }
  2780. private bool m_packetProcessingEnabled = true;
  2781. public bool PacketProcessingEnabled {
  2782. get { return m_packetProcessingEnabled; }
  2783. set { m_packetProcessingEnabled = value; }
  2784. }
  2785. protected void ProcessInPacket(Packet Pack)
  2786. {
  2787. ack_pack(Pack);
  2788. if (ProcessPacketMethod(Pack))
  2789. {
  2790. //there is a handler registered that handled this packet type
  2791. return;
  2792. }
  2793. else
  2794. {
  2795. switch (Pack.Type)
  2796. {
  2797. #region Scene/Avatar
  2798. case PacketType.AvatarPropertiesRequest:
  2799. AvatarPropertiesRequestPacket avatarProperties = (AvatarPropertiesRequestPacket)Pack;
  2800. handlerRequestAvatarProperties = OnRequestAvatarProperties;
  2801. if (handlerRequestAvatarProperties != null)
  2802. {
  2803. handlerRequestAvatarProperties(this, avatarProperties.AgentData.AvatarID);
  2804. }
  2805. break;
  2806. case PacketType.ChatFromViewer:
  2807. ChatFromViewerPacket inchatpack = (ChatFromViewerPacket)Pack;
  2808. string fromName = String.Empty; //ClientAvatar.firstname + " " + ClientAvatar.lastname;
  2809. byte[] message = inchatpack.ChatData.Message;
  2810. byte type = inchatpack.ChatData.Type;
  2811. LLVector3 fromPos = new LLVector3(); // ClientAvatar.Pos;
  2812. LLUUID fromAgentID = AgentId;
  2813. int channel = inchatpack.ChatData.Channel;
  2814. if (OnChatFromViewer != null)
  2815. {
  2816. ChatFromViewerArgs args = new ChatFromViewerArgs();
  2817. args.Channel = channel;
  2818. args.From = fromName;
  2819. args.Message = Helpers.FieldToUTF8String(message);
  2820. args.Type = (ChatTypeEnum)type;
  2821. args.Position = fromPos;
  2822. args.Scene = Scene;
  2823. args.Sender = this;
  2824. handlerChatFromViewer = OnChatFromViewer;
  2825. if (handlerChatFromViewer != null)
  2826. handlerChatFromViewer(this, args);
  2827. }
  2828. break;
  2829. case PacketType.AvatarPropertiesUpdate:
  2830. AvatarPropertiesUpdatePacket Packet = (AvatarPropertiesUpdatePacket)Pack;
  2831. handlerUpdateAvatarProperties = OnUpdateAvatarProperties;
  2832. if (handlerUpdateAvatarProperties != null)
  2833. {
  2834. AvatarPropertiesUpdatePacket.PropertiesDataBlock Properties = Packet.PropertiesData;
  2835. UserProfileData UserProfile = new UserProfileData();
  2836. UserProfile.ID = AgentId;
  2837. UserProfile.AboutText = Helpers.FieldToUTF8String(Properties.AboutText);
  2838. UserProfile.FirstLifeAboutText = Helpers.FieldToUTF8String(Properties.FLAboutText);
  2839. UserProfile.FirstLifeImage = Properties.FLImageID;
  2840. UserProfile.Image = Properties.ImageID;
  2841. handlerUpdateAvatarProperties(this, UserProfile);
  2842. }
  2843. break;
  2844. case PacketType.ScriptDialogReply:
  2845. ScriptDialogReplyPacket rdialog = (ScriptDialogReplyPacket)Pack;
  2846. int ch = rdialog.Data.ChatChannel;
  2847. byte[] msg = rdialog.Data.ButtonLabel;
  2848. if (OnChatFromViewer != null)
  2849. {
  2850. ChatFromViewerArgs args = new ChatFromViewerArgs();
  2851. args.Channel = ch;
  2852. args.From = String.Empty;
  2853. args.Message = Helpers.FieldToUTF8String(msg);
  2854. args.Type = ChatTypeEnum.Shout;
  2855. args.Position = new LLVector3();
  2856. args.Scene = Scene;
  2857. args.Sender = this;
  2858. handlerChatFromViewer2 = OnChatFromViewer;
  2859. if (handlerChatFromViewer2 != null)
  2860. handlerChatFromViewer2(this, args);
  2861. }
  2862. break;
  2863. case PacketType.ImprovedInstantMessage:
  2864. ImprovedInstantMessagePacket msgpack = (ImprovedInstantMessagePacket)Pack;
  2865. string IMfromName = Util.FieldToString(msgpack.MessageBlock.FromAgentName);
  2866. string IMmessage = Helpers.FieldToUTF8String(msgpack.MessageBlock.Message);
  2867. handlerInstantMessage = OnInstantMessage;
  2868. if (handlerInstantMessage != null)
  2869. {
  2870. handlerInstantMessage(this, msgpack.AgentData.AgentID, msgpack.AgentData.SessionID,
  2871. msgpack.MessageBlock.ToAgentID, msgpack.MessageBlock.ID,
  2872. msgpack.MessageBlock.Timestamp, IMfromName, IMmessage,
  2873. msgpack.MessageBlock.Dialog, msgpack.MessageBlock.FromGroup,
  2874. msgpack.MessageBlock.Offline, msgpack.MessageBlock.ParentEstateID,
  2875. msgpack.MessageBlock.Position, msgpack.MessageBlock.RegionID,
  2876. msgpack.MessageBlock.BinaryBucket);
  2877. }
  2878. break;
  2879. case PacketType.AcceptFriendship:
  2880. AcceptFriendshipPacket afriendpack = (AcceptFriendshipPacket)Pack;
  2881. // My guess is this is the folder to stick the calling card into
  2882. List<LLUUID> callingCardFolders = new List<LLUUID>();
  2883. LLUUID agentID = afriendpack.AgentData.AgentID;
  2884. LLUUID transactionID = afriendpack.TransactionBlock.TransactionID;
  2885. for (int fi = 0; fi < afriendpack.FolderData.Length; fi++)
  2886. {
  2887. callingCardFolders.Add(afriendpack.FolderData[fi].FolderID);
  2888. }
  2889. handlerApproveFriendRequest = OnApproveFriendRequest;
  2890. if (handlerApproveFriendRequest != null)
  2891. {
  2892. handlerApproveFriendRequest(this, agentID, transactionID, callingCardFolders);
  2893. }
  2894. break;
  2895. case PacketType.TerminateFriendship:
  2896. TerminateFriendshipPacket tfriendpack = (TerminateFriendshipPacket)Pack;
  2897. LLUUID listOwnerAgentID = tfriendpack.AgentData.AgentID;
  2898. LLUUID exFriendID = tfriendpack.ExBlock.OtherID;
  2899. handlerTerminateFriendship = OnTerminateFriendship;
  2900. if (handlerTerminateFriendship != null)
  2901. {
  2902. handlerTerminateFriendship(this, listOwnerAgentID, exFriendID);
  2903. }
  2904. break;
  2905. case PacketType.RezObject:
  2906. RezObjectPacket rezPacket = (RezObjectPacket)Pack;
  2907. handlerRezObject = OnRezObject;
  2908. if (handlerRezObject != null)
  2909. {
  2910. //rezPacket.RezData.BypassRaycast;
  2911. //rezPacket.RezData.RayEnd;
  2912. //rezPacket.RezData.RayEndIsIntersection;
  2913. //rezPacket.RezData.RayStart;
  2914. //rezPacket.RezData.RayTargetID;
  2915. //rezPacket.RezData.RemoveItem;
  2916. //rezPacket.RezData.RezSelected;
  2917. //rezPacket.RezData.FromTaskID;
  2918. //m_log.Info("[REZData]: " + rezPacket.ToString());
  2919. handlerRezObject(this, rezPacket.InventoryData.ItemID, rezPacket.RezData.RayEnd,
  2920. rezPacket.RezData.RayStart, rezPacket.RezData.RayTargetID,
  2921. rezPacket.RezData.BypassRaycast, rezPacket.RezData.RayEndIsIntersection,
  2922. rezPacket.RezData.EveryoneMask, rezPacket.RezData.GroupMask,
  2923. rezPacket.RezData.NextOwnerMask, rezPacket.RezData.ItemFlags,
  2924. rezPacket.RezData.RezSelected, rezPacket.RezData.RemoveItem,
  2925. rezPacket.RezData.FromTaskID);
  2926. }
  2927. break;
  2928. case PacketType.DeRezObject:
  2929. handlerDeRezObject = OnDeRezObject;
  2930. if (handlerDeRezObject != null)
  2931. {
  2932. handlerDeRezObject(Pack, this);
  2933. }
  2934. break;
  2935. case PacketType.ModifyLand:
  2936. ModifyLandPacket modify = (ModifyLandPacket)Pack;
  2937. //m_log.Info("[LAND]: LAND:" + modify.ToString());
  2938. if (modify.ParcelData.Length > 0)
  2939. {
  2940. if (OnModifyTerrain != null)
  2941. {
  2942. for (int i = 0; i < modify.ParcelData.Length; i++)
  2943. {
  2944. handlerModifyTerrain = OnModifyTerrain;
  2945. if (handlerModifyTerrain != null)
  2946. {
  2947. handlerModifyTerrain(modify.ModifyBlock.Height, modify.ModifyBlock.Seconds,
  2948. modify.ModifyBlock.BrushSize,
  2949. modify.ModifyBlock.Action, modify.ParcelData[i].North,
  2950. modify.ParcelData[i].West, modify.ParcelData[i].South,
  2951. modify.ParcelData[i].East, this);
  2952. }
  2953. }
  2954. }
  2955. }
  2956. break;
  2957. case PacketType.RegionHandshakeReply:
  2958. handlerRegionHandShakeReply = OnRegionHandShakeReply;
  2959. if (handlerRegionHandShakeReply != null)
  2960. {
  2961. handlerRegionHandShakeReply(this);
  2962. }
  2963. break;
  2964. case PacketType.AgentWearablesRequest:
  2965. handlerRequestWearables = OnRequestWearables;
  2966. if (handlerRequestWearables != null)
  2967. {
  2968. handlerRequestWearables();
  2969. }
  2970. handlerRequestAvatarsData = OnRequestAvatarsData;
  2971. if (handlerRequestAvatarsData != null)
  2972. {
  2973. handlerRequestAvatarsData(this);
  2974. }
  2975. break;
  2976. case PacketType.AgentSetAppearance:
  2977. AgentSetAppearancePacket appear = (AgentSetAppearancePacket)Pack;
  2978. handlerSetAppearance = OnSetAppearance;
  2979. if (handlerSetAppearance != null)
  2980. {
  2981. // Temporarily protect ourselves from the mantis #951 failure.
  2982. // However, we could do this for several other handlers where a failure isn't terminal
  2983. // for the client session anyway, in order to protect ourselves against bad code in plugins
  2984. try
  2985. {
  2986. handlerSetAppearance(appear.ObjectData.TextureEntry, appear.VisualParam);
  2987. }
  2988. catch (Exception e)
  2989. {
  2990. m_log.ErrorFormat(
  2991. "[CLIENT VIEW]: AgentSetApperance packet handler threw an exception, {0}",
  2992. e);
  2993. }
  2994. }
  2995. break;
  2996. case PacketType.AgentIsNowWearing:
  2997. if (OnAvatarNowWearing != null)
  2998. {
  2999. AgentIsNowWearingPacket nowWearing = (AgentIsNowWearingPacket)Pack;
  3000. AvatarWearingArgs wearingArgs = new AvatarWearingArgs();
  3001. for (int i = 0; i < nowWearing.WearableData.Length; i++)
  3002. {
  3003. AvatarWearingArgs.Wearable wearable =
  3004. new AvatarWearingArgs.Wearable(nowWearing.WearableData[i].ItemID,
  3005. nowWearing.WearableData[i].WearableType);
  3006. wearingArgs.NowWearing.Add(wearable);
  3007. }
  3008. handlerAvatarNowWearing = OnAvatarNowWearing;
  3009. if (handlerAvatarNowWearing != null)
  3010. {
  3011. handlerAvatarNowWearing(this, wearingArgs);
  3012. }
  3013. }
  3014. break;
  3015. case PacketType.RezSingleAttachmentFromInv:
  3016. handlerRezSingleAttachment = OnRezSingleAttachmentFromInv;
  3017. if (handlerRezSingleAttachment != null)
  3018. {
  3019. RezSingleAttachmentFromInvPacket rez = (RezSingleAttachmentFromInvPacket)Pack;
  3020. handlerRezSingleAttachment(this, rez.ObjectData.ItemID,
  3021. rez.ObjectData.AttachmentPt, rez.ObjectData.ItemFlags, rez.ObjectData.NextOwnerMask);
  3022. }
  3023. break;
  3024. case PacketType.DetachAttachmentIntoInv:
  3025. handlerDetachAttachmentIntoInv = OnDetachAttachmentIntoInv;
  3026. if (handlerDetachAttachmentIntoInv != null)
  3027. {
  3028. DetachAttachmentIntoInvPacket detachtoInv = (DetachAttachmentIntoInvPacket)Pack;
  3029. LLUUID itemID = detachtoInv.ObjectData.ItemID;
  3030. LLUUID ATTACH_agentID = detachtoInv.ObjectData.AgentID;
  3031. handlerDetachAttachmentIntoInv(itemID, this);
  3032. }
  3033. break;
  3034. case PacketType.ObjectAttach:
  3035. if (OnObjectAttach != null)
  3036. {
  3037. ObjectAttachPacket att = (ObjectAttachPacket)Pack;
  3038. handlerObjectAttach = OnObjectAttach;
  3039. if (handlerObjectAttach != null)
  3040. {
  3041. if (att.ObjectData.Length > 0)
  3042. {
  3043. handlerObjectAttach(this, att.ObjectData[0].ObjectLocalID, att.AgentData.AttachmentPoint, att.ObjectData[0].Rotation);
  3044. }
  3045. }
  3046. }
  3047. break;
  3048. case PacketType.ObjectDetach:
  3049. ObjectDetachPacket dett = (ObjectDetachPacket)Pack;
  3050. for (int j = 0; j < dett.ObjectData.Length; j++)
  3051. {
  3052. uint obj = dett.ObjectData[j].ObjectLocalID;
  3053. handlerObjectDetach = OnObjectDetach;
  3054. if (handlerObjectDetach != null)
  3055. {
  3056. handlerObjectDetach(obj,this);
  3057. }
  3058. }
  3059. break;
  3060. case PacketType.SetAlwaysRun:
  3061. SetAlwaysRunPacket run = (SetAlwaysRunPacket)Pack;
  3062. handlerSetAlwaysRun = OnSetAlwaysRun;
  3063. if (handlerSetAlwaysRun != null)
  3064. handlerSetAlwaysRun(this, run.AgentData.AlwaysRun);
  3065. break;
  3066. case PacketType.CompleteAgentMovement:
  3067. handlerCompleteMovementToRegion = OnCompleteMovementToRegion;
  3068. if (handlerCompleteMovementToRegion != null)
  3069. {
  3070. handlerCompleteMovementToRegion();
  3071. }
  3072. handlerCompleteMovementToRegion = null;
  3073. break;
  3074. case PacketType.AgentUpdate:
  3075. if (OnAgentUpdate != null)
  3076. {
  3077. AgentUpdatePacket agenUpdate = (AgentUpdatePacket)Pack;
  3078. handlerAgentUpdate = OnAgentUpdate;
  3079. if (handlerAgentUpdate != null)
  3080. OnAgentUpdate(this, agenUpdate);
  3081. handlerAgentUpdate = null;
  3082. //agenUpdate.AgentData.ControlFlags, agenUpdate.AgentData.BodyRotationa);
  3083. }
  3084. break;
  3085. case PacketType.AgentAnimation:
  3086. AgentAnimationPacket AgentAni = (AgentAnimationPacket)Pack;
  3087. handlerStartAnim = null;
  3088. handlerStopAnim = null;
  3089. for (int i = 0; i < AgentAni.AnimationList.Length; i++)
  3090. {
  3091. if (AgentAni.AnimationList[i].StartAnim)
  3092. {
  3093. handlerStartAnim = OnStartAnim;
  3094. if (handlerStartAnim != null)
  3095. {
  3096. handlerStartAnim(this, AgentAni.AnimationList[i].AnimID);
  3097. }
  3098. }
  3099. else
  3100. {
  3101. handlerStopAnim = OnStopAnim;
  3102. if (handlerStopAnim != null)
  3103. {
  3104. handlerStopAnim(this, AgentAni.AnimationList[i].AnimID);
  3105. }
  3106. }
  3107. }
  3108. break;
  3109. case PacketType.AgentRequestSit:
  3110. if (OnAgentRequestSit != null)
  3111. {
  3112. AgentRequestSitPacket agentRequestSit = (AgentRequestSitPacket)Pack;
  3113. handlerAgentRequestSit = OnAgentRequestSit;
  3114. if (handlerAgentRequestSit != null)
  3115. handlerAgentRequestSit(this, agentRequestSit.AgentData.AgentID,
  3116. agentRequestSit.TargetObject.TargetID, agentRequestSit.TargetObject.Offset);
  3117. }
  3118. break;
  3119. case PacketType.AgentSit:
  3120. if (OnAgentSit != null)
  3121. {
  3122. AgentSitPacket agentSit = (AgentSitPacket)Pack;
  3123. handlerAgentSit = OnAgentSit;
  3124. if (handlerAgentSit != null)
  3125. {
  3126. OnAgentSit(this, agentSit.AgentData.AgentID);
  3127. }
  3128. }
  3129. break;
  3130. case PacketType.AvatarPickerRequest:
  3131. AvatarPickerRequestPacket avRequestQuery = (AvatarPickerRequestPacket)Pack;
  3132. AvatarPickerRequestPacket.AgentDataBlock Requestdata = avRequestQuery.AgentData;
  3133. AvatarPickerRequestPacket.DataBlock querydata = avRequestQuery.Data;
  3134. //Console.WriteLine("Agent Sends:" + Helpers.FieldToUTF8String(querydata.Name));
  3135. handlerAvatarPickerRequest = OnAvatarPickerRequest;
  3136. if (handlerAvatarPickerRequest != null)
  3137. {
  3138. handlerAvatarPickerRequest(this, Requestdata.AgentID, Requestdata.QueryID,
  3139. Helpers.FieldToUTF8String(querydata.Name));
  3140. }
  3141. break;
  3142. case PacketType.AgentDataUpdateRequest:
  3143. AgentDataUpdateRequestPacket avRequestDataUpdatePacket = (AgentDataUpdateRequestPacket)Pack;
  3144. handlerAgentDataUpdateRequest = OnAgentDataUpdateRequest;
  3145. if (handlerAgentDataUpdateRequest != null)
  3146. {
  3147. handlerAgentDataUpdateRequest(this, avRequestDataUpdatePacket.AgentData.AgentID, avRequestDataUpdatePacket.AgentData.SessionID);
  3148. }
  3149. break;
  3150. case PacketType.UserInfoRequest:
  3151. UserInfoRequestPacket avUserInfoRequestPacket = (UserInfoRequestPacket)Pack;
  3152. handlerUserInfoRequest = OnUserInfoRequest;
  3153. if (handlerUserInfoRequest != null)
  3154. {
  3155. handlerUserInfoRequest(this, avUserInfoRequestPacket.AgentData.AgentID, avUserInfoRequestPacket.AgentData.SessionID);
  3156. }
  3157. break;
  3158. case PacketType.SetStartLocationRequest:
  3159. SetStartLocationRequestPacket avSetStartLocationRequestPacket = (SetStartLocationRequestPacket)Pack;
  3160. if (avSetStartLocationRequestPacket.AgentData.AgentID == AgentId && avSetStartLocationRequestPacket.AgentData.SessionID == SessionId)
  3161. {
  3162. handlerSetStartLocationRequest = OnSetStartLocationRequest;
  3163. if (handlerSetStartLocationRequest != null)
  3164. {
  3165. handlerSetStartLocationRequest(this, 0, avSetStartLocationRequestPacket.StartLocationData.LocationPos,
  3166. avSetStartLocationRequestPacket.StartLocationData.LocationLookAt,
  3167. avSetStartLocationRequestPacket.StartLocationData.LocationID);
  3168. }
  3169. }
  3170. break;
  3171. case PacketType.AgentThrottle:
  3172. AgentThrottlePacket atpack = (AgentThrottlePacket)Pack;
  3173. m_packetQueue.SetThrottleFromClient(atpack.Throttle.Throttles);
  3174. break;
  3175. case PacketType.AgentPause:
  3176. m_probesWithNoIngressPackets = 0;
  3177. m_clientBlocked = true;
  3178. break;
  3179. case PacketType.AgentResume:
  3180. m_probesWithNoIngressPackets = 0;
  3181. m_clientBlocked = false;
  3182. SendStartPingCheck(0);
  3183. break;
  3184. #endregion
  3185. #region Objects/m_sceneObjects
  3186. case PacketType.ObjectLink:
  3187. ObjectLinkPacket link = (ObjectLinkPacket)Pack;
  3188. uint parentprimid = 0;
  3189. List<uint> childrenprims = new List<uint>();
  3190. if (link.ObjectData.Length > 1)
  3191. {
  3192. parentprimid = link.ObjectData[0].ObjectLocalID;
  3193. for (int i = 1; i < link.ObjectData.Length; i++)
  3194. {
  3195. childrenprims.Add(link.ObjectData[i].ObjectLocalID);
  3196. }
  3197. }
  3198. handlerLinkObjects = OnLinkObjects;
  3199. if (handlerLinkObjects != null)
  3200. {
  3201. handlerLinkObjects(this, parentprimid, childrenprims);
  3202. }
  3203. break;
  3204. case PacketType.ObjectDelink:
  3205. ObjectDelinkPacket delink = (ObjectDelinkPacket)Pack;
  3206. // It appears the prim at index 0 is not always the root prim (for
  3207. // instance, when one prim of a link set has been edited independently
  3208. // of the others). Therefore, we'll pass all the ids onto the delink
  3209. // method for it to decide which is the root.
  3210. List<uint> prims = new List<uint>();
  3211. for (int i = 0; i < delink.ObjectData.Length; i++)
  3212. {
  3213. prims.Add(delink.ObjectData[i].ObjectLocalID);
  3214. }
  3215. handlerDelinkObjects = OnDelinkObjects;
  3216. if (handlerDelinkObjects != null)
  3217. {
  3218. handlerDelinkObjects(prims);
  3219. }
  3220. break;
  3221. case PacketType.ObjectAdd:
  3222. if (OnAddPrim != null)
  3223. {
  3224. ObjectAddPacket addPacket = (ObjectAddPacket)Pack;
  3225. PrimitiveBaseShape shape = GetShapeFromAddPacket(addPacket);
  3226. // m_log.Info("[REZData]: " + addPacket.ToString());
  3227. //BypassRaycast: 1
  3228. //RayStart: <69.79469, 158.2652, 98.40343>
  3229. //RayEnd: <61.97724, 141.995, 92.58341>
  3230. //RayTargetID: 00000000-0000-0000-0000-000000000000
  3231. handlerAddPrim = OnAddPrim;
  3232. if (handlerAddPrim != null)
  3233. handlerAddPrim(AgentId, addPacket.ObjectData.RayEnd, addPacket.ObjectData.Rotation, shape, addPacket.ObjectData.BypassRaycast, addPacket.ObjectData.RayStart, addPacket.ObjectData.RayTargetID, addPacket.ObjectData.RayEndIsIntersection);
  3234. }
  3235. break;
  3236. case PacketType.ObjectShape:
  3237. ObjectShapePacket shapePacket = (ObjectShapePacket)Pack;
  3238. handlerUpdatePrimShape = null;
  3239. for (int i = 0; i < shapePacket.ObjectData.Length; i++)
  3240. {
  3241. handlerUpdatePrimShape = OnUpdatePrimShape;
  3242. if (handlerUpdatePrimShape != null)
  3243. {
  3244. handlerUpdatePrimShape(m_agentId, shapePacket.ObjectData[i].ObjectLocalID,
  3245. shapePacket.ObjectData[i]);
  3246. }
  3247. }
  3248. break;
  3249. case PacketType.ObjectExtraParams:
  3250. ObjectExtraParamsPacket extraPar = (ObjectExtraParamsPacket)Pack;
  3251. handlerUpdateExtraParams = OnUpdateExtraParams;
  3252. if (handlerUpdateExtraParams != null)
  3253. {
  3254. handlerUpdateExtraParams(m_agentId, extraPar.ObjectData[0].ObjectLocalID,
  3255. extraPar.ObjectData[0].ParamType,
  3256. extraPar.ObjectData[0].ParamInUse, extraPar.ObjectData[0].ParamData);
  3257. }
  3258. break;
  3259. case PacketType.ObjectDuplicate:
  3260. ObjectDuplicatePacket dupe = (ObjectDuplicatePacket)Pack;
  3261. ObjectDuplicatePacket.AgentDataBlock AgentandGroupData = dupe.AgentData;
  3262. handlerObjectDuplicate = null;
  3263. for (int i = 0; i < dupe.ObjectData.Length; i++)
  3264. {
  3265. handlerObjectDuplicate = OnObjectDuplicate;
  3266. if (handlerObjectDuplicate != null)
  3267. {
  3268. handlerObjectDuplicate(dupe.ObjectData[i].ObjectLocalID, dupe.SharedData.Offset,
  3269. dupe.SharedData.DuplicateFlags, AgentandGroupData.AgentID,
  3270. AgentandGroupData.GroupID);
  3271. }
  3272. }
  3273. break;
  3274. case PacketType.ObjectSelect:
  3275. ObjectSelectPacket incomingselect = (ObjectSelectPacket)Pack;
  3276. handlerObjectSelect = null;
  3277. for (int i = 0; i < incomingselect.ObjectData.Length; i++)
  3278. {
  3279. handlerObjectSelect = OnObjectSelect;
  3280. if (handlerObjectSelect != null)
  3281. {
  3282. handlerObjectSelect(incomingselect.ObjectData[i].ObjectLocalID, this);
  3283. }
  3284. }
  3285. break;
  3286. case PacketType.ObjectDeselect:
  3287. ObjectDeselectPacket incomingdeselect = (ObjectDeselectPacket)Pack;
  3288. handlerObjectDeselect = null;
  3289. for (int i = 0; i < incomingdeselect.ObjectData.Length; i++)
  3290. {
  3291. handlerObjectDeselect = OnObjectDeselect;
  3292. if (handlerObjectDeselect != null)
  3293. {
  3294. OnObjectDeselect(incomingdeselect.ObjectData[i].ObjectLocalID, this);
  3295. }
  3296. }
  3297. break;
  3298. case PacketType.ObjectFlagUpdate:
  3299. ObjectFlagUpdatePacket flags = (ObjectFlagUpdatePacket)Pack;
  3300. handlerUpdatePrimFlags = OnUpdatePrimFlags;
  3301. if (handlerUpdatePrimFlags != null)
  3302. {
  3303. handlerUpdatePrimFlags(flags.AgentData.ObjectLocalID, Pack, this);
  3304. }
  3305. break;
  3306. case PacketType.ObjectImage:
  3307. ObjectImagePacket imagePack = (ObjectImagePacket)Pack;
  3308. handlerUpdatePrimTexture = null;
  3309. for (int i = 0; i < imagePack.ObjectData.Length; i++)
  3310. {
  3311. handlerUpdatePrimTexture = OnUpdatePrimTexture;
  3312. if (handlerUpdatePrimTexture != null)
  3313. {
  3314. handlerUpdatePrimTexture(imagePack.ObjectData[i].ObjectLocalID,
  3315. imagePack.ObjectData[i].TextureEntry, this);
  3316. }
  3317. }
  3318. break;
  3319. case PacketType.ObjectGrab:
  3320. ObjectGrabPacket grab = (ObjectGrabPacket)Pack;
  3321. handlerGrabObject = OnGrabObject;
  3322. if (handlerGrabObject != null)
  3323. {
  3324. handlerGrabObject(grab.ObjectData.LocalID, grab.ObjectData.GrabOffset, this);
  3325. }
  3326. break;
  3327. case PacketType.ObjectGrabUpdate:
  3328. ObjectGrabUpdatePacket grabUpdate = (ObjectGrabUpdatePacket)Pack;
  3329. handlerGrabUpdate = OnGrabUpdate;
  3330. if (handlerGrabUpdate != null)
  3331. {
  3332. handlerGrabUpdate(grabUpdate.ObjectData.ObjectID, grabUpdate.ObjectData.GrabOffsetInitial,
  3333. grabUpdate.ObjectData.GrabPosition, this);
  3334. }
  3335. break;
  3336. case PacketType.ObjectDeGrab:
  3337. ObjectDeGrabPacket deGrab = (ObjectDeGrabPacket)Pack;
  3338. handlerDeGrabObject = OnDeGrabObject;
  3339. if (handlerDeGrabObject != null)
  3340. {
  3341. handlerDeGrabObject(deGrab.ObjectData.LocalID, this);
  3342. }
  3343. break;
  3344. case PacketType.ObjectDescription:
  3345. ObjectDescriptionPacket objDes = (ObjectDescriptionPacket)Pack;
  3346. handlerObjectDescription = null;
  3347. for (int i = 0; i < objDes.ObjectData.Length; i++)
  3348. {
  3349. handlerObjectDescription = OnObjectDescription;
  3350. if (handlerObjectDescription != null)
  3351. {
  3352. handlerObjectDescription(this, objDes.ObjectData[i].LocalID,
  3353. Util.FieldToString(objDes.ObjectData[i].Description));
  3354. }
  3355. }
  3356. break;
  3357. case PacketType.ObjectName:
  3358. ObjectNamePacket objName = (ObjectNamePacket)Pack;
  3359. handlerObjectName = null;
  3360. for (int i = 0; i < objName.ObjectData.Length; i++)
  3361. {
  3362. handlerObjectName = OnObjectName;
  3363. if (handlerObjectName != null)
  3364. {
  3365. handlerObjectName(this, objName.ObjectData[i].LocalID,
  3366. Util.FieldToString(objName.ObjectData[i].Name));
  3367. }
  3368. }
  3369. break;
  3370. case PacketType.ObjectPermissions:
  3371. if (OnObjectPermissions != null)
  3372. {
  3373. ObjectPermissionsPacket newobjPerms = (ObjectPermissionsPacket)Pack;
  3374. LLUUID AgentID = newobjPerms.AgentData.AgentID;
  3375. LLUUID SessionID = newobjPerms.AgentData.SessionID;
  3376. handlerObjectPermissions = null;
  3377. for (int i = 0; i < newobjPerms.ObjectData.Length; i++)
  3378. {
  3379. ObjectPermissionsPacket.ObjectDataBlock permChanges = newobjPerms.ObjectData[i];
  3380. byte field = permChanges.Field;
  3381. uint localID = permChanges.ObjectLocalID;
  3382. uint mask = permChanges.Mask;
  3383. byte set = permChanges.Set;
  3384. handlerObjectPermissions = OnObjectPermissions;
  3385. if (handlerObjectPermissions != null)
  3386. OnObjectPermissions(this, AgentID, SessionID, field, localID, mask, set);
  3387. }
  3388. }
  3389. // Here's our data,
  3390. // PermField contains the field the info goes into
  3391. // PermField determines which mask we're changing
  3392. //
  3393. // chmask is the mask of the change
  3394. // setTF is whether we're adding it or taking it away
  3395. //
  3396. // objLocalID is the localID of the object.
  3397. // Unfortunately, we have to pass the event the packet because objData is an array
  3398. // That means multiple object perms may be updated in a single packet.
  3399. break;
  3400. case PacketType.Undo:
  3401. UndoPacket undoitem = (UndoPacket)Pack;
  3402. if (undoitem.ObjectData.Length > 0)
  3403. {
  3404. for (int i = 0; i < undoitem.ObjectData.Length; i++)
  3405. {
  3406. LLUUID objiD = undoitem.ObjectData[i].ObjectID;
  3407. handlerOnUndo = OnUndo;
  3408. if (handlerOnUndo != null)
  3409. {
  3410. handlerOnUndo(this, objiD);
  3411. }
  3412. }
  3413. }
  3414. break;
  3415. case PacketType.ObjectDuplicateOnRay:
  3416. ObjectDuplicateOnRayPacket dupeOnRay = (ObjectDuplicateOnRayPacket)Pack;
  3417. handlerObjectDuplicateOnRay = null;
  3418. for (int i = 0; i < dupeOnRay.ObjectData.Length; i++)
  3419. {
  3420. handlerObjectDuplicateOnRay = OnObjectDuplicateOnRay;
  3421. if (handlerObjectDuplicateOnRay != null)
  3422. {
  3423. handlerObjectDuplicateOnRay(dupeOnRay.ObjectData[i].ObjectLocalID, dupeOnRay.AgentData.DuplicateFlags,
  3424. dupeOnRay.AgentData.AgentID, dupeOnRay.AgentData.GroupID, dupeOnRay.AgentData.RayTargetID, dupeOnRay.AgentData.RayEnd,
  3425. dupeOnRay.AgentData.RayStart, dupeOnRay.AgentData.BypassRaycast, dupeOnRay.AgentData.RayEndIsIntersection,
  3426. dupeOnRay.AgentData.CopyCenters, dupeOnRay.AgentData.CopyRotates);
  3427. }
  3428. }
  3429. break;
  3430. case PacketType.RequestObjectPropertiesFamily:
  3431. //This powers the little tooltip that appears when you move your mouse over an object
  3432. RequestObjectPropertiesFamilyPacket packToolTip = (RequestObjectPropertiesFamilyPacket)Pack;
  3433. RequestObjectPropertiesFamilyPacket.ObjectDataBlock packObjBlock = packToolTip.ObjectData;
  3434. handlerRequestObjectPropertiesFamily = OnRequestObjectPropertiesFamily;
  3435. if (handlerRequestObjectPropertiesFamily != null)
  3436. {
  3437. handlerRequestObjectPropertiesFamily(this, m_agentId, packObjBlock.RequestFlags,
  3438. packObjBlock.ObjectID);
  3439. }
  3440. break;
  3441. case PacketType.ObjectIncludeInSearch:
  3442. //This lets us set objects to appear in search (stuff like DataSnapshot, etc)
  3443. ObjectIncludeInSearchPacket packInSearch = (ObjectIncludeInSearchPacket)Pack;
  3444. handlerObjectIncludeInSearch = null;
  3445. foreach (ObjectIncludeInSearchPacket.ObjectDataBlock objData in packInSearch.ObjectData) {
  3446. bool inSearch = objData.IncludeInSearch;
  3447. uint localID = objData.ObjectLocalID;
  3448. handlerObjectIncludeInSearch = OnObjectIncludeInSearch;
  3449. if (handlerObjectIncludeInSearch != null) {
  3450. handlerObjectIncludeInSearch(this, inSearch, localID);
  3451. }
  3452. }
  3453. break;
  3454. case PacketType.ScriptAnswerYes:
  3455. ScriptAnswerYesPacket scriptAnswer = (ScriptAnswerYesPacket)Pack;
  3456. handlerScriptAnswer = OnScriptAnswer;
  3457. if (handlerScriptAnswer != null)
  3458. {
  3459. handlerScriptAnswer(this, scriptAnswer.Data.TaskID, scriptAnswer.Data.ItemID, scriptAnswer.Data.Questions);
  3460. }
  3461. break;
  3462. #endregion
  3463. #region Inventory/Asset/Other related packets
  3464. case PacketType.RequestImage:
  3465. RequestImagePacket imageRequest = (RequestImagePacket)Pack;
  3466. //Console.WriteLine("image request: " + Pack.ToString());
  3467. handlerTextureRequest = null;
  3468. for (int i = 0; i < imageRequest.RequestImage.Length; i++)
  3469. {
  3470. if (OnRequestTexture != null)
  3471. {
  3472. TextureRequestArgs args = new TextureRequestArgs();
  3473. args.RequestedAssetID = imageRequest.RequestImage[i].Image;
  3474. args.DiscardLevel = imageRequest.RequestImage[i].DiscardLevel;
  3475. args.PacketNumber = imageRequest.RequestImage[i].Packet;
  3476. args.Priority = imageRequest.RequestImage[i].DownloadPriority;
  3477. handlerTextureRequest = OnRequestTexture;
  3478. if (handlerTextureRequest != null)
  3479. OnRequestTexture(this, args);
  3480. }
  3481. }
  3482. break;
  3483. case PacketType.TransferRequest:
  3484. //Console.WriteLine("ClientView.ProcessPackets.cs:ProcessInPacket() - Got transfer request");
  3485. TransferRequestPacket transfer = (TransferRequestPacket)Pack;
  3486. m_assetCache.AddAssetRequest(this, transfer);
  3487. /* RequestAsset = OnRequestAsset;
  3488. if (RequestAsset != null)
  3489. {
  3490. RequestAsset(this, transfer);
  3491. }*/
  3492. break;
  3493. case PacketType.AssetUploadRequest:
  3494. AssetUploadRequestPacket request = (AssetUploadRequestPacket)Pack;
  3495. // Console.WriteLine("upload request " + Pack.ToString());
  3496. // Console.WriteLine("upload request was for assetid: " + request.AssetBlock.TransactionID.Combine(this.SecureSessionId).ToString());
  3497. LLUUID temp = LLUUID.Combine(request.AssetBlock.TransactionID, SecureSessionId);
  3498. handlerAssetUploadRequest = OnAssetUploadRequest;
  3499. if (handlerAssetUploadRequest != null)
  3500. {
  3501. handlerAssetUploadRequest(this, temp,
  3502. request.AssetBlock.TransactionID, request.AssetBlock.Type,
  3503. request.AssetBlock.AssetData, request.AssetBlock.StoreLocal,
  3504. request.AssetBlock.Tempfile);
  3505. }
  3506. break;
  3507. case PacketType.RequestXfer:
  3508. RequestXferPacket xferReq = (RequestXferPacket)Pack;
  3509. handlerRequestXfer = OnRequestXfer;
  3510. if (handlerRequestXfer != null)
  3511. {
  3512. handlerRequestXfer(this, xferReq.XferID.ID, Util.FieldToString(xferReq.XferID.Filename));
  3513. }
  3514. break;
  3515. case PacketType.SendXferPacket:
  3516. SendXferPacketPacket xferRec = (SendXferPacketPacket)Pack;
  3517. handlerXferReceive = OnXferReceive;
  3518. if (handlerXferReceive != null)
  3519. {
  3520. handlerXferReceive(this, xferRec.XferID.ID, xferRec.XferID.Packet, xferRec.DataPacket.Data);
  3521. }
  3522. break;
  3523. case PacketType.ConfirmXferPacket:
  3524. ConfirmXferPacketPacket confirmXfer = (ConfirmXferPacketPacket)Pack;
  3525. handlerConfirmXfer = OnConfirmXfer;
  3526. if (handlerConfirmXfer != null)
  3527. {
  3528. handlerConfirmXfer(this, confirmXfer.XferID.ID, confirmXfer.XferID.Packet);
  3529. }
  3530. break;
  3531. case PacketType.CreateInventoryFolder:
  3532. CreateInventoryFolderPacket invFolder = (CreateInventoryFolderPacket)Pack;
  3533. handlerCreateInventoryFolder = OnCreateNewInventoryFolder;
  3534. if (handlerCreateInventoryFolder != null)
  3535. {
  3536. handlerCreateInventoryFolder(this, invFolder.FolderData.FolderID,
  3537. (ushort)invFolder.FolderData.Type,
  3538. Util.FieldToString(invFolder.FolderData.Name),
  3539. invFolder.FolderData.ParentID);
  3540. }
  3541. break;
  3542. case PacketType.UpdateInventoryFolder:
  3543. if (OnUpdateInventoryFolder != null)
  3544. {
  3545. UpdateInventoryFolderPacket invFolderx = (UpdateInventoryFolderPacket)Pack;
  3546. handlerUpdateInventoryFolder = null;
  3547. for (int i = 0; i < invFolderx.FolderData.Length; i++)
  3548. {
  3549. handlerUpdateInventoryFolder = OnUpdateInventoryFolder;
  3550. if (handlerUpdateInventoryFolder != null)
  3551. {
  3552. OnUpdateInventoryFolder(this, invFolderx.FolderData[i].FolderID,
  3553. (ushort)invFolderx.FolderData[i].Type,
  3554. Util.FieldToString(invFolderx.FolderData[i].Name),
  3555. invFolderx.FolderData[i].ParentID);
  3556. }
  3557. }
  3558. }
  3559. break;
  3560. case PacketType.MoveInventoryFolder:
  3561. if (OnMoveInventoryFolder != null)
  3562. {
  3563. MoveInventoryFolderPacket invFoldery = (MoveInventoryFolderPacket)Pack;
  3564. handlerMoveInventoryFolder = null;
  3565. for (int i = 0; i < invFoldery.InventoryData.Length; i++)
  3566. {
  3567. handlerMoveInventoryFolder = OnMoveInventoryFolder;
  3568. if (handlerMoveInventoryFolder != null)
  3569. {
  3570. OnMoveInventoryFolder(this, invFoldery.InventoryData[i].FolderID,
  3571. invFoldery.InventoryData[i].ParentID);
  3572. }
  3573. }
  3574. }
  3575. break;
  3576. case PacketType.CreateInventoryItem:
  3577. CreateInventoryItemPacket createItem = (CreateInventoryItemPacket)Pack;
  3578. handlerCreateNewInventoryItem = OnCreateNewInventoryItem;
  3579. if (handlerCreateNewInventoryItem != null)
  3580. {
  3581. handlerCreateNewInventoryItem(this, createItem.InventoryBlock.TransactionID,
  3582. createItem.InventoryBlock.FolderID,
  3583. createItem.InventoryBlock.CallbackID,
  3584. Util.FieldToString(createItem.InventoryBlock.Description),
  3585. Util.FieldToString(createItem.InventoryBlock.Name),
  3586. createItem.InventoryBlock.InvType,
  3587. createItem.InventoryBlock.Type,
  3588. createItem.InventoryBlock.WearableType,
  3589. createItem.InventoryBlock.NextOwnerMask);
  3590. }
  3591. break;
  3592. case PacketType.FetchInventory:
  3593. if (OnFetchInventory != null)
  3594. {
  3595. FetchInventoryPacket FetchInventoryx = (FetchInventoryPacket)Pack;
  3596. handlerFetchInventory = null;
  3597. for (int i = 0; i < FetchInventoryx.InventoryData.Length; i++)
  3598. {
  3599. handlerFetchInventory = OnFetchInventory;
  3600. if (handlerFetchInventory != null)
  3601. {
  3602. OnFetchInventory(this, FetchInventoryx.InventoryData[i].ItemID,
  3603. FetchInventoryx.InventoryData[i].OwnerID);
  3604. }
  3605. }
  3606. }
  3607. break;
  3608. case PacketType.FetchInventoryDescendents:
  3609. FetchInventoryDescendentsPacket Fetch = (FetchInventoryDescendentsPacket)Pack;
  3610. handlerFetchInventoryDescendents = OnFetchInventoryDescendents;
  3611. if (handlerFetchInventoryDescendents != null)
  3612. {
  3613. handlerFetchInventoryDescendents(this, Fetch.InventoryData.FolderID, Fetch.InventoryData.OwnerID,
  3614. Fetch.InventoryData.FetchFolders, Fetch.InventoryData.FetchItems,
  3615. Fetch.InventoryData.SortOrder);
  3616. }
  3617. break;
  3618. case PacketType.PurgeInventoryDescendents:
  3619. PurgeInventoryDescendentsPacket Purge = (PurgeInventoryDescendentsPacket)Pack;
  3620. handlerPurgeInventoryDescendents = OnPurgeInventoryDescendents;
  3621. if (handlerPurgeInventoryDescendents != null)
  3622. {
  3623. handlerPurgeInventoryDescendents(this, Purge.InventoryData.FolderID);
  3624. }
  3625. break;
  3626. case PacketType.UpdateInventoryItem:
  3627. UpdateInventoryItemPacket update = (UpdateInventoryItemPacket)Pack;
  3628. if (OnUpdateInventoryItem != null)
  3629. {
  3630. handlerUpdateInventoryItem = null;
  3631. for (int i = 0; i < update.InventoryData.Length; i++)
  3632. {
  3633. handlerUpdateInventoryItem = OnUpdateInventoryItem;
  3634. if (handlerUpdateInventoryItem != null)
  3635. {
  3636. InventoryItemBase itemUpd = new InventoryItemBase();
  3637. itemUpd.ID = update.InventoryData[i].ItemID;
  3638. itemUpd.Name = Util.FieldToString(update.InventoryData[i].Name);
  3639. itemUpd.Description = Util.FieldToString(update.InventoryData[i].Description);
  3640. itemUpd.GroupID = update.InventoryData[i].GroupID;
  3641. itemUpd.GroupOwned = update.InventoryData[i].GroupOwned;
  3642. itemUpd.NextPermissions = update.InventoryData[i].NextOwnerMask;
  3643. itemUpd.EveryOnePermissions = update.InventoryData[i].EveryoneMask;
  3644. itemUpd.CreationDate = update.InventoryData[i].CreationDate;
  3645. itemUpd.Folder = update.InventoryData[i].FolderID;
  3646. itemUpd.InvType = update.InventoryData[i].InvType;
  3647. itemUpd.SalePrice = update.InventoryData[i].SalePrice;
  3648. itemUpd.SaleType = update.InventoryData[i].SaleType;
  3649. itemUpd.Flags = update.InventoryData[i].Flags;
  3650. /*
  3651. OnUpdateInventoryItem(this, update.InventoryData[i].TransactionID,
  3652. update.InventoryData[i].ItemID,
  3653. Util.FieldToString(update.InventoryData[i].Name),
  3654. Util.FieldToString(update.InventoryData[i].Description),
  3655. update.InventoryData[i].NextOwnerMask);
  3656. */
  3657. OnUpdateInventoryItem(this, update.InventoryData[i].TransactionID,
  3658. update.InventoryData[i].ItemID,
  3659. itemUpd);
  3660. }
  3661. }
  3662. }
  3663. //Console.WriteLine(Pack.ToString());
  3664. /*for (int i = 0; i < update.InventoryData.Length; i++)
  3665. {
  3666. if (update.InventoryData[i].TransactionID != LLUUID.Zero)
  3667. {
  3668. AssetBase asset = m_assetCache.GetAsset(update.InventoryData[i].TransactionID.Combine(this.SecureSessionId));
  3669. if (asset != null)
  3670. {
  3671. // Console.WriteLine("updating inventory item, found asset" + asset.FullID.ToString() + " already in cache");
  3672. m_inventoryCache.UpdateInventoryItemAsset(this, update.InventoryData[i].ItemID, asset);
  3673. }
  3674. else
  3675. {
  3676. asset = this.UploadAssets.AddUploadToAssetCache(update.InventoryData[i].TransactionID);
  3677. if (asset != null)
  3678. {
  3679. //Console.WriteLine("updating inventory item, adding asset" + asset.FullID.ToString() + " to cache");
  3680. m_inventoryCache.UpdateInventoryItemAsset(this, update.InventoryData[i].ItemID, asset);
  3681. }
  3682. else
  3683. {
  3684. //Console.WriteLine("trying to update inventory item, but asset is null");
  3685. }
  3686. }
  3687. }
  3688. else
  3689. {
  3690. m_inventoryCache.UpdateInventoryItemDetails(this, update.InventoryData[i].ItemID, update.InventoryData[i]); ;
  3691. }
  3692. }*/
  3693. break;
  3694. case PacketType.CopyInventoryItem:
  3695. CopyInventoryItemPacket copyitem = (CopyInventoryItemPacket)Pack;
  3696. handlerCopyInventoryItem = null;
  3697. if (OnCopyInventoryItem != null)
  3698. {
  3699. foreach (CopyInventoryItemPacket.InventoryDataBlock datablock in copyitem.InventoryData)
  3700. {
  3701. handlerCopyInventoryItem = OnCopyInventoryItem;
  3702. if (handlerCopyInventoryItem != null)
  3703. {
  3704. handlerCopyInventoryItem(this, datablock.CallbackID, datablock.OldAgentID,
  3705. datablock.OldItemID, datablock.NewFolderID,
  3706. Util.FieldToString(datablock.NewName));
  3707. }
  3708. }
  3709. }
  3710. break;
  3711. case PacketType.MoveInventoryItem:
  3712. MoveInventoryItemPacket moveitem = (MoveInventoryItemPacket)Pack;
  3713. if (OnMoveInventoryItem != null)
  3714. {
  3715. handlerMoveInventoryItem = null;
  3716. foreach (MoveInventoryItemPacket.InventoryDataBlock datablock in moveitem.InventoryData)
  3717. {
  3718. handlerMoveInventoryItem = OnMoveInventoryItem;
  3719. if (handlerMoveInventoryItem != null)
  3720. {
  3721. handlerMoveInventoryItem(this, datablock.FolderID, datablock.ItemID, datablock.Length,
  3722. Util.FieldToString(datablock.NewName));
  3723. }
  3724. }
  3725. }
  3726. break;
  3727. case PacketType.RemoveInventoryItem:
  3728. RemoveInventoryItemPacket removeItem = (RemoveInventoryItemPacket)Pack;
  3729. if (OnRemoveInventoryItem != null)
  3730. {
  3731. handlerRemoveInventoryItem = null;
  3732. foreach (RemoveInventoryItemPacket.InventoryDataBlock datablock in removeItem.InventoryData)
  3733. {
  3734. handlerRemoveInventoryItem = OnRemoveInventoryItem;
  3735. if (handlerRemoveInventoryItem != null)
  3736. {
  3737. handlerRemoveInventoryItem(this, datablock.ItemID);
  3738. }
  3739. }
  3740. }
  3741. break;
  3742. case PacketType.RemoveInventoryFolder:
  3743. RemoveInventoryFolderPacket removeFolder = (RemoveInventoryFolderPacket)Pack;
  3744. if (OnRemoveInventoryFolder != null)
  3745. {
  3746. handlerRemoveInventoryFolder = null;
  3747. foreach (RemoveInventoryFolderPacket.FolderDataBlock datablock in removeFolder.FolderData)
  3748. {
  3749. handlerRemoveInventoryFolder = OnRemoveInventoryFolder;
  3750. if (handlerRemoveInventoryFolder != null)
  3751. {
  3752. handlerRemoveInventoryFolder(this, datablock.FolderID);
  3753. }
  3754. }
  3755. }
  3756. break;
  3757. case PacketType.RequestTaskInventory:
  3758. RequestTaskInventoryPacket requesttask = (RequestTaskInventoryPacket)Pack;
  3759. handlerRequestTaskInventory = OnRequestTaskInventory;
  3760. if (handlerRequestTaskInventory != null)
  3761. {
  3762. handlerRequestTaskInventory(this, requesttask.InventoryData.LocalID);
  3763. }
  3764. break;
  3765. case PacketType.UpdateTaskInventory:
  3766. UpdateTaskInventoryPacket updatetask = (UpdateTaskInventoryPacket)Pack;
  3767. if (OnUpdateTaskInventory != null)
  3768. {
  3769. if (updatetask.UpdateData.Key == 0)
  3770. {
  3771. handlerUpdateTaskInventory = OnUpdateTaskInventory;
  3772. if (handlerUpdateTaskInventory != null)
  3773. {
  3774. handlerUpdateTaskInventory(this, updatetask.InventoryData.ItemID,
  3775. updatetask.InventoryData.FolderID, updatetask.UpdateData.LocalID);
  3776. }
  3777. }
  3778. }
  3779. break;
  3780. case PacketType.RemoveTaskInventory:
  3781. RemoveTaskInventoryPacket removeTask = (RemoveTaskInventoryPacket)Pack;
  3782. handlerRemoveTaskItem = OnRemoveTaskItem;
  3783. if (handlerRemoveTaskItem != null)
  3784. {
  3785. handlerRemoveTaskItem(this, removeTask.InventoryData.ItemID, removeTask.InventoryData.LocalID);
  3786. }
  3787. break;
  3788. case PacketType.MoveTaskInventory:
  3789. MoveTaskInventoryPacket moveTaskInventoryPacket = (MoveTaskInventoryPacket)Pack;
  3790. handlerMoveTaskItem = OnMoveTaskItem;
  3791. if (handlerMoveTaskItem != null)
  3792. {
  3793. handlerMoveTaskItem(
  3794. this, moveTaskInventoryPacket.AgentData.FolderID,
  3795. moveTaskInventoryPacket.InventoryData.LocalID,
  3796. moveTaskInventoryPacket.InventoryData.ItemID);
  3797. }
  3798. break;
  3799. case PacketType.RezScript:
  3800. //Console.WriteLine(Pack.ToString());
  3801. RezScriptPacket rezScriptx = (RezScriptPacket)Pack;
  3802. handlerRezScript = OnRezScript;
  3803. if (handlerRezScript != null)
  3804. {
  3805. handlerRezScript(this, rezScriptx.InventoryBlock.ItemID, rezScriptx.UpdateBlock.ObjectLocalID);
  3806. }
  3807. break;
  3808. case PacketType.MapLayerRequest:
  3809. RequestMapLayer();
  3810. break;
  3811. case PacketType.MapBlockRequest:
  3812. MapBlockRequestPacket MapRequest = (MapBlockRequestPacket)Pack;
  3813. handlerRequestMapBlocks = OnRequestMapBlocks;
  3814. if (handlerRequestMapBlocks != null)
  3815. {
  3816. handlerRequestMapBlocks(this, MapRequest.PositionData.MinX, MapRequest.PositionData.MinY,
  3817. MapRequest.PositionData.MaxX, MapRequest.PositionData.MaxY);
  3818. }
  3819. break;
  3820. case PacketType.MapNameRequest:
  3821. MapNameRequestPacket map = (MapNameRequestPacket)Pack;
  3822. string mapName = UTF8Encoding.UTF8.GetString(map.NameData.Name, 0,
  3823. map.NameData.Name.Length - 1);
  3824. handlerMapNameRequest = OnMapNameRequest;
  3825. if (handlerMapNameRequest != null)
  3826. {
  3827. handlerMapNameRequest(this, mapName);
  3828. }
  3829. break;
  3830. case PacketType.TeleportLandmarkRequest:
  3831. TeleportLandmarkRequestPacket tpReq = (TeleportLandmarkRequestPacket)Pack;
  3832. LLUUID lmid = tpReq.Info.LandmarkID;
  3833. AssetLandmark lm;
  3834. if (lmid != LLUUID.Zero)
  3835. {
  3836. AssetBase lma = m_assetCache.GetAsset(lmid, false);
  3837. if (lma == null)
  3838. {
  3839. // Failed to find landmark
  3840. TeleportCancelPacket tpCancel = (TeleportCancelPacket)PacketPool.Instance.GetPacket(PacketType.TeleportCancel);
  3841. tpCancel.Info.SessionID = tpReq.Info.SessionID;
  3842. tpCancel.Info.AgentID = tpReq.Info.AgentID;
  3843. OutPacket(tpCancel, ThrottleOutPacketType.Task);
  3844. }
  3845. try
  3846. {
  3847. lm = new AssetLandmark(lma);
  3848. }
  3849. catch (NullReferenceException)
  3850. {
  3851. // asset not found generates null ref inside the assetlandmark constructor.
  3852. TeleportCancelPacket tpCancel = (TeleportCancelPacket)PacketPool.Instance.GetPacket(PacketType.TeleportCancel);
  3853. tpCancel.Info.SessionID = tpReq.Info.SessionID;
  3854. tpCancel.Info.AgentID = tpReq.Info.AgentID;
  3855. OutPacket(tpCancel, ThrottleOutPacketType.Task);
  3856. break;
  3857. }
  3858. }
  3859. else
  3860. {
  3861. // Teleport home request
  3862. handlerTeleportHomeRequest = OnTeleportHomeRequest;
  3863. if (handlerTeleportHomeRequest != null)
  3864. {
  3865. handlerTeleportHomeRequest(this.AgentId,this);
  3866. }
  3867. break;
  3868. }
  3869. handlerTeleportLandmarkRequest = OnTeleportLandmarkRequest;
  3870. if (handlerTeleportLandmarkRequest != null)
  3871. {
  3872. handlerTeleportLandmarkRequest(this, lm.RegionHandle, lm.Position);
  3873. }
  3874. else
  3875. {
  3876. //no event handler so cancel request
  3877. TeleportCancelPacket tpCancel = (TeleportCancelPacket)PacketPool.Instance.GetPacket(PacketType.TeleportCancel);
  3878. tpCancel.Info.AgentID = tpReq.Info.AgentID;
  3879. tpCancel.Info.SessionID = tpReq.Info.SessionID;
  3880. OutPacket(tpCancel, ThrottleOutPacketType.Task);
  3881. }
  3882. break;
  3883. case PacketType.TeleportLocationRequest:
  3884. TeleportLocationRequestPacket tpLocReq = (TeleportLocationRequestPacket)Pack;
  3885. // Console.WriteLine(tpLocReq.ToString());
  3886. handlerTeleportLocationRequest = OnTeleportLocationRequest;
  3887. if (handlerTeleportLocationRequest != null)
  3888. {
  3889. handlerTeleportLocationRequest(this, tpLocReq.Info.RegionHandle, tpLocReq.Info.Position,
  3890. tpLocReq.Info.LookAt, 16);
  3891. }
  3892. else
  3893. {
  3894. //no event handler so cancel request
  3895. TeleportCancelPacket tpCancel = (TeleportCancelPacket)PacketPool.Instance.GetPacket(PacketType.TeleportCancel);
  3896. tpCancel.Info.SessionID = tpLocReq.AgentData.SessionID;
  3897. tpCancel.Info.AgentID = tpLocReq.AgentData.AgentID;
  3898. OutPacket(tpCancel, ThrottleOutPacketType.Task);
  3899. }
  3900. break;
  3901. #endregion
  3902. case PacketType.UUIDNameRequest:
  3903. UUIDNameRequestPacket incoming = (UUIDNameRequestPacket)Pack;
  3904. foreach (UUIDNameRequestPacket.UUIDNameBlockBlock UUIDBlock in incoming.UUIDNameBlock)
  3905. {
  3906. handlerNameRequest = OnNameFromUUIDRequest;
  3907. if (handlerNameRequest != null)
  3908. {
  3909. handlerNameRequest(UUIDBlock.ID, this);
  3910. }
  3911. }
  3912. break;
  3913. #region Parcel related packets
  3914. case PacketType.ParcelAccessListRequest:
  3915. ParcelAccessListRequestPacket requestPacket = (ParcelAccessListRequestPacket)Pack;
  3916. handlerParcelAccessListRequest = OnParcelAccessListRequest;
  3917. if (handlerParcelAccessListRequest != null)
  3918. {
  3919. handlerParcelAccessListRequest(requestPacket.AgentData.AgentID, requestPacket.AgentData.SessionID,
  3920. requestPacket.Data.Flags, requestPacket.Data.SequenceID,
  3921. requestPacket.Data.LocalID, this);
  3922. }
  3923. break;
  3924. case PacketType.ParcelAccessListUpdate:
  3925. ParcelAccessListUpdatePacket updatePacket = (ParcelAccessListUpdatePacket)Pack;
  3926. List<ParcelManager.ParcelAccessEntry> entries = new List<ParcelManager.ParcelAccessEntry>();
  3927. foreach (ParcelAccessListUpdatePacket.ListBlock block in updatePacket.List)
  3928. {
  3929. ParcelManager.ParcelAccessEntry entry = new ParcelManager.ParcelAccessEntry();
  3930. entry.AgentID = block.ID;
  3931. entry.Flags = (ParcelManager.AccessList)block.Flags;
  3932. entry.Time = new DateTime();
  3933. entries.Add(entry);
  3934. }
  3935. handlerParcelAccessListUpdateRequest = OnParcelAccessListUpdateRequest;
  3936. if (handlerParcelAccessListUpdateRequest != null)
  3937. {
  3938. handlerParcelAccessListUpdateRequest(updatePacket.AgentData.AgentID,
  3939. updatePacket.AgentData.SessionID, updatePacket.Data.Flags,
  3940. updatePacket.Data.LocalID, entries, this);
  3941. }
  3942. break;
  3943. case PacketType.ParcelPropertiesRequest:
  3944. ParcelPropertiesRequestPacket propertiesRequest = (ParcelPropertiesRequestPacket)Pack;
  3945. handlerParcelPropertiesRequest = OnParcelPropertiesRequest;
  3946. if (handlerParcelPropertiesRequest != null)
  3947. {
  3948. handlerParcelPropertiesRequest((int)Math.Round(propertiesRequest.ParcelData.West),
  3949. (int)Math.Round(propertiesRequest.ParcelData.South),
  3950. (int)Math.Round(propertiesRequest.ParcelData.East),
  3951. (int)Math.Round(propertiesRequest.ParcelData.North),
  3952. propertiesRequest.ParcelData.SequenceID,
  3953. propertiesRequest.ParcelData.SnapSelection, this);
  3954. }
  3955. break;
  3956. case PacketType.ParcelDivide:
  3957. ParcelDividePacket landDivide = (ParcelDividePacket)Pack;
  3958. handlerParcelDivideRequest = OnParcelDivideRequest;
  3959. if (handlerParcelDivideRequest != null)
  3960. {
  3961. handlerParcelDivideRequest((int)Math.Round(landDivide.ParcelData.West),
  3962. (int)Math.Round(landDivide.ParcelData.South),
  3963. (int)Math.Round(landDivide.ParcelData.East),
  3964. (int)Math.Round(landDivide.ParcelData.North), this);
  3965. }
  3966. break;
  3967. case PacketType.ParcelJoin:
  3968. ParcelJoinPacket landJoin = (ParcelJoinPacket)Pack;
  3969. handlerParcelJoinRequest = OnParcelJoinRequest;
  3970. if (handlerParcelJoinRequest != null)
  3971. {
  3972. handlerParcelJoinRequest((int)Math.Round(landJoin.ParcelData.West),
  3973. (int)Math.Round(landJoin.ParcelData.South),
  3974. (int)Math.Round(landJoin.ParcelData.East),
  3975. (int)Math.Round(landJoin.ParcelData.North), this);
  3976. }
  3977. break;
  3978. case PacketType.ParcelPropertiesUpdate:
  3979. ParcelPropertiesUpdatePacket parcelPropertiesPacket = (ParcelPropertiesUpdatePacket)Pack;
  3980. handlerParcelPropertiesUpdateRequest = OnParcelPropertiesUpdateRequest;
  3981. if (handlerParcelPropertiesUpdateRequest != null)
  3982. {
  3983. handlerParcelPropertiesUpdateRequest(parcelPropertiesPacket, this);
  3984. }
  3985. break;
  3986. case PacketType.ParcelSelectObjects:
  3987. ParcelSelectObjectsPacket selectPacket = (ParcelSelectObjectsPacket)Pack;
  3988. handlerParcelSelectObjects = OnParcelSelectObjects;
  3989. if (handlerParcelSelectObjects != null)
  3990. {
  3991. handlerParcelSelectObjects(selectPacket.ParcelData.LocalID,
  3992. Convert.ToInt32(selectPacket.ParcelData.ReturnType), this);
  3993. }
  3994. break;
  3995. case PacketType.ParcelObjectOwnersRequest:
  3996. //Console.WriteLine(Pack.ToString());
  3997. ParcelObjectOwnersRequestPacket reqPacket = (ParcelObjectOwnersRequestPacket)Pack;
  3998. handlerParcelObjectOwnerRequest = OnParcelObjectOwnerRequest;
  3999. if (handlerParcelObjectOwnerRequest != null)
  4000. {
  4001. handlerParcelObjectOwnerRequest(reqPacket.ParcelData.LocalID, this);
  4002. }
  4003. break;
  4004. #endregion
  4005. #region Estate Packets
  4006. case PacketType.EstateOwnerMessage:
  4007. EstateOwnerMessagePacket messagePacket = (EstateOwnerMessagePacket)Pack;
  4008. handlerEstateOwnerMessage = OnEstateOwnerMessage;
  4009. if (handlerEstateOwnerMessage != null)
  4010. {
  4011. handlerEstateOwnerMessage(messagePacket, this);
  4012. }
  4013. break;
  4014. case PacketType.RequestRegionInfo:
  4015. RequestRegionInfoPacket.AgentDataBlock mPacket = ((RequestRegionInfoPacket)Pack).AgentData;
  4016. handlerRegionInfoRequest = OnRegionInfoRequest;
  4017. if (handlerRegionInfoRequest != null)
  4018. {
  4019. handlerRegionInfoRequest(this, mPacket.SessionID);
  4020. }
  4021. break;
  4022. case PacketType.EstateCovenantRequest:
  4023. EstateCovenantRequestPacket.AgentDataBlock epack =
  4024. ((EstateCovenantRequestPacket)Pack).AgentData;
  4025. handlerEstateCovenantRequest = OnEstateCovenantRequest;
  4026. if (handlerEstateCovenantRequest != null)
  4027. {
  4028. handlerEstateCovenantRequest(this, epack.SessionID);
  4029. }
  4030. break;
  4031. #endregion
  4032. #region GodPackets
  4033. case PacketType.RequestGodlikePowers:
  4034. RequestGodlikePowersPacket rglpPack = (RequestGodlikePowersPacket)Pack;
  4035. RequestGodlikePowersPacket.RequestBlockBlock rblock = rglpPack.RequestBlock;
  4036. LLUUID token = rblock.Token;
  4037. RequestGodlikePowersPacket.AgentDataBlock ablock = rglpPack.AgentData;
  4038. handlerReqGodlikePowers = OnRequestGodlikePowers;
  4039. if (handlerReqGodlikePowers != null)
  4040. {
  4041. handlerReqGodlikePowers(ablock.AgentID, ablock.SessionID, token, rblock.Godlike, this);
  4042. }
  4043. break;
  4044. case PacketType.GodKickUser:
  4045. m_log.Warn("[CLIENT]: unhandled GodKickUser packet");
  4046. GodKickUserPacket gkupack = (GodKickUserPacket)Pack;
  4047. if (gkupack.UserInfo.GodSessionID == SessionId && AgentId == gkupack.UserInfo.GodID)
  4048. {
  4049. handlerGodKickUser = OnGodKickUser;
  4050. if (handlerGodKickUser != null)
  4051. {
  4052. handlerGodKickUser(gkupack.UserInfo.GodID, gkupack.UserInfo.GodSessionID,
  4053. gkupack.UserInfo.AgentID, (uint)0, gkupack.UserInfo.Reason);
  4054. }
  4055. }
  4056. else
  4057. {
  4058. SendAgentAlertMessage("Kick request denied", false);
  4059. }
  4060. //KickUserPacket kupack = new KickUserPacket();
  4061. //KickUserPacket.UserInfoBlock kupackib = kupack.UserInfo;
  4062. //kupack.UserInfo.AgentID = gkupack.UserInfo.AgentID;
  4063. //kupack.UserInfo.SessionID = gkupack.UserInfo.GodSessionID;
  4064. //kupack.TargetBlock.TargetIP = (uint)0;
  4065. //kupack.TargetBlock.TargetPort = (ushort)0;
  4066. //kupack.UserInfo.Reason = gkupack.UserInfo.Reason;
  4067. //OutPacket(kupack, ThrottleOutPacketType.Task);
  4068. break;
  4069. #endregion
  4070. #region Economy/Transaction Packets
  4071. case PacketType.MoneyBalanceRequest:
  4072. MoneyBalanceRequestPacket moneybalancerequestpacket = (MoneyBalanceRequestPacket)Pack;
  4073. handlerMoneyBalanceRequest = OnMoneyBalanceRequest;
  4074. if (handlerMoneyBalanceRequest != null)
  4075. {
  4076. handlerMoneyBalanceRequest(this, moneybalancerequestpacket.AgentData.AgentID, moneybalancerequestpacket.AgentData.SessionID, moneybalancerequestpacket.MoneyData.TransactionID);
  4077. }
  4078. break;
  4079. case PacketType.EconomyDataRequest:
  4080. handlerEconomoyDataRequest = OnEconomyDataRequest;
  4081. if (handlerEconomoyDataRequest != null)
  4082. {
  4083. handlerEconomoyDataRequest(AgentId);
  4084. }
  4085. // TODO: handle this packet
  4086. //m_log.Warn("[CLIENT]: unhandled EconomyDataRequest packet");
  4087. break;
  4088. case PacketType.RequestPayPrice:
  4089. RequestPayPricePacket requestPayPricePacket = (RequestPayPricePacket)Pack;
  4090. handlerRequestPayPrice = OnRequestPayPrice;
  4091. if (handlerRequestPayPrice != null)
  4092. {
  4093. handlerRequestPayPrice(this, requestPayPricePacket.ObjectData.ObjectID);
  4094. }
  4095. break;
  4096. #endregion
  4097. #region unimplemented handlers
  4098. case PacketType.StartPingCheck:
  4099. // Send the client the ping response back
  4100. // Pass the same PingID in the matching packet
  4101. // Handled In the packet processing
  4102. //m_log.Debug("[CLIENT]: possibly unhandled StartPingCheck packet");
  4103. break;
  4104. case PacketType.CompletePingCheck:
  4105. // TODO: Perhaps this should be processed on the Sim to determine whether or not to drop a dead client
  4106. //m_log.Warn("[CLIENT]: unhandled CompletePingCheck packet");
  4107. break;
  4108. case PacketType.ObjectScale:
  4109. // TODO: handle this packet
  4110. m_log.Warn("[CLIENT]: unhandled ObjectScale packet");
  4111. break;
  4112. case PacketType.ViewerStats:
  4113. // TODO: handle this packet
  4114. m_log.Warn("[CLIENT]: unhandled ViewerStats packet");
  4115. break;
  4116. case PacketType.CreateGroupRequest:
  4117. // TODO: handle this packet
  4118. m_log.Warn("[CLIENT]: unhandled CreateGroupRequest packet");
  4119. break;
  4120. case PacketType.GenericMessage:
  4121. // TODO: handle this packet
  4122. m_log.Warn("[CLIENT]: unhandled GenericMessage packet");
  4123. break;
  4124. case PacketType.MapItemRequest:
  4125. // TODO: handle this packet
  4126. m_log.Warn("[CLIENT]: unhandled MapItemRequest packet");
  4127. break;
  4128. case PacketType.TransferAbort:
  4129. // TODO: handle this packet
  4130. m_log.Warn("[CLIENT]: unhandled TransferAbort packet");
  4131. break;
  4132. case PacketType.MuteListRequest:
  4133. // TODO: handle this packet
  4134. m_log.Warn("[CLIENT]: unhandled MuteListRequest packet");
  4135. break;
  4136. case PacketType.ParcelDwellRequest:
  4137. // TODO: handle this packet
  4138. m_log.Warn("[CLIENT]: unhandled ParcelDwellRequest packet");
  4139. break;
  4140. case PacketType.UseCircuitCode:
  4141. // TODO: Don't display this one, we handle it at a lower level
  4142. //m_log.Warn("[CLIENT]: unhandled UseCircuitCode packet");
  4143. break;
  4144. case PacketType.AgentHeightWidth:
  4145. // TODO: handle this packet
  4146. m_log.Warn("[CLIENT]: unhandled AgentHeightWidth packet");
  4147. break;
  4148. case PacketType.ObjectSpinStop:
  4149. // TODO: handle this packet
  4150. m_log.Warn("[CLIENT]: unhandled ObjectSpinStop packet");
  4151. break;
  4152. case PacketType.SoundTrigger:
  4153. // TODO: handle this packet
  4154. m_log.Warn("[CLIENT]: unhandled SoundTrigger packet");
  4155. break;
  4156. case PacketType.InventoryDescendents:
  4157. // TODO: handle this packet
  4158. m_log.Warn("[CLIENT]: unhandled InventoryDescent packet");
  4159. break;
  4160. case PacketType.GetScriptRunning:
  4161. m_log.Warn("[CLIENT]: unhandled GetScriptRunning packet");
  4162. break;
  4163. default:
  4164. m_log.Warn("[CLIENT]: unhandled packet " + Pack.ToString());
  4165. break;
  4166. #endregion
  4167. }
  4168. }
  4169. PacketPool.Instance.ReturnPacket(Pack);
  4170. }
  4171. private static PrimitiveBaseShape GetShapeFromAddPacket(ObjectAddPacket addPacket)
  4172. {
  4173. PrimitiveBaseShape shape = new PrimitiveBaseShape();
  4174. shape.PCode = addPacket.ObjectData.PCode;
  4175. shape.State = addPacket.ObjectData.State;
  4176. shape.PathBegin = addPacket.ObjectData.PathBegin;
  4177. shape.PathEnd = addPacket.ObjectData.PathEnd;
  4178. shape.PathScaleX = addPacket.ObjectData.PathScaleX;
  4179. shape.PathScaleY = addPacket.ObjectData.PathScaleY;
  4180. shape.PathShearX = addPacket.ObjectData.PathShearX;
  4181. shape.PathShearY = addPacket.ObjectData.PathShearY;
  4182. shape.PathSkew = addPacket.ObjectData.PathSkew;
  4183. shape.ProfileBegin = addPacket.ObjectData.ProfileBegin;
  4184. shape.ProfileEnd = addPacket.ObjectData.ProfileEnd;
  4185. shape.Scale = addPacket.ObjectData.Scale;
  4186. shape.PathCurve = addPacket.ObjectData.PathCurve;
  4187. shape.ProfileCurve = addPacket.ObjectData.ProfileCurve;
  4188. shape.ProfileHollow = addPacket.ObjectData.ProfileHollow;
  4189. shape.PathRadiusOffset = addPacket.ObjectData.PathRadiusOffset;
  4190. shape.PathRevolutions = addPacket.ObjectData.PathRevolutions;
  4191. shape.PathTaperX = addPacket.ObjectData.PathTaperX;
  4192. shape.PathTaperY = addPacket.ObjectData.PathTaperY;
  4193. shape.PathTwist = addPacket.ObjectData.PathTwist;
  4194. shape.PathTwistBegin = addPacket.ObjectData.PathTwistBegin;
  4195. LLObject.TextureEntry ntex = new LLObject.TextureEntry(new LLUUID("89556747-24cb-43ed-920b-47caed15465f"));
  4196. shape.TextureEntry = ntex.ToBytes();
  4197. //shape.Textures = ntex;
  4198. return shape;
  4199. }
  4200. public void SendBlueBoxMessage(LLUUID FromAvatarID, LLUUID fromSessionID, String FromAvatarName, String Message)
  4201. {
  4202. if (!ChildAgentStatus())
  4203. SendInstantMessage(FromAvatarID, fromSessionID, Message, AgentId, SessionId, FromAvatarName, (byte)1, (uint)Util.UnixTimeSinceEpoch());
  4204. //SendInstantMessage(FromAvatarID, fromSessionID, Message, AgentId, SessionId, FromAvatarName, (byte)21,(uint) Util.UnixTimeSinceEpoch());
  4205. }
  4206. public void SendLogoutPacket()
  4207. {
  4208. LogoutReplyPacket logReply = (LogoutReplyPacket)PacketPool.Instance.GetPacket(PacketType.LogoutReply);
  4209. // TODO: don't create new blocks if recycling an old packet
  4210. logReply.AgentData.AgentID = AgentId;
  4211. logReply.AgentData.SessionID = SessionId;
  4212. logReply.InventoryData = new LogoutReplyPacket.InventoryDataBlock[1];
  4213. logReply.InventoryData[0] = new LogoutReplyPacket.InventoryDataBlock();
  4214. logReply.InventoryData[0].ItemID = LLUUID.Zero;
  4215. OutPacket(logReply, ThrottleOutPacketType.Task);
  4216. }
  4217. public ClientInfo GetClientInfo()
  4218. {
  4219. //MainLog.Instance.Verbose("CLIENT", "GetClientInfo BGN");
  4220. ClientInfo info = new ClientInfo();
  4221. info.userEP = this.m_userEndPoint;
  4222. info.proxyEP = this.m_proxyEndPoint;
  4223. info.agentcircuit = new sAgentCircuitData(RequestClientInfo());
  4224. info.pendingAcks = m_pendingAcks;
  4225. info.needAck = new Dictionary<uint,byte[]>();
  4226. lock (m_needAck)
  4227. {
  4228. foreach (uint key in m_needAck.Keys)
  4229. {
  4230. info.needAck.Add(key, m_needAck[key].ToBytes());
  4231. }
  4232. }
  4233. /* pending
  4234. QueItem[] queitems = m_packetQueue.GetQueueArray();
  4235. MainLog.Instance.Verbose("CLIENT", "Queue Count : [{0}]", queitems.Length);
  4236. for (int i = 0; i < queitems.Length; i++)
  4237. {
  4238. if (queitems[i].Incoming == false)
  4239. {
  4240. info.out_packets.Add(queitems[i].Packet.ToBytes());
  4241. MainLog.Instance.Verbose("CLIENT", "Add OutPacket [{0}]", queitems[i].Packet.Type.ToString());
  4242. }
  4243. }
  4244. */
  4245. info.sequence = m_sequence;
  4246. //MainLog.Instance.Verbose("CLIENT", "GetClientInfo END");
  4247. return info;
  4248. }
  4249. public void SetClientInfo(ClientInfo info)
  4250. {
  4251. m_pendingAcks = info.pendingAcks;
  4252. m_needAck = new Dictionary<uint,Packet>();
  4253. Packet packet = null;
  4254. int packetEnd = 0;
  4255. byte[] zero = new byte[3000];
  4256. foreach (uint key in info.needAck.Keys)
  4257. {
  4258. byte[] buff = info.needAck[key];
  4259. packetEnd = buff.Length - 1;
  4260. try
  4261. {
  4262. packet = PacketPool.Instance.GetPacket(buff, ref packetEnd, zero);
  4263. }
  4264. catch (Exception)
  4265. {
  4266. //MainLog.Instance.Debug("UDPSERVER", e.ToString());
  4267. }
  4268. m_needAck.Add(key, packet);
  4269. }
  4270. m_sequence = info.sequence;
  4271. }
  4272. }
  4273. }