Scene.PacketHandlers.cs 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218
  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.Collections.Generic;
  29. using libsecondlife;
  30. using libsecondlife.Packets;
  31. using OpenSim.Framework;
  32. using OpenSim.Framework.UserManagement;
  33. using OpenSim.Framework.Console;
  34. namespace OpenSim.Region.Environment.Scenes
  35. {
  36. public partial class Scene
  37. {
  38. /// <summary>
  39. /// Modifies terrain using the specified information
  40. /// </summary>
  41. /// <param name="height">The height at which the user started modifying the terrain</param>
  42. /// <param name="seconds">The number of seconds the modify button was pressed</param>
  43. /// <param name="brushsize">The size of the brush used</param>
  44. /// <param name="action">The action to be performed</param>
  45. /// <param name="north">Distance from the north border where the cursor is located</param>
  46. /// <param name="west">Distance from the west border where the cursor is located</param>
  47. public void ModifyTerrain(float height, float seconds, byte brushsize, byte action, float north, float west,
  48. float south, float east,
  49. IClientAPI remoteUser)
  50. {
  51. // Do a permissions check before allowing terraforming.
  52. // random users are now no longer allowed to terraform
  53. // if permissions are enabled.
  54. if (!PermissionsMngr.CanTerraform(remoteUser.AgentId, new LLVector3(north, west, 0)))
  55. return;
  56. //if it wasn't for the permission checking we could have the terrain module directly subscribe to the OnModifyTerrain event
  57. Terrain.ModifyTerrain(height, seconds, brushsize, action, north, west, south, east, remoteUser);
  58. }
  59. /// <summary>
  60. ///
  61. /// </summary>
  62. /// <param name="message"></param>
  63. /// <param name="type"></param>
  64. /// <param name="fromPos"></param>
  65. /// <param name="fromName"></param>
  66. /// <param name="fromAgentID"></param>
  67. public void SimChat(byte[] message, ChatTypeEnum type, int channel, LLVector3 fromPos, string fromName,
  68. LLUUID fromAgentID)
  69. {
  70. if (m_simChatModule != null)
  71. {
  72. ChatFromViewerArgs args = new ChatFromViewerArgs();
  73. args.Message = Helpers.FieldToUTF8String(message);
  74. args.Channel = channel;
  75. args.Type = type;
  76. args.Position = fromPos;
  77. ScenePresence user = GetScenePresence(fromAgentID);
  78. if (user != null)
  79. args.Sender = user.ControllingClient;
  80. else
  81. args.Sender = null;
  82. args.From = fromName;
  83. m_simChatModule.SimChat(this, args);
  84. }
  85. }
  86. /// <summary>
  87. ///
  88. /// </summary>
  89. /// <param name="primLocalID"></param>
  90. /// <param name="remoteClient"></param>
  91. public void SelectPrim(uint primLocalID, IClientAPI remoteClient)
  92. {
  93. List<EntityBase> EntitieList = GetEntities();
  94. foreach (EntityBase ent in EntitieList)
  95. {
  96. if (ent is SceneObjectGroup)
  97. {
  98. if (((SceneObjectGroup) ent).LocalId == primLocalID)
  99. {
  100. ((SceneObjectGroup) ent).GetProperties(remoteClient);
  101. ((SceneObjectGroup) ent).IsSelected = true;
  102. LandManager.setPrimsTainted();
  103. break;
  104. }
  105. }
  106. }
  107. }
  108. /// <summary>
  109. ///
  110. /// </summary>
  111. /// <param name="primLocalID"></param>
  112. /// <param name="remoteClient"></param>
  113. public void DeselectPrim(uint primLocalID, IClientAPI remoteClient)
  114. {
  115. List<EntityBase> EntitieList = GetEntities();
  116. foreach (EntityBase ent in EntitieList)
  117. {
  118. if (ent is SceneObjectGroup)
  119. {
  120. if (((SceneObjectGroup) ent).LocalId == primLocalID)
  121. {
  122. ((SceneObjectGroup) ent).IsSelected = false;
  123. LandManager.setPrimsTainted();
  124. break;
  125. }
  126. }
  127. }
  128. }
  129. public virtual void ProcessMoneyTransferRequest(LLUUID source, LLUUID destination, int amount, int transactiontype, string description)
  130. {
  131. EventManager.MoneyTransferArgs args = new EventManager.MoneyTransferArgs(
  132. source, destination, amount, transactiontype, description);
  133. EventManager.TriggerMoneyTransfer(this, args);
  134. }
  135. public virtual void ProcessObjectGrab(uint localID, LLVector3 offsetPos, IClientAPI remoteClient)
  136. {
  137. List<EntityBase> EntitieList = GetEntities();
  138. foreach (EntityBase ent in EntitieList)
  139. {
  140. if (ent is SceneObjectGroup)
  141. {
  142. SceneObjectGroup obj = ent as SceneObjectGroup;
  143. // Is this prim part of the group
  144. if (obj.HasChildPrim(localID))
  145. {
  146. // Currently only grab/touch for the single prim
  147. // the client handles rez correctly
  148. obj.ObjectGrabHandler(localID, offsetPos, remoteClient);
  149. // trigger event, one for each prim part in the group
  150. // so that a touch to a non-root prim in a group will still
  151. // trigger a touch_start for a script in the root prim
  152. foreach (SceneObjectPart part in obj.Children.Values)
  153. {
  154. EventManager.TriggerObjectGrab(part.LocalID, part.OffsetPosition, remoteClient);
  155. }
  156. return;
  157. }
  158. }
  159. }
  160. }
  161. public void ProcessAvatarPickerRequest(IClientAPI client, LLUUID avatarID, LLUUID RequestID, string query)
  162. {
  163. //EventManager.TriggerAvatarPickerRequest();
  164. List<AvatarPickerAvatar> AvatarResponses = new List<AvatarPickerAvatar>();
  165. AvatarResponses = m_sceneGridService.GenerateAgentPickerRequestResponse(RequestID, query);
  166. AvatarPickerReplyPacket replyPacket = (AvatarPickerReplyPacket) PacketPool.Instance.GetPacket(PacketType.AvatarPickerReply);
  167. // TODO: don't create new blocks if recycling an old packet
  168. AvatarPickerReplyPacket.DataBlock[] searchData =
  169. new AvatarPickerReplyPacket.DataBlock[AvatarResponses.Count];
  170. AvatarPickerReplyPacket.AgentDataBlock agentData = new AvatarPickerReplyPacket.AgentDataBlock();
  171. agentData.AgentID = avatarID;
  172. agentData.QueryID = RequestID;
  173. replyPacket.AgentData = agentData;
  174. //byte[] bytes = new byte[AvatarResponses.Count*32];
  175. int i = 0;
  176. foreach (AvatarPickerAvatar item in AvatarResponses)
  177. {
  178. LLUUID translatedIDtem = item.AvatarID;
  179. searchData[i] = new AvatarPickerReplyPacket.DataBlock();
  180. searchData[i].AvatarID = translatedIDtem;
  181. searchData[i].FirstName = Helpers.StringToField((string) item.firstName);
  182. searchData[i].LastName = Helpers.StringToField((string) item.lastName);
  183. i++;
  184. }
  185. if (AvatarResponses.Count == 0)
  186. {
  187. searchData = new AvatarPickerReplyPacket.DataBlock[0];
  188. }
  189. replyPacket.Data = searchData;
  190. client.SendAvatarPickerReply(replyPacket);
  191. }
  192. }
  193. }