WorldPacketHandlers.cs 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Text;
  4. using libsecondlife;
  5. using libsecondlife.Packets;
  6. using OpenSim.Physics.Manager;
  7. using OpenSim.Framework.Interfaces;
  8. using OpenSim.Framework.Types;
  9. using OpenSim.Framework.Terrain;
  10. using OpenSim.Framework.Inventory;
  11. using OpenSim.Framework.Utilities;
  12. using OpenSim.Assets;
  13. namespace OpenSim.world
  14. {
  15. partial class World
  16. {
  17. public bool ModifyTerrain(SimClient simClient, Packet packet)
  18. {
  19. ModifyLandPacket modify = (ModifyLandPacket)packet;
  20. switch (modify.ModifyBlock.Action)
  21. {
  22. case 1:
  23. // raise terrain
  24. if (modify.ParcelData.Length > 0)
  25. {
  26. Terrain.raise(modify.ParcelData[0].North, modify.ParcelData[0].West, 10.0, 0.1);
  27. RegenerateTerrain(true, (int)modify.ParcelData[0].North, (int)modify.ParcelData[0].West);
  28. }
  29. break;
  30. case 2:
  31. //lower terrain
  32. if (modify.ParcelData.Length > 0)
  33. {
  34. Terrain.lower(modify.ParcelData[0].North, modify.ParcelData[0].West, 10.0, 0.1);
  35. RegenerateTerrain(true, (int)modify.ParcelData[0].North, (int)modify.ParcelData[0].West);
  36. }
  37. break;
  38. }
  39. return true;
  40. }
  41. public bool SimChat(SimClient simClient, Packet packet)
  42. {
  43. System.Text.Encoding enc = System.Text.Encoding.ASCII;
  44. ChatFromViewerPacket inchatpack = (ChatFromViewerPacket)packet;
  45. if (Util.FieldToString(inchatpack.ChatData.Message) == "")
  46. {
  47. //empty message so don't bother with it
  48. return true;
  49. }
  50. libsecondlife.Packets.ChatFromSimulatorPacket reply = new ChatFromSimulatorPacket();
  51. reply.ChatData.Audible = 1;
  52. reply.ChatData.Message = inchatpack.ChatData.Message;
  53. reply.ChatData.ChatType = inchatpack.ChatData.Type;
  54. reply.ChatData.SourceType = 1;
  55. reply.ChatData.Position = simClient.ClientAvatar.Pos;
  56. reply.ChatData.FromName = enc.GetBytes(simClient.ClientAvatar.firstname + " " + simClient.ClientAvatar.lastname + "\0");
  57. reply.ChatData.OwnerID = simClient.AgentID;
  58. reply.ChatData.SourceID = simClient.AgentID;
  59. foreach (SimClient client in m_clientThreads.Values)
  60. {
  61. switch (inchatpack.ChatData.Type)
  62. {
  63. case 0:
  64. int dis = Util.fast_distance2d((int)(client.ClientAvatar.Pos.X - simClient.ClientAvatar.Pos.X),(int)( client.ClientAvatar.Pos.Y - simClient.ClientAvatar.Pos.Y));
  65. if ((dis < 10) && (dis > -10))
  66. {
  67. client.OutPacket(reply);
  68. }
  69. break;
  70. case 1:
  71. dis = Util.fast_distance2d((int)(client.ClientAvatar.Pos.X - simClient.ClientAvatar.Pos.X), (int)(client.ClientAvatar.Pos.Y - simClient.ClientAvatar.Pos.Y));
  72. if ((dis < 30) && (dis > -30))
  73. {
  74. client.OutPacket(reply);
  75. }
  76. break;
  77. case 2:
  78. dis = Util.fast_distance2d((int)(client.ClientAvatar.Pos.X - simClient.ClientAvatar.Pos.X),(int)( client.ClientAvatar.Pos.Y - simClient.ClientAvatar.Pos.Y));
  79. if ((dis < 100) && (dis > -100))
  80. {
  81. client.OutPacket(reply);
  82. }
  83. break;
  84. }
  85. }
  86. return true;
  87. }
  88. public bool RezObject(SimClient simClient, Packet packet)
  89. {
  90. RezObjectPacket rezPacket = (RezObjectPacket)packet;
  91. AgentInventory inven = this._inventoryCache.GetAgentsInventory(simClient.AgentID);
  92. if (inven != null)
  93. {
  94. if (inven.InventoryItems.ContainsKey(rezPacket.InventoryData.ItemID))
  95. {
  96. AssetBase asset = this._assetCache.GetAsset(inven.InventoryItems[rezPacket.InventoryData.ItemID].AssetID);
  97. if (asset != null)
  98. {
  99. PrimData primd = new PrimData(asset.Data);
  100. Primitive nPrim = new Primitive(m_clientThreads, m_regionHandle, this);
  101. nPrim.CreateFromStorage(primd, rezPacket.RezData.RayEnd, this._primCount, true);
  102. this.Entities.Add(nPrim.uuid, nPrim);
  103. this._primCount++;
  104. this._inventoryCache.DeleteInventoryItem(simClient, rezPacket.InventoryData.ItemID);
  105. }
  106. }
  107. }
  108. return true;
  109. }
  110. public bool DeRezObject(SimClient simClient, Packet packet)
  111. {
  112. DeRezObjectPacket DeRezPacket = (DeRezObjectPacket)packet;
  113. //Needs to delete object from physics at a later date
  114. if (DeRezPacket.AgentBlock.DestinationID == LLUUID.Zero)
  115. {
  116. //currently following code not used (or don't know of any case of destination being zero
  117. libsecondlife.LLUUID[] DeRezEnts;
  118. DeRezEnts = new libsecondlife.LLUUID[DeRezPacket.ObjectData.Length];
  119. int i = 0;
  120. foreach (DeRezObjectPacket.ObjectDataBlock Data in DeRezPacket.ObjectData)
  121. {
  122. //OpenSim.Framework.Console.MainConsole.Instance.WriteLine("LocalID:" + Data.ObjectLocalID.ToString());
  123. foreach (Entity ent in this.Entities.Values)
  124. {
  125. if (ent.localid == Data.ObjectLocalID)
  126. {
  127. DeRezEnts[i++] = ent.uuid;
  128. this.localStorage.RemovePrim(ent.uuid);
  129. KillObjectPacket kill = new KillObjectPacket();
  130. kill.ObjectData = new KillObjectPacket.ObjectDataBlock[1];
  131. kill.ObjectData[0] = new KillObjectPacket.ObjectDataBlock();
  132. kill.ObjectData[0].ID = ent.localid;
  133. foreach (SimClient client in m_clientThreads.Values)
  134. {
  135. client.OutPacket(kill);
  136. }
  137. //Uncommenting this means an old UUID will be re-used, thus crashing the asset server
  138. //Uncomment when prim/object UUIDs are random or such
  139. //2007-03-22 - Randomskk
  140. //this._primCount--;
  141. OpenSim.Framework.Console.MainConsole.Instance.WriteLine("Deleted UUID " + ent.uuid);
  142. }
  143. }
  144. }
  145. foreach (libsecondlife.LLUUID uuid in DeRezEnts)
  146. {
  147. lock (Entities)
  148. {
  149. Entities.Remove(uuid);
  150. }
  151. }
  152. }
  153. else
  154. {
  155. foreach (DeRezObjectPacket.ObjectDataBlock Data in DeRezPacket.ObjectData)
  156. {
  157. Entity selectedEnt = null;
  158. //OpenSim.Framework.Console.MainConsole.Instance.WriteLine("LocalID:" + Data.ObjectLocalID.ToString());
  159. foreach (Entity ent in this.Entities.Values)
  160. {
  161. if (ent.localid == Data.ObjectLocalID)
  162. {
  163. AssetBase primAsset = new AssetBase();
  164. primAsset.FullID = LLUUID.Random();//DeRezPacket.AgentBlock.TransactionID.Combine(LLUUID.Zero); //should be combining with securesessionid
  165. primAsset.InvType = 6;
  166. primAsset.Type = 6;
  167. primAsset.Name = "Prim";
  168. primAsset.Description = "";
  169. primAsset.Data = ((Primitive)ent).GetByteArray();
  170. this._assetCache.AddAsset(primAsset);
  171. this._inventoryCache.AddNewInventoryItem(simClient, DeRezPacket.AgentBlock.DestinationID, primAsset);
  172. selectedEnt = ent;
  173. break;
  174. }
  175. }
  176. if (selectedEnt != null)
  177. {
  178. this.localStorage.RemovePrim(selectedEnt.uuid);
  179. KillObjectPacket kill = new KillObjectPacket();
  180. kill.ObjectData = new KillObjectPacket.ObjectDataBlock[1];
  181. kill.ObjectData[0] = new KillObjectPacket.ObjectDataBlock();
  182. kill.ObjectData[0].ID = selectedEnt.localid;
  183. foreach (SimClient client in m_clientThreads.Values)
  184. {
  185. client.OutPacket(kill);
  186. }
  187. lock (Entities)
  188. {
  189. Entities.Remove(selectedEnt.uuid);
  190. }
  191. }
  192. }
  193. }
  194. return true;
  195. }
  196. }
  197. }