1
0

ClientView.cs 182 KB

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