CapabilitiesModule.cs 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230
  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 copyrightD
  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 OpenSimulator 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;
  28. using System.Collections.Generic;
  29. using System.Reflection;
  30. using log4net;
  31. using Nini.Config;
  32. using OpenMetaverse;
  33. using OpenSim.Framework;
  34. using OpenSim.Region.Framework.Interfaces;
  35. using OpenSim.Region.Framework.Scenes;
  36. using Caps=OpenSim.Framework.Capabilities.Caps;
  37. namespace OpenSim.Region.CoreModules.Agent.Capabilities
  38. {
  39. public class CapabilitiesModule : INonSharedRegionModule, ICapabilitiesModule
  40. {
  41. private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
  42. protected Scene m_scene;
  43. /// <summary>
  44. /// Each agent has its own capabilities handler.
  45. /// </summary>
  46. protected Dictionary<UUID, Caps> m_capsHandlers = new Dictionary<UUID, Caps>();
  47. protected Dictionary<UUID, string> capsPaths = new Dictionary<UUID, string>();
  48. protected Dictionary<UUID, Dictionary<ulong, string>> childrenSeeds
  49. = new Dictionary<UUID, Dictionary<ulong, string>>();
  50. public void Initialise(IConfigSource source)
  51. {
  52. }
  53. public void AddRegion(Scene scene)
  54. {
  55. m_scene = scene;
  56. m_scene.RegisterModuleInterface<ICapabilitiesModule>(this);
  57. }
  58. public void RegionLoaded(Scene scene)
  59. {
  60. }
  61. public void RemoveRegion(Scene scene)
  62. {
  63. m_scene.UnregisterModuleInterface<ICapabilitiesModule>(this);
  64. }
  65. public void PostInitialise() {}
  66. public void Close() {}
  67. public string Name
  68. {
  69. get { return "Capabilities Module"; }
  70. }
  71. public Type ReplaceableInterface
  72. {
  73. get { return null; }
  74. }
  75. public void AddCapsHandler(UUID agentId)
  76. {
  77. if (m_scene.RegionInfo.EstateSettings.IsBanned(agentId))
  78. return;
  79. String capsObjectPath = GetCapsPath(agentId);
  80. if (m_capsHandlers.ContainsKey(agentId))
  81. {
  82. Caps oldCaps = m_capsHandlers[agentId];
  83. m_log.DebugFormat(
  84. "[CAPS]: Reregistering caps for agent {0}. Old caps path {1}, new caps path {2}. ",
  85. agentId, oldCaps.CapsObjectPath, capsObjectPath);
  86. // This should not happen. The caller code is confused. We need to fix that.
  87. // CAPs can never be reregistered, or the client will be confused.
  88. // Hence this return here.
  89. //return;
  90. }
  91. Caps caps
  92. = new Caps(m_scene,
  93. m_scene.AssetService, MainServer.Instance, m_scene.RegionInfo.ExternalHostName,
  94. (MainServer.Instance == null) ? 0: MainServer.Instance.Port,
  95. capsObjectPath, agentId, m_scene.DumpAssetsToFile, m_scene.RegionInfo.RegionName);
  96. caps.RegisterHandlers();
  97. m_scene.EventManager.TriggerOnRegisterCaps(agentId, caps);
  98. caps.AddNewInventoryItem = m_scene.AddUploadedInventoryItem;
  99. caps.ItemUpdatedCall = m_scene.CapsUpdateInventoryItemAsset;
  100. caps.TaskScriptUpdatedCall = m_scene.CapsUpdateTaskInventoryScriptAsset;
  101. caps.CAPSFetchInventoryDescendents = m_scene.HandleFetchInventoryDescendentsCAPS;
  102. caps.GetClient = m_scene.SceneContents.GetControllingClient;
  103. m_capsHandlers[agentId] = caps;
  104. }
  105. public void RemoveCapsHandler(UUID agentId)
  106. {
  107. if (childrenSeeds.ContainsKey(agentId))
  108. {
  109. childrenSeeds.Remove(agentId);
  110. }
  111. lock (m_capsHandlers)
  112. {
  113. if (m_capsHandlers.ContainsKey(agentId))
  114. {
  115. m_capsHandlers[agentId].DeregisterHandlers();
  116. m_scene.EventManager.TriggerOnDeregisterCaps(agentId, m_capsHandlers[agentId]);
  117. m_capsHandlers.Remove(agentId);
  118. }
  119. else
  120. {
  121. m_log.WarnFormat(
  122. "[CAPS]: Received request to remove CAPS handler for root agent {0} in {1}, but no such CAPS handler found!",
  123. agentId, m_scene.RegionInfo.RegionName);
  124. }
  125. }
  126. }
  127. public Caps GetCapsHandlerForUser(UUID agentId)
  128. {
  129. lock (m_capsHandlers)
  130. {
  131. if (m_capsHandlers.ContainsKey(agentId))
  132. {
  133. return m_capsHandlers[agentId];
  134. }
  135. }
  136. return null;
  137. }
  138. public void NewUserConnection(AgentCircuitData agent)
  139. {
  140. capsPaths[agent.AgentID] = agent.CapsPath;
  141. childrenSeeds[agent.AgentID]
  142. = ((agent.ChildrenCapSeeds == null) ? new Dictionary<ulong, string>() : agent.ChildrenCapSeeds);
  143. }
  144. public string GetCapsPath(UUID agentId)
  145. {
  146. if (capsPaths.ContainsKey(agentId))
  147. {
  148. return capsPaths[agentId];
  149. }
  150. return null;
  151. }
  152. public Dictionary<ulong, string> GetChildrenSeeds(UUID agentID)
  153. {
  154. Dictionary<ulong, string> seeds = null;
  155. if (childrenSeeds.TryGetValue(agentID, out seeds))
  156. return seeds;
  157. return new Dictionary<ulong, string>();
  158. }
  159. public void DropChildSeed(UUID agentID, ulong handle)
  160. {
  161. Dictionary<ulong, string> seeds;
  162. if (childrenSeeds.TryGetValue(agentID, out seeds))
  163. {
  164. seeds.Remove(handle);
  165. }
  166. }
  167. public string GetChildSeed(UUID agentID, ulong handle)
  168. {
  169. Dictionary<ulong, string> seeds;
  170. string returnval;
  171. if (childrenSeeds.TryGetValue(agentID, out seeds))
  172. {
  173. if (seeds.TryGetValue(handle, out returnval))
  174. return returnval;
  175. }
  176. return null;
  177. }
  178. public void SetChildrenSeed(UUID agentID, Dictionary<ulong, string> seeds)
  179. {
  180. //m_log.DebugFormat(" !!! Setting child seeds in {0} to {1}", m_scene.RegionInfo.RegionName, seeds.Count);
  181. childrenSeeds[agentID] = seeds;
  182. }
  183. public void DumpChildrenSeeds(UUID agentID)
  184. {
  185. m_log.Info("================ ChildrenSeed "+m_scene.RegionInfo.RegionName+" ================");
  186. foreach (KeyValuePair<ulong, string> kvp in childrenSeeds[agentID])
  187. {
  188. uint x, y;
  189. Utils.LongToUInts(kvp.Key, out x, out y);
  190. x = x / Constants.RegionSize;
  191. y = y / Constants.RegionSize;
  192. m_log.Info(" >> "+x+", "+y+": "+kvp.Value);
  193. }
  194. }
  195. }
  196. }