ClientView.PacketHandlers.cs 9.4 KB

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