Scene.PacketHandlers.cs 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248
  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. using System.Collections.Generic;
  28. using libsecondlife;
  29. using libsecondlife.Packets;
  30. using OpenSim.Framework;
  31. namespace OpenSim.Region.Environment.Scenes
  32. {
  33. public partial class Scene
  34. {
  35. /// <summary>
  36. ///
  37. /// </summary>
  38. /// <param name="message"></param>
  39. /// <param name="type"></param>
  40. /// <param name="fromPos"></param>
  41. /// <param name="fromName"></param>
  42. /// <param name="fromAgentID"></param>
  43. public void SimChat(byte[] message, ChatTypeEnum type, int channel, LLVector3 fromPos, string fromName,
  44. LLUUID fromAgentID)
  45. {
  46. if (m_simChatModule != null)
  47. {
  48. ChatFromViewerArgs args = new ChatFromViewerArgs();
  49. args.Message = Helpers.FieldToUTF8String(message);
  50. args.Channel = channel;
  51. args.Type = type;
  52. args.Position = fromPos;
  53. ScenePresence user = GetScenePresence(fromAgentID);
  54. if (user != null)
  55. args.Sender = user.ControllingClient;
  56. else
  57. args.Sender = null;
  58. args.From = fromName;
  59. m_simChatModule.SimChat(this, args);
  60. }
  61. }
  62. /// <summary>
  63. /// Invoked when the client selects a prim.
  64. /// </summary>
  65. /// <param name="primLocalID"></param>
  66. /// <param name="remoteClient"></param>
  67. public void SelectPrim(uint primLocalID, IClientAPI remoteClient)
  68. {
  69. List<EntityBase> EntitieList = GetEntities();
  70. foreach (EntityBase ent in EntitieList)
  71. {
  72. if (ent is SceneObjectGroup)
  73. {
  74. if (((SceneObjectGroup) ent).LocalId == primLocalID)
  75. {
  76. // A prim is only tainted if it's allowed to be edited by the person clicking it.
  77. if (m_permissionManager.CanEditObjectPosition(remoteClient.AgentId, ((SceneObjectGroup)ent).UUID) || m_permissionManager.CanEditObject(remoteClient.AgentId, ((SceneObjectGroup)ent).UUID))
  78. {
  79. ((SceneObjectGroup) ent).GetProperties(remoteClient);
  80. ((SceneObjectGroup) ent).IsSelected = true;
  81. LandChannel.setPrimsTainted();
  82. }
  83. break;
  84. }
  85. }
  86. }
  87. }
  88. /// <summary>
  89. ///
  90. /// </summary>
  91. /// <param name="primLocalID"></param>
  92. /// <param name="remoteClient"></param>
  93. public void DeselectPrim(uint primLocalID, IClientAPI remoteClient)
  94. {
  95. List<EntityBase> EntitieList = GetEntities();
  96. foreach (EntityBase ent in EntitieList)
  97. {
  98. if (ent is SceneObjectGroup)
  99. {
  100. if (((SceneObjectGroup) ent).LocalId == primLocalID)
  101. {
  102. if (m_permissionManager.CanEditObjectPosition(remoteClient.AgentId, ((SceneObjectGroup)ent).UUID) || m_permissionManager.CanEditObject(remoteClient.AgentId, ((SceneObjectGroup)ent).UUID))
  103. {
  104. ((SceneObjectGroup) ent).IsSelected = false;
  105. LandChannel.setPrimsTainted();
  106. break;
  107. }
  108. }
  109. }
  110. }
  111. }
  112. public virtual void ProcessMoneyTransferRequest(LLUUID source, LLUUID destination, int amount, int transactiontype, string description)
  113. {
  114. EventManager.MoneyTransferArgs args = new EventManager.MoneyTransferArgs(
  115. source, destination, amount, transactiontype, description);
  116. EventManager.TriggerMoneyTransfer(this, args);
  117. }
  118. public virtual void ProcessParcelBuy(LLUUID agentId, LLUUID groupId, bool final, bool groupOwned,
  119. bool removeContribution, int parcelLocalID, int parcelArea, int parcelPrice, bool authenticated)
  120. {
  121. EventManager.LandBuyArgs args = new EventManager.LandBuyArgs(
  122. agentId, groupId, final, groupOwned, removeContribution, parcelLocalID, parcelArea, parcelPrice, authenticated);
  123. // First, allow all validators a stab at it
  124. m_eventManager.TriggerValidateLandBuy(this, args);
  125. // Then, check validation and transfer
  126. m_eventManager.TriggerLandBuy(this, args);
  127. }
  128. public virtual void ProcessObjectGrab(uint localID, LLVector3 offsetPos, IClientAPI remoteClient)
  129. {
  130. List<EntityBase> EntitieList = GetEntities();
  131. foreach (EntityBase ent in EntitieList)
  132. {
  133. if (ent is SceneObjectGroup)
  134. {
  135. SceneObjectGroup obj = ent as SceneObjectGroup;
  136. if (obj != null)
  137. {
  138. // Is this prim part of the group
  139. if (obj.HasChildPrim(localID))
  140. {
  141. // Currently only grab/touch for the single prim
  142. // the client handles rez correctly
  143. obj.ObjectGrabHandler(localID, offsetPos, remoteClient);
  144. SceneObjectPart part = obj.GetChildPart(localID);
  145. // If the touched prim handles touches, deliver it
  146. // If not, deliver to root prim
  147. if ((part.ScriptEvents & scriptEvents.touch_start) != 0)
  148. EventManager.TriggerObjectGrab(part.LocalId, part.OffsetPosition, remoteClient);
  149. else
  150. EventManager.TriggerObjectGrab(obj.RootPart.LocalId, part.OffsetPosition, remoteClient);
  151. return;
  152. }
  153. }
  154. }
  155. }
  156. }
  157. public virtual void ProcessObjectDeGrab(uint localID, IClientAPI remoteClient)
  158. {
  159. List<EntityBase> EntitieList = GetEntities();
  160. foreach (EntityBase ent in EntitieList)
  161. {
  162. if (ent is SceneObjectGroup)
  163. {
  164. SceneObjectGroup obj = ent as SceneObjectGroup;
  165. // Is this prim part of the group
  166. if (obj.HasChildPrim(localID))
  167. {
  168. SceneObjectPart part=obj.GetChildPart(localID);
  169. if (part != null)
  170. {
  171. // If the touched prim handles touches, deliver it
  172. // If not, deliver to root prim
  173. if ((part.ScriptEvents & scriptEvents.touch_end) != 0)
  174. EventManager.TriggerObjectDeGrab(part.LocalId, remoteClient);
  175. else
  176. EventManager.TriggerObjectDeGrab(obj.RootPart.LocalId, remoteClient);
  177. return;
  178. }
  179. return;
  180. }
  181. }
  182. }
  183. }
  184. public void ProcessAvatarPickerRequest(IClientAPI client, LLUUID avatarID, LLUUID RequestID, string query)
  185. {
  186. //EventManager.TriggerAvatarPickerRequest();
  187. List<AvatarPickerAvatar> AvatarResponses = new List<AvatarPickerAvatar>();
  188. AvatarResponses = m_sceneGridService.GenerateAgentPickerRequestResponse(RequestID, query);
  189. AvatarPickerReplyPacket replyPacket = (AvatarPickerReplyPacket) PacketPool.Instance.GetPacket(PacketType.AvatarPickerReply);
  190. // TODO: don't create new blocks if recycling an old packet
  191. AvatarPickerReplyPacket.DataBlock[] searchData =
  192. new AvatarPickerReplyPacket.DataBlock[AvatarResponses.Count];
  193. AvatarPickerReplyPacket.AgentDataBlock agentData = new AvatarPickerReplyPacket.AgentDataBlock();
  194. agentData.AgentID = avatarID;
  195. agentData.QueryID = RequestID;
  196. replyPacket.AgentData = agentData;
  197. //byte[] bytes = new byte[AvatarResponses.Count*32];
  198. int i = 0;
  199. foreach (AvatarPickerAvatar item in AvatarResponses)
  200. {
  201. LLUUID translatedIDtem = item.AvatarID;
  202. searchData[i] = new AvatarPickerReplyPacket.DataBlock();
  203. searchData[i].AvatarID = translatedIDtem;
  204. searchData[i].FirstName = Helpers.StringToField((string) item.firstName);
  205. searchData[i].LastName = Helpers.StringToField((string) item.lastName);
  206. i++;
  207. }
  208. if (AvatarResponses.Count == 0)
  209. {
  210. searchData = new AvatarPickerReplyPacket.DataBlock[0];
  211. }
  212. replyPacket.Data = searchData;
  213. client.SendAvatarPickerReply(replyPacket);
  214. }
  215. }
  216. }