CapabilitiesModule.cs 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208
  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 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;
  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.Communications.Capabilities.Caps;
  37. namespace OpenSim.Region.CoreModules.Agent.Capabilities
  38. {
  39. public class CapabilitiesModule : IRegionModule, 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(Scene scene, IConfigSource source)
  51. {
  52. m_scene = scene;
  53. m_scene.RegisterModuleInterface<ICapabilitiesModule>(this);
  54. }
  55. public void PostInitialise() {}
  56. public void Close() {}
  57. public string Name { get { return "Capabilities Module"; } }
  58. public bool IsSharedModule { get { return false; } }
  59. public void AddCapsHandler(UUID agentId)
  60. {
  61. if (m_scene.RegionInfo.EstateSettings.IsBanned(agentId))
  62. return;
  63. String capsObjectPath = GetCapsPath(agentId);
  64. if (m_capsHandlers.ContainsKey(agentId))
  65. {
  66. Caps oldCaps = m_capsHandlers[agentId];
  67. m_log.DebugFormat(
  68. "[CAPS]: Reregistering caps for agent {0}. Old caps path {1}, new caps path {2}. ",
  69. agentId, oldCaps.CapsObjectPath, capsObjectPath);
  70. // This should not happen. The caller code is confused. We need to fix that.
  71. // CAPs can never be reregistered, or the client will be confused.
  72. // Hence this return here.
  73. //return;
  74. }
  75. Caps caps
  76. = new Caps(
  77. m_scene.CommsManager.AssetCache, m_scene.CommsManager.HttpServer, m_scene.RegionInfo.ExternalHostName,
  78. m_scene.CommsManager.HttpServer.Port,
  79. capsObjectPath, agentId, m_scene.DumpAssetsToFile, m_scene.RegionInfo.RegionName);
  80. caps.RegisterHandlers();
  81. m_scene.EventManager.TriggerOnRegisterCaps(agentId, caps);
  82. caps.AddNewInventoryItem = m_scene.AddUploadedInventoryItem;
  83. caps.ItemUpdatedCall = m_scene.CapsUpdateInventoryItemAsset;
  84. caps.TaskScriptUpdatedCall = m_scene.CapsUpdateTaskInventoryScriptAsset;
  85. caps.CAPSFetchInventoryDescendents = m_scene.HandleFetchInventoryDescendentsCAPS;
  86. caps.GetClient = m_scene.SceneContents.GetControllingClient;
  87. m_capsHandlers[agentId] = caps;
  88. }
  89. public void RemoveCapsHandler(UUID agentId)
  90. {
  91. if (childrenSeeds.ContainsKey(agentId))
  92. {
  93. childrenSeeds.Remove(agentId);
  94. }
  95. lock (m_capsHandlers)
  96. {
  97. if (m_capsHandlers.ContainsKey(agentId))
  98. {
  99. m_capsHandlers[agentId].DeregisterHandlers();
  100. m_scene.EventManager.TriggerOnDeregisterCaps(agentId, m_capsHandlers[agentId]);
  101. m_capsHandlers.Remove(agentId);
  102. }
  103. else
  104. {
  105. m_log.WarnFormat(
  106. "[CAPS]: Received request to remove CAPS handler for root agent {0} in {1}, but no such CAPS handler found!",
  107. agentId, m_scene.RegionInfo.RegionName);
  108. }
  109. }
  110. }
  111. public Caps GetCapsHandlerForUser(UUID agentId)
  112. {
  113. lock (m_capsHandlers)
  114. {
  115. if (m_capsHandlers.ContainsKey(agentId))
  116. {
  117. return m_capsHandlers[agentId];
  118. }
  119. }
  120. return null;
  121. }
  122. public void NewUserConnection(AgentCircuitData agent)
  123. {
  124. capsPaths[agent.AgentID] = agent.CapsPath;
  125. childrenSeeds[agent.AgentID]
  126. = ((agent.ChildrenCapSeeds == null) ? new Dictionary<ulong, string>() : agent.ChildrenCapSeeds);
  127. }
  128. public string GetCapsPath(UUID agentId)
  129. {
  130. if (capsPaths.ContainsKey(agentId))
  131. {
  132. return capsPaths[agentId];
  133. }
  134. return null;
  135. }
  136. public Dictionary<ulong, string> GetChildrenSeeds(UUID agentID)
  137. {
  138. Dictionary<ulong, string> seeds = null;
  139. if (childrenSeeds.TryGetValue(agentID, out seeds))
  140. return seeds;
  141. return new Dictionary<ulong, string>();
  142. }
  143. public void DropChildSeed(UUID agentID, ulong handle)
  144. {
  145. Dictionary<ulong, string> seeds;
  146. if (childrenSeeds.TryGetValue(agentID, out seeds))
  147. {
  148. seeds.Remove(handle);
  149. }
  150. }
  151. public string GetChildSeed(UUID agentID, ulong handle)
  152. {
  153. Dictionary<ulong, string> seeds;
  154. string returnval;
  155. if (childrenSeeds.TryGetValue(agentID, out seeds))
  156. {
  157. if (seeds.TryGetValue(handle, out returnval))
  158. return returnval;
  159. }
  160. return null;
  161. }
  162. public void SetChildrenSeed(UUID agentID, Dictionary<ulong, string> seeds)
  163. {
  164. //m_log.Debug(" !!! Setting child seeds in {0} to {1}", RegionInfo.RegionName, value.Count);
  165. childrenSeeds[agentID] = seeds;
  166. }
  167. public void DumpChildrenSeeds(UUID agentID)
  168. {
  169. m_log.Info("================ ChildrenSeed "+m_scene.RegionInfo.RegionName+" ================");
  170. foreach (KeyValuePair<ulong, string> kvp in childrenSeeds[agentID])
  171. {
  172. uint x, y;
  173. Utils.LongToUInts(kvp.Key, out x, out y);
  174. x = x / Constants.RegionSize;
  175. y = y / Constants.RegionSize;
  176. m_log.Info(" >> "+x+", "+y+": "+kvp.Value);
  177. }
  178. }
  179. }
  180. }