ClientView.cs 191 KB

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