CapabilitiesModule.cs 8.0 KB

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