ClientView.cs 212 KB

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