ClientView.PacketHandlers.cs 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236
  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 libsecondlife;
  29. using libsecondlife.Packets;
  30. using OpenSim.Framework.Console;
  31. namespace OpenSim.Region.ClientStack
  32. {
  33. public partial class ClientView
  34. {
  35. protected virtual void RegisterLocalPacketHandlers()
  36. {
  37. this.AddLocalPacketHandler(PacketType.LogoutRequest, this.Logout);
  38. this.AddLocalPacketHandler(PacketType.AgentCachedTexture, this.AgentTextureCached);
  39. this.AddLocalPacketHandler(PacketType.MultipleObjectUpdate, this.MultipleObjUpdate);
  40. }
  41. protected virtual bool Logout(ClientView simClient, Packet packet)
  42. {
  43. MainLog.Instance.Verbose( "OpenSimClient.cs:ProcessInPacket() - Got a logout request");
  44. //send reply to let the client logout
  45. LogoutReplyPacket logReply = new LogoutReplyPacket();
  46. logReply.AgentData.AgentID = this.AgentID;
  47. logReply.AgentData.SessionID = this.SessionID;
  48. logReply.InventoryData = new LogoutReplyPacket.InventoryDataBlock[1];
  49. logReply.InventoryData[0] = new LogoutReplyPacket.InventoryDataBlock();
  50. logReply.InventoryData[0].ItemID = LLUUID.Zero;
  51. OutPacket(logReply);
  52. //
  53. this.KillClient();
  54. return true;
  55. }
  56. protected bool AgentTextureCached(ClientView simclient, Packet packet)
  57. {
  58. // Console.WriteLine(packet.ToString());
  59. AgentCachedTexturePacket chechedtex = (AgentCachedTexturePacket)packet;
  60. AgentCachedTextureResponsePacket cachedresp = new AgentCachedTextureResponsePacket();
  61. cachedresp.AgentData.AgentID = this.AgentID;
  62. cachedresp.AgentData.SessionID = this.SessionID;
  63. cachedresp.AgentData.SerialNum = this.cachedtextureserial;
  64. this.cachedtextureserial++;
  65. cachedresp.WearableData = new AgentCachedTextureResponsePacket.WearableDataBlock[chechedtex.WearableData.Length];
  66. for (int i = 0; i < chechedtex.WearableData.Length; i++)
  67. {
  68. cachedresp.WearableData[i] = new AgentCachedTextureResponsePacket.WearableDataBlock();
  69. cachedresp.WearableData[i].TextureIndex = chechedtex.WearableData[i].TextureIndex;
  70. cachedresp.WearableData[i].TextureID = LLUUID.Zero;
  71. cachedresp.WearableData[i].HostName = new byte[0];
  72. }
  73. this.OutPacket(cachedresp);
  74. return true;
  75. }
  76. protected bool MultipleObjUpdate(ClientView simClient, Packet packet)
  77. {
  78. MultipleObjectUpdatePacket multipleupdate = (MultipleObjectUpdatePacket)packet;
  79. //System.Console.WriteLine("new multi update packet " + multipleupdate.ToString());
  80. for (int i = 0; i < multipleupdate.ObjectData.Length; i++)
  81. {
  82. #region position
  83. if (multipleupdate.ObjectData[i].Type == 9) //change position
  84. {
  85. if (OnUpdatePrimGroupPosition != null)
  86. {
  87. LLVector3 pos = new LLVector3(multipleupdate.ObjectData[i].Data, 0);
  88. OnUpdatePrimGroupPosition(multipleupdate.ObjectData[i].ObjectLocalID, pos, this);
  89. }
  90. }
  91. else if (multipleupdate.ObjectData[i].Type == 1) //single item of group change position
  92. {
  93. if (OnUpdatePrimSinglePosition != null)
  94. {
  95. libsecondlife.LLVector3 pos = new LLVector3(multipleupdate.ObjectData[i].Data, 0);
  96. // System.Console.WriteLine("new movement position is " + pos.X + " , " + pos.Y + " , " + pos.Z);
  97. OnUpdatePrimSinglePosition(multipleupdate.ObjectData[i].ObjectLocalID, pos, this);
  98. }
  99. }
  100. #endregion position
  101. #region rotation
  102. else if (multipleupdate.ObjectData[i].Type == 2)// single item of group rotation from tab
  103. {
  104. if (OnUpdatePrimSingleRotation != null)
  105. {
  106. LLQuaternion rot = new LLQuaternion(multipleupdate.ObjectData[i].Data, 0, true);
  107. // Console.WriteLine("new rotation is " + rot.X + " , " + rot.Y + " , " + rot.Z + " , " + rot.W);
  108. OnUpdatePrimSingleRotation(multipleupdate.ObjectData[i].ObjectLocalID, rot, this);
  109. }
  110. }
  111. else if (multipleupdate.ObjectData[i].Type == 3)// single item of group rotation from mouse
  112. {
  113. if (OnUpdatePrimSingleRotation != null)
  114. {
  115. libsecondlife.LLQuaternion rot = new LLQuaternion(multipleupdate.ObjectData[i].Data, 12, true);
  116. // Console.WriteLine("new rotation is " + rot.X + " , " + rot.Y + " , " + rot.Z + " , " + rot.W);
  117. OnUpdatePrimSingleRotation(multipleupdate.ObjectData[i].ObjectLocalID, rot, this);
  118. }
  119. }
  120. else if (multipleupdate.ObjectData[i].Type == 10)//group rotation from object tab
  121. {
  122. if (OnUpdatePrimGroupRotation != null)
  123. {
  124. libsecondlife.LLQuaternion rot = new LLQuaternion(multipleupdate.ObjectData[i].Data, 0, true);
  125. // Console.WriteLine("new rotation is " + rot.X + " , " + rot.Y + " , " + rot.Z + " , " + rot.W);
  126. OnUpdatePrimGroupRotation(multipleupdate.ObjectData[i].ObjectLocalID, rot, this);
  127. }
  128. }
  129. else if (multipleupdate.ObjectData[i].Type == 11)//group rotation from mouse
  130. {
  131. if (OnUpdatePrimGroupMouseRotation != null)
  132. {
  133. libsecondlife.LLVector3 pos = new LLVector3(multipleupdate.ObjectData[i].Data, 0);
  134. libsecondlife.LLQuaternion rot = new LLQuaternion(multipleupdate.ObjectData[i].Data, 12, true);
  135. //Console.WriteLine("new rotation position is " + pos.X + " , " + pos.Y + " , " + pos.Z);
  136. // Console.WriteLine("new rotation is " + rot.X + " , " + rot.Y + " , " + rot.Z + " , " + rot.W);
  137. OnUpdatePrimGroupMouseRotation(multipleupdate.ObjectData[i].ObjectLocalID, pos, rot, this);
  138. }
  139. }
  140. #endregion
  141. #region scale
  142. else if (multipleupdate.ObjectData[i].Type == 13)//group scale from object tab
  143. {
  144. if (OnUpdatePrimScale != null)
  145. {
  146. LLVector3 scale = new LLVector3(multipleupdate.ObjectData[i].Data, 12);
  147. //Console.WriteLine("new scale is " + scale.X + " , " + scale.Y + " , " + scale.Z);
  148. OnUpdatePrimScale(multipleupdate.ObjectData[i].ObjectLocalID, scale, this);
  149. }
  150. }
  151. else if (multipleupdate.ObjectData[i].Type == 29)//group scale from mouse
  152. {
  153. if (OnUpdatePrimScale != null)
  154. {
  155. libsecondlife.LLVector3 scale = new LLVector3(multipleupdate.ObjectData[i].Data, 0);
  156. // Console.WriteLine("new scale is " + scale.X + " , " + scale.Y + " , " + scale.Z );
  157. // OnUpdatePrimScale(multipleupdate.ObjectData[i].ObjectLocalID, scale, this);
  158. }
  159. }
  160. else if (multipleupdate.ObjectData[i].Type == 5)//single prim scale from object tab
  161. {
  162. if (OnUpdatePrimScale != null)
  163. {
  164. libsecondlife.LLVector3 scale = new LLVector3(multipleupdate.ObjectData[i].Data, 12);
  165. // Console.WriteLine("new scale is " + scale.X + " , " + scale.Y + " , " + scale.Z);
  166. OnUpdatePrimScale(multipleupdate.ObjectData[i].ObjectLocalID, scale, this);
  167. }
  168. }
  169. else if (multipleupdate.ObjectData[i].Type == 21)//single prim scale from mouse
  170. {
  171. if (OnUpdatePrimScale != null)
  172. {
  173. libsecondlife.LLVector3 scale = new LLVector3(multipleupdate.ObjectData[i].Data, 12);
  174. // Console.WriteLine("new scale is " + scale.X + " , " + scale.Y + " , " + scale.Z);
  175. OnUpdatePrimScale(multipleupdate.ObjectData[i].ObjectLocalID, scale, this);
  176. }
  177. }
  178. #endregion
  179. }
  180. return true;
  181. }
  182. public void RequestMapLayer()
  183. {
  184. //should be getting the map layer from the grid server
  185. //send a layer covering the 800,800 - 1200,1200 area (should be covering the requested area)
  186. MapLayerReplyPacket mapReply = new MapLayerReplyPacket();
  187. mapReply.AgentData.AgentID = this.AgentID;
  188. mapReply.AgentData.Flags = 0;
  189. mapReply.LayerData = new MapLayerReplyPacket.LayerDataBlock[1];
  190. mapReply.LayerData[0] = new MapLayerReplyPacket.LayerDataBlock();
  191. mapReply.LayerData[0].Bottom = 0;
  192. mapReply.LayerData[0].Left = 0;
  193. mapReply.LayerData[0].Top = 30000;
  194. mapReply.LayerData[0].Right = 30000;
  195. mapReply.LayerData[0].ImageID = new LLUUID("00000000-0000-0000-9999-000000000006");
  196. this.OutPacket(mapReply);
  197. }
  198. public void RequestMapBlocks(int minX, int minY, int maxX, int maxY)
  199. {
  200. /*
  201. IList simMapProfiles = m_gridServer.RequestMapBlocks(minX, minY, maxX, maxY);
  202. MapBlockReplyPacket mbReply = new MapBlockReplyPacket();
  203. mbReply.AgentData.AgentID = this.AgentID;
  204. int len;
  205. if (simMapProfiles == null)
  206. len = 0;
  207. else
  208. len = simMapProfiles.Count;
  209. mbReply.Data = new MapBlockReplyPacket.DataBlock[len];
  210. int iii;
  211. for (iii = 0; iii < len; iii++)
  212. {
  213. Hashtable mp = (Hashtable)simMapProfiles[iii];
  214. mbReply.Data[iii] = new MapBlockReplyPacket.DataBlock();
  215. mbReply.Data[iii].Name = System.Text.Encoding.UTF8.GetBytes((string)mp["name"]);
  216. mbReply.Data[iii].Access = System.Convert.ToByte(mp["access"]);
  217. mbReply.Data[iii].Agents = System.Convert.ToByte(mp["agents"]);
  218. mbReply.Data[iii].MapImageID = new LLUUID((string)mp["map-image-id"]);
  219. mbReply.Data[iii].RegionFlags = System.Convert.ToUInt32(mp["region-flags"]);
  220. mbReply.Data[iii].WaterHeight = System.Convert.ToByte(mp["water-height"]);
  221. mbReply.Data[iii].X = System.Convert.ToUInt16(mp["x"]);
  222. mbReply.Data[iii].Y = System.Convert.ToUInt16(mp["y"]);
  223. }
  224. this.OutPacket(mbReply);
  225. */
  226. }
  227. }
  228. }