ClientView.PacketHandlers.cs 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. using System;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using libsecondlife;
  5. using libsecondlife.Packets;
  6. using Nwc.XmlRpc;
  7. using System.Net;
  8. using System.Net.Sockets;
  9. using System.IO;
  10. using System.Threading;
  11. using System.Timers;
  12. using OpenSim.Framework.Interfaces;
  13. using OpenSim.Framework.Types;
  14. using OpenSim.Framework.Inventory;
  15. using OpenSim.Framework.Utilities;
  16. using OpenSim.Assets;
  17. namespace OpenSim
  18. {
  19. public partial class ClientView
  20. {
  21. protected virtual void RegisterLocalPacketHandlers()
  22. {
  23. this.AddLocalPacketHandler(PacketType.LogoutRequest, this.Logout);
  24. this.AddLocalPacketHandler(PacketType.AgentCachedTexture, this.AgentTextureCached);
  25. this.AddLocalPacketHandler(PacketType.MultipleObjectUpdate, this.MultipleObjUpdate);
  26. }
  27. protected virtual bool Logout(ClientView simClient, Packet packet)
  28. {
  29. OpenSim.Framework.Console.MainConsole.Instance.WriteLine(OpenSim.Framework.Console.LogPriority.LOW, "OpenSimClient.cs:ProcessInPacket() - Got a logout request");
  30. //send reply to let the client logout
  31. LogoutReplyPacket logReply = new LogoutReplyPacket();
  32. logReply.AgentData.AgentID = this.AgentID;
  33. logReply.AgentData.SessionID = this.SessionID;
  34. logReply.InventoryData = new LogoutReplyPacket.InventoryDataBlock[1];
  35. logReply.InventoryData[0] = new LogoutReplyPacket.InventoryDataBlock();
  36. logReply.InventoryData[0].ItemID = LLUUID.Zero;
  37. OutPacket(logReply);
  38. //tell all clients to kill our object
  39. KillObjectPacket kill = new KillObjectPacket();
  40. kill.ObjectData = new KillObjectPacket.ObjectDataBlock[1];
  41. kill.ObjectData[0] = new KillObjectPacket.ObjectDataBlock();
  42. // kill.ObjectData[0].ID = this.ClientAvatar.localid;
  43. foreach (ClientView client in m_clientThreads.Values)
  44. {
  45. client.OutPacket(kill);
  46. }
  47. this.m_inventoryCache.ClientLeaving(this.AgentID, null);
  48. // m_gridServer.LogoutSession(this.SessionID, this.AgentID, this.CircuitCode);
  49. /*lock (m_world.Entities)
  50. {
  51. m_world.Entities.Remove(this.AgentID);
  52. }*/
  53. // m_world.RemoveViewerAgent(this);
  54. //need to do other cleaning up here too
  55. m_clientThreads.Remove(this.CircuitCode);
  56. m_networkServer.RemoveClientCircuit(this.CircuitCode);
  57. this.ClientThread.Abort();
  58. return true;
  59. }
  60. protected bool AgentTextureCached(ClientView simclient, Packet packet)
  61. {
  62. // Console.WriteLine(packet.ToString());
  63. AgentCachedTexturePacket chechedtex = (AgentCachedTexturePacket)packet;
  64. AgentCachedTextureResponsePacket cachedresp = new AgentCachedTextureResponsePacket();
  65. cachedresp.AgentData.AgentID = this.AgentID;
  66. cachedresp.AgentData.SessionID = this.SessionID;
  67. cachedresp.AgentData.SerialNum = this.cachedtextureserial;
  68. this.cachedtextureserial++;
  69. cachedresp.WearableData = new AgentCachedTextureResponsePacket.WearableDataBlock[chechedtex.WearableData.Length];
  70. for (int i = 0; i < chechedtex.WearableData.Length; i++)
  71. {
  72. cachedresp.WearableData[i] = new AgentCachedTextureResponsePacket.WearableDataBlock();
  73. cachedresp.WearableData[i].TextureIndex = chechedtex.WearableData[i].TextureIndex;
  74. cachedresp.WearableData[i].TextureID = LLUUID.Zero;
  75. cachedresp.WearableData[i].HostName = new byte[0];
  76. }
  77. this.OutPacket(cachedresp);
  78. return true;
  79. }
  80. protected bool MultipleObjUpdate(ClientView simClient, Packet packet)
  81. {
  82. MultipleObjectUpdatePacket multipleupdate = (MultipleObjectUpdatePacket)packet;
  83. for (int i = 0; i < multipleupdate.ObjectData.Length; i++)
  84. {
  85. if (multipleupdate.ObjectData[i].Type == 9) //change position
  86. {
  87. libsecondlife.LLVector3 pos = new LLVector3(multipleupdate.ObjectData[i].Data, 0);
  88. OnUpdatePrimPosition(multipleupdate.ObjectData[i].ObjectLocalID, pos, this);
  89. //should update stored position of the prim
  90. }
  91. else if (multipleupdate.ObjectData[i].Type == 10)//rotation
  92. {
  93. libsecondlife.LLQuaternion rot = new LLQuaternion(multipleupdate.ObjectData[i].Data, 0, true);
  94. OnUpdatePrimRotation(multipleupdate.ObjectData[i].ObjectLocalID, rot, this);
  95. }
  96. else if (multipleupdate.ObjectData[i].Type == 13)//scale
  97. {
  98. libsecondlife.LLVector3 scale = new LLVector3(multipleupdate.ObjectData[i].Data, 12);
  99. OnUpdatePrimScale(multipleupdate.ObjectData[i].ObjectLocalID, scale, this);
  100. }
  101. }
  102. return true;
  103. }
  104. public void RequestMapLayer() //should be getting the map layer from the grid server
  105. {
  106. //send a layer covering the 800,800 - 1200,1200 area (should be covering the requested area)
  107. MapLayerReplyPacket mapReply = new MapLayerReplyPacket();
  108. mapReply.AgentData.AgentID = this.AgentID;
  109. mapReply.AgentData.Flags = 0;
  110. mapReply.LayerData = new MapLayerReplyPacket.LayerDataBlock[1];
  111. mapReply.LayerData[0] = new MapLayerReplyPacket.LayerDataBlock();
  112. mapReply.LayerData[0].Bottom = 800;
  113. mapReply.LayerData[0].Left = 800;
  114. mapReply.LayerData[0].Top = 1200;
  115. mapReply.LayerData[0].Right = 1200;
  116. mapReply.LayerData[0].ImageID = new LLUUID("00000000-0000-0000-9999-000000000006");
  117. this.OutPacket(mapReply);
  118. }
  119. public void RequestMapBlocks(int minX, int minY, int maxX, int maxY)
  120. {
  121. IList simMapProfiles = m_gridServer.RequestMapBlocks(minX, minY, maxX, maxY);
  122. MapBlockReplyPacket mbReply = new MapBlockReplyPacket();
  123. mbReply.AgentData.AgentID = this.AgentID;
  124. int len;
  125. if (simMapProfiles == null)
  126. len = 0;
  127. else
  128. len = simMapProfiles.Count;
  129. mbReply.Data = new MapBlockReplyPacket.DataBlock[len];
  130. int iii;
  131. for (iii = 0; iii < len; iii++)
  132. {
  133. Hashtable mp = (Hashtable)simMapProfiles[iii];
  134. mbReply.Data[iii] = new MapBlockReplyPacket.DataBlock();
  135. mbReply.Data[iii].Name = System.Text.Encoding.UTF8.GetBytes((string)mp["name"]);
  136. mbReply.Data[iii].Access = System.Convert.ToByte(mp["access"]);
  137. mbReply.Data[iii].Agents = System.Convert.ToByte(mp["agents"]);
  138. mbReply.Data[iii].MapImageID = new LLUUID((string)mp["map-image-id"]);
  139. mbReply.Data[iii].RegionFlags = System.Convert.ToUInt32(mp["region-flags"]);
  140. mbReply.Data[iii].WaterHeight = System.Convert.ToByte(mp["water-height"]);
  141. mbReply.Data[iii].X = System.Convert.ToUInt16(mp["x"]);
  142. mbReply.Data[iii].Y = System.Convert.ToUInt16(mp["y"]);
  143. }
  144. this.OutPacket(mbReply);
  145. }
  146. }
  147. }