Scene.PacketHandlers.cs 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305
  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. protected void SimChat(byte[] message, ChatTypeEnum type, int channel, LLVector3 fromPos, string fromName,
  36. LLUUID fromID, bool fromAgent, bool broadcast)
  37. {
  38. ChatFromViewerArgs args = new ChatFromViewerArgs();
  39. args.Message = Helpers.FieldToUTF8String(message);
  40. args.Channel = channel;
  41. args.Type = type;
  42. args.Position = fromPos;
  43. args.SenderUUID = fromID;
  44. args.Scene = this;
  45. if (fromAgent)
  46. {
  47. ScenePresence user = GetScenePresence(fromID);
  48. if (user != null)
  49. args.Sender = user.ControllingClient;
  50. }
  51. else
  52. {
  53. SceneObjectPart obj = GetSceneObjectPart(fromID);
  54. args.SenderObject = obj;
  55. }
  56. args.From = fromName;
  57. //args.
  58. if (broadcast)
  59. EventManager.TriggerOnChatBroadcast(this, args);
  60. else
  61. EventManager.TriggerOnChatFromWorld(this, args);
  62. }
  63. /// <summary>
  64. ///
  65. /// </summary>
  66. /// <param name="message"></param>
  67. /// <param name="type"></param>
  68. /// <param name="fromPos"></param>
  69. /// <param name="fromName"></param>
  70. /// <param name="fromAgentID"></param>
  71. public void SimChat(byte[] message, ChatTypeEnum type, int channel, LLVector3 fromPos, string fromName,
  72. LLUUID fromID, bool fromAgent)
  73. {
  74. SimChat(message, type, channel, fromPos, fromName, fromID, fromAgent, false);
  75. }
  76. /// <summary>
  77. ///
  78. /// </summary>
  79. /// <param name="message"></param>
  80. /// <param name="type"></param>
  81. /// <param name="fromPos"></param>
  82. /// <param name="fromName"></param>
  83. /// <param name="fromAgentID"></param>
  84. public void SimChatBroadcast(byte[] message, ChatTypeEnum type, int channel, LLVector3 fromPos, string fromName,
  85. LLUUID fromID, bool fromAgent)
  86. {
  87. SimChat(message, type, channel, fromPos, fromName, fromID, fromAgent, true);
  88. }
  89. /// <summary>
  90. /// Invoked when the client selects a prim.
  91. /// </summary>
  92. /// <param name="primLocalID"></param>
  93. /// <param name="remoteClient"></param>
  94. public void SelectPrim(uint primLocalID, IClientAPI remoteClient)
  95. {
  96. List<EntityBase> EntityList = GetEntities();
  97. foreach (EntityBase ent in EntityList)
  98. {
  99. if (ent is SceneObjectGroup)
  100. {
  101. if (((SceneObjectGroup) ent).LocalId == primLocalID)
  102. {
  103. ((SceneObjectGroup) ent).GetProperties(remoteClient);
  104. ((SceneObjectGroup) ent).IsSelected = true;
  105. // A prim is only tainted if it's allowed to be edited by the person clicking it.
  106. if (ExternalChecks.ExternalChecksCanEditObject(((SceneObjectGroup)ent).UUID, remoteClient.AgentId) || ExternalChecks.ExternalChecksCanMoveObject(((SceneObjectGroup)ent).UUID, remoteClient.AgentId))
  107. {
  108. EventManager.TriggerParcelPrimCountTainted();
  109. }
  110. break;
  111. }
  112. }
  113. }
  114. }
  115. /// <summary>
  116. ///
  117. /// </summary>
  118. /// <param name="primLocalID"></param>
  119. /// <param name="remoteClient"></param>
  120. public void DeselectPrim(uint primLocalID, IClientAPI remoteClient)
  121. {
  122. List<EntityBase> EntityList = GetEntities();
  123. foreach (EntityBase ent in EntityList)
  124. {
  125. if (ent is SceneObjectGroup)
  126. {
  127. if (((SceneObjectGroup) ent).LocalId == primLocalID)
  128. {
  129. ((SceneObjectGroup) ent).IsSelected = false;
  130. ((SceneObjectGroup)ent).ScheduleGroupForFullUpdate();
  131. if (ExternalChecks.ExternalChecksCanEditObject(((SceneObjectGroup)ent).UUID, remoteClient.AgentId) || ExternalChecks.ExternalChecksCanMoveObject(((SceneObjectGroup)ent).UUID, remoteClient.AgentId))
  132. {
  133. EventManager.TriggerParcelPrimCountTainted();
  134. break;
  135. }
  136. }
  137. }
  138. }
  139. }
  140. public virtual void ProcessMoneyTransferRequest(LLUUID source, LLUUID destination, int amount, int transactiontype, string description)
  141. {
  142. EventManager.MoneyTransferArgs args = new EventManager.MoneyTransferArgs(
  143. source, destination, amount, transactiontype, description);
  144. EventManager.TriggerMoneyTransfer(this, args);
  145. }
  146. public virtual void ProcessParcelBuy(LLUUID agentId, LLUUID groupId, bool final, bool groupOwned,
  147. bool removeContribution, int parcelLocalID, int parcelArea, int parcelPrice, bool authenticated)
  148. {
  149. EventManager.LandBuyArgs args = new EventManager.LandBuyArgs(
  150. agentId, groupId, final, groupOwned, removeContribution, parcelLocalID, parcelArea, parcelPrice, authenticated);
  151. // First, allow all validators a stab at it
  152. m_eventManager.TriggerValidateLandBuy(this, args);
  153. // Then, check validation and transfer
  154. m_eventManager.TriggerLandBuy(this, args);
  155. }
  156. public virtual void ProcessObjectGrab(uint localID, LLVector3 offsetPos, IClientAPI remoteClient)
  157. {
  158. List<EntityBase> EntityList = GetEntities();
  159. foreach (EntityBase ent in EntityList)
  160. {
  161. if (ent is SceneObjectGroup)
  162. {
  163. SceneObjectGroup obj = ent as SceneObjectGroup;
  164. if (obj != null)
  165. {
  166. // Is this prim part of the group
  167. if (obj.HasChildPrim(localID))
  168. {
  169. // Currently only grab/touch for the single prim
  170. // the client handles rez correctly
  171. obj.ObjectGrabHandler(localID, offsetPos, remoteClient);
  172. SceneObjectPart part = obj.GetChildPart(localID);
  173. // If the touched prim handles touches, deliver it
  174. // If not, deliver to root prim
  175. if ((part.ScriptEvents & scriptEvents.touch_start) != 0)
  176. EventManager.TriggerObjectGrab(part.LocalId, part.OffsetPosition, remoteClient);
  177. else
  178. EventManager.TriggerObjectGrab(obj.RootPart.LocalId, part.OffsetPosition, remoteClient);
  179. return;
  180. }
  181. }
  182. }
  183. }
  184. }
  185. public virtual void ProcessObjectDeGrab(uint localID, IClientAPI remoteClient)
  186. {
  187. List<EntityBase> EntityList = GetEntities();
  188. foreach (EntityBase ent in EntityList)
  189. {
  190. if (ent is SceneObjectGroup)
  191. {
  192. SceneObjectGroup obj = ent as SceneObjectGroup;
  193. // Is this prim part of the group
  194. if (obj.HasChildPrim(localID))
  195. {
  196. SceneObjectPart part=obj.GetChildPart(localID);
  197. if (part != null)
  198. {
  199. // If the touched prim handles touches, deliver it
  200. // If not, deliver to root prim
  201. if ((part.ScriptEvents & scriptEvents.touch_end) != 0)
  202. EventManager.TriggerObjectDeGrab(part.LocalId, remoteClient);
  203. else
  204. EventManager.TriggerObjectDeGrab(obj.RootPart.LocalId, remoteClient);
  205. return;
  206. }
  207. return;
  208. }
  209. }
  210. }
  211. }
  212. public void ProcessAvatarPickerRequest(IClientAPI client, LLUUID avatarID, LLUUID RequestID, string query)
  213. {
  214. //EventManager.TriggerAvatarPickerRequest();
  215. List<AvatarPickerAvatar> AvatarResponses = new List<AvatarPickerAvatar>();
  216. AvatarResponses = m_sceneGridService.GenerateAgentPickerRequestResponse(RequestID, query);
  217. AvatarPickerReplyPacket replyPacket = (AvatarPickerReplyPacket) PacketPool.Instance.GetPacket(PacketType.AvatarPickerReply);
  218. // TODO: don't create new blocks if recycling an old packet
  219. AvatarPickerReplyPacket.DataBlock[] searchData =
  220. new AvatarPickerReplyPacket.DataBlock[AvatarResponses.Count];
  221. AvatarPickerReplyPacket.AgentDataBlock agentData = new AvatarPickerReplyPacket.AgentDataBlock();
  222. agentData.AgentID = avatarID;
  223. agentData.QueryID = RequestID;
  224. replyPacket.AgentData = agentData;
  225. //byte[] bytes = new byte[AvatarResponses.Count*32];
  226. int i = 0;
  227. foreach (AvatarPickerAvatar item in AvatarResponses)
  228. {
  229. LLUUID translatedIDtem = item.AvatarID;
  230. searchData[i] = new AvatarPickerReplyPacket.DataBlock();
  231. searchData[i].AvatarID = translatedIDtem;
  232. searchData[i].FirstName = Helpers.StringToField((string) item.firstName);
  233. searchData[i].LastName = Helpers.StringToField((string) item.lastName);
  234. i++;
  235. }
  236. if (AvatarResponses.Count == 0)
  237. {
  238. searchData = new AvatarPickerReplyPacket.DataBlock[0];
  239. }
  240. replyPacket.Data = searchData;
  241. AvatarPickerReplyAgentDataArgs agent_data = new AvatarPickerReplyAgentDataArgs();
  242. agent_data.AgentID = replyPacket.AgentData.AgentID;
  243. agent_data.QueryID = replyPacket.AgentData.QueryID;
  244. List<AvatarPickerReplyDataArgs> data_args = new List<AvatarPickerReplyDataArgs>();
  245. for (i = 0; i < replyPacket.Data.Length; i++)
  246. {
  247. AvatarPickerReplyDataArgs data_arg = new AvatarPickerReplyDataArgs();
  248. data_arg.AvatarID = replyPacket.Data[i].AvatarID;
  249. data_arg.FirstName = replyPacket.Data[i].FirstName;
  250. data_arg.LastName = replyPacket.Data[i].LastName;
  251. data_args.Add(data_arg);
  252. }
  253. client.SendAvatarPickerReply(agent_data, data_args);
  254. }
  255. public void ProcessScriptReset(IClientAPI remoteClient, LLUUID objectID,
  256. LLUUID itemID)
  257. {
  258. SceneObjectPart part=GetSceneObjectPart(objectID);
  259. if (part == null)
  260. return;
  261. if (ExternalChecks.ExternalChecksCanResetScript(itemID, remoteClient.AgentId))
  262. {
  263. EventManager.TriggerScriptReset(part.LocalId, itemID);
  264. }
  265. }
  266. }
  267. }