Scene.PacketHandlers.cs 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203
  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. using OpenSim.Framework.UserManagement;
  32. using OpenSim.Framework.Console;
  33. namespace OpenSim.Region.Environment.Scenes
  34. {
  35. public partial class Scene
  36. {
  37. /// <summary>
  38. ///
  39. /// </summary>
  40. /// <param name="message"></param>
  41. /// <param name="type"></param>
  42. /// <param name="fromPos"></param>
  43. /// <param name="fromName"></param>
  44. /// <param name="fromAgentID"></param>
  45. public void SimChat(byte[] message, ChatTypeEnum type, int channel, LLVector3 fromPos, string fromName,
  46. LLUUID fromAgentID)
  47. {
  48. if (m_simChatModule != null)
  49. {
  50. ChatFromViewerArgs args = new ChatFromViewerArgs();
  51. args.Message = Helpers.FieldToUTF8String(message);
  52. args.Channel = channel;
  53. args.Type = type;
  54. args.Position = fromPos;
  55. ScenePresence user = GetScenePresence(fromAgentID);
  56. if (user != null)
  57. args.Sender = user.ControllingClient;
  58. else
  59. args.Sender = null;
  60. args.From = fromName;
  61. m_simChatModule.SimChat(this, args);
  62. }
  63. }
  64. /// <summary>
  65. ///
  66. /// </summary>
  67. /// <param name="primLocalID"></param>
  68. /// <param name="remoteClient"></param>
  69. public void SelectPrim(uint primLocalID, IClientAPI remoteClient)
  70. {
  71. List<EntityBase> EntitieList = GetEntities();
  72. foreach (EntityBase ent in EntitieList)
  73. {
  74. if (ent is SceneObjectGroup)
  75. {
  76. if (((SceneObjectGroup) ent).LocalId == primLocalID)
  77. {
  78. // A prim is only tainted if it's allowed to be edited by the person clicking it.
  79. if (m_permissionManager.CanEditObjectPosition(remoteClient.AgentId, ((SceneObjectGroup)ent).UUID) || m_permissionManager.CanEditObject(remoteClient.AgentId, ((SceneObjectGroup)ent).UUID))
  80. {
  81. ((SceneObjectGroup) ent).GetProperties(remoteClient);
  82. ((SceneObjectGroup) ent).IsSelected = true;
  83. LandChannel.setPrimsTainted();
  84. }
  85. break;
  86. }
  87. }
  88. }
  89. }
  90. /// <summary>
  91. ///
  92. /// </summary>
  93. /// <param name="primLocalID"></param>
  94. /// <param name="remoteClient"></param>
  95. public void DeselectPrim(uint primLocalID, IClientAPI remoteClient)
  96. {
  97. List<EntityBase> EntitieList = GetEntities();
  98. foreach (EntityBase ent in EntitieList)
  99. {
  100. if (ent is SceneObjectGroup)
  101. {
  102. if (((SceneObjectGroup) ent).LocalId == primLocalID)
  103. {
  104. if (m_permissionManager.CanEditObjectPosition(remoteClient.AgentId, ((SceneObjectGroup)ent).UUID) || m_permissionManager.CanEditObject(remoteClient.AgentId, ((SceneObjectGroup)ent).UUID))
  105. {
  106. ((SceneObjectGroup) ent).IsSelected = false;
  107. LandChannel.setPrimsTainted();
  108. break;
  109. }
  110. }
  111. }
  112. }
  113. }
  114. public virtual void ProcessMoneyTransferRequest(LLUUID source, LLUUID destination, int amount, int transactiontype, string description)
  115. {
  116. EventManager.MoneyTransferArgs args = new EventManager.MoneyTransferArgs(
  117. source, destination, amount, transactiontype, description);
  118. EventManager.TriggerMoneyTransfer(this, args);
  119. }
  120. public virtual void ProcessObjectGrab(uint localID, LLVector3 offsetPos, IClientAPI remoteClient)
  121. {
  122. List<EntityBase> EntitieList = GetEntities();
  123. foreach (EntityBase ent in EntitieList)
  124. {
  125. if (ent is SceneObjectGroup)
  126. {
  127. SceneObjectGroup obj = ent as SceneObjectGroup;
  128. // Is this prim part of the group
  129. if (obj.HasChildPrim(localID))
  130. {
  131. // Currently only grab/touch for the single prim
  132. // the client handles rez correctly
  133. obj.ObjectGrabHandler(localID, offsetPos, remoteClient);
  134. // trigger event, one for each prim part in the group
  135. // so that a touch to a non-root prim in a group will still
  136. // trigger a touch_start for a script in the root prim
  137. foreach (SceneObjectPart part in obj.Children.Values)
  138. {
  139. EventManager.TriggerObjectGrab(part.LocalId, part.OffsetPosition, remoteClient);
  140. }
  141. return;
  142. }
  143. }
  144. }
  145. }
  146. public void ProcessAvatarPickerRequest(IClientAPI client, LLUUID avatarID, LLUUID RequestID, string query)
  147. {
  148. //EventManager.TriggerAvatarPickerRequest();
  149. List<AvatarPickerAvatar> AvatarResponses = new List<AvatarPickerAvatar>();
  150. AvatarResponses = m_sceneGridService.GenerateAgentPickerRequestResponse(RequestID, query);
  151. AvatarPickerReplyPacket replyPacket = (AvatarPickerReplyPacket) PacketPool.Instance.GetPacket(PacketType.AvatarPickerReply);
  152. // TODO: don't create new blocks if recycling an old packet
  153. AvatarPickerReplyPacket.DataBlock[] searchData =
  154. new AvatarPickerReplyPacket.DataBlock[AvatarResponses.Count];
  155. AvatarPickerReplyPacket.AgentDataBlock agentData = new AvatarPickerReplyPacket.AgentDataBlock();
  156. agentData.AgentID = avatarID;
  157. agentData.QueryID = RequestID;
  158. replyPacket.AgentData = agentData;
  159. //byte[] bytes = new byte[AvatarResponses.Count*32];
  160. int i = 0;
  161. foreach (AvatarPickerAvatar item in AvatarResponses)
  162. {
  163. LLUUID translatedIDtem = item.AvatarID;
  164. searchData[i] = new AvatarPickerReplyPacket.DataBlock();
  165. searchData[i].AvatarID = translatedIDtem;
  166. searchData[i].FirstName = Helpers.StringToField((string) item.firstName);
  167. searchData[i].LastName = Helpers.StringToField((string) item.lastName);
  168. i++;
  169. }
  170. if (AvatarResponses.Count == 0)
  171. {
  172. searchData = new AvatarPickerReplyPacket.DataBlock[0];
  173. }
  174. replyPacket.Data = searchData;
  175. client.SendAvatarPickerReply(replyPacket);
  176. }
  177. }
  178. }