aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/Environment/Modules/Agent/Capabilities
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--OpenSim/Region/Environment/Modules/Agent/Capabilities/CapabilitiesModule.cs204
1 files changed, 204 insertions, 0 deletions
diff --git a/OpenSim/Region/Environment/Modules/Agent/Capabilities/CapabilitiesModule.cs b/OpenSim/Region/Environment/Modules/Agent/Capabilities/CapabilitiesModule.cs
new file mode 100644
index 0000000..9fa6d7d
--- /dev/null
+++ b/OpenSim/Region/Environment/Modules/Agent/Capabilities/CapabilitiesModule.cs
@@ -0,0 +1,204 @@
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
28using System;
29using System.Collections.Generic;
30using System.Reflection;
31using log4net;
32using Nini.Config;
33using OpenMetaverse;
34using OpenSim.Framework;
35using OpenSim.Framework.Communications.Cache;
36using OpenSim.Framework.Communications.Capabilities;
37using OpenSim.Region.Environment.Interfaces;
38using OpenSim.Region.Environment.Scenes;
39using Caps = OpenSim.Framework.Communications.Capabilities.Caps;
40
41namespace OpenSim.Region.Environment.Modules.Agent.Capabilities
42{
43 public class CapabilitiesModule : IRegionModule, ICapabilitiesModule
44 {
45 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
46
47 protected Scene m_scene;
48
49 /// <summary>
50 /// Each agent has its own capabilities handler.
51 /// </summary>
52 protected Dictionary<UUID, Caps> m_capsHandlers = new Dictionary<UUID, Caps>();
53
54 protected Dictionary<UUID, string> capsPaths = new Dictionary<UUID, string>();
55 protected Dictionary<UUID, Dictionary<ulong, string>> childrenSeeds
56 = new Dictionary<UUID, Dictionary<ulong, string>>();
57
58 public void Initialise(Scene scene, IConfigSource source)
59 {
60 m_scene = scene;
61 m_scene.RegisterModuleInterface<ICapabilitiesModule>(this);
62 }
63
64 public void PostInitialise() {}
65 public void Close() {}
66 public string Name { get { return "Capabilities Module"; } }
67 public bool IsSharedModule { get { return false; } }
68
69 public void AddCapsHandler(UUID agentId)
70 {
71 if (m_scene.RegionInfo.EstateSettings.IsBanned(agentId))
72 return;
73
74 String capsObjectPath = GetCapsPath(agentId);
75
76 Caps cap = null;
77 if (m_capsHandlers.TryGetValue(agentId, out cap))
78 {
79 m_log.DebugFormat(
80 "[CAPS]: Attempt at registering twice for the same agent {0}. {1}. Ignoring.",
81 agentId, capsObjectPath);
82 //return;
83 }
84
85 cap
86 = new Caps(
87 m_scene.AssetCache, m_scene.CommsManager.HttpServer, m_scene.RegionInfo.ExternalHostName,
88 m_scene.CommsManager.HttpServer.Port,
89 capsObjectPath, agentId, m_scene.DumpAssetsToFile, m_scene.RegionInfo.RegionName);
90
91 cap.RegisterHandlers();
92
93 m_scene.EventManager.TriggerOnRegisterCaps(agentId, cap);
94
95 cap.AddNewInventoryItem = m_scene.AddUploadedInventoryItem;
96 cap.ItemUpdatedCall = m_scene.CapsUpdateInventoryItemAsset;
97 cap.TaskScriptUpdatedCall = m_scene.CapsUpdateTaskInventoryScriptAsset;
98 cap.CAPSFetchInventoryDescendents = m_scene.HandleFetchInventoryDescendentsCAPS;
99 cap.GetClient = m_scene.m_sceneGraph.GetControllingClient;
100
101 m_capsHandlers[agentId] = cap;
102 }
103
104 public void RemoveCapsHandler(UUID agentId)
105 {
106 if (childrenSeeds.ContainsKey(agentId))
107 {
108 childrenSeeds.Remove(agentId);
109 }
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
118 m_capsHandlers.Remove(agentId);
119 }
120 else
121 {
122 m_log.WarnFormat(
123 "[CAPS]: Received request to remove CAPS handler for root agent {0} in {1}, but no such CAPS handler found!",
124 agentId, m_scene.RegionInfo.RegionName);
125 }
126 }
127 }
128
129 public Caps GetCapsHandlerForUser(UUID agentId)
130 {
131 lock (m_capsHandlers)
132 {
133 if (m_capsHandlers.ContainsKey(agentId))
134 {
135 return m_capsHandlers[agentId];
136 }
137 }
138
139 return null;
140 }
141
142 public void NewUserConnection(AgentCircuitData agent)
143 {
144 capsPaths[agent.AgentID] = agent.CapsPath;
145 childrenSeeds[agent.AgentID] = ((agent.ChildrenCapSeeds == null) ? new Dictionary<ulong, string>() : agent.ChildrenCapSeeds);
146 }
147
148 public string GetCapsPath(UUID agentId)
149 {
150 if (capsPaths.ContainsKey(agentId))
151 {
152 return capsPaths[agentId];
153 }
154
155 return null;
156 }
157
158 public Dictionary<ulong, string> GetChildrenSeeds(UUID agentID)
159 {
160 Dictionary<ulong, string> seeds = null;
161 if (childrenSeeds.TryGetValue(agentID, out seeds))
162 return seeds;
163 return new Dictionary<ulong, string>();
164 }
165
166 public void DropChildSeed(UUID agentID, ulong handle)
167 {
168 Dictionary<ulong, string> seeds;
169 if (childrenSeeds.TryGetValue(agentID, out seeds))
170 {
171 seeds.Remove(handle);
172 }
173 }
174
175 public string GetChildSeed(UUID agentID, ulong handle)
176 {
177 Dictionary<ulong, string> seeds;
178 if (childrenSeeds.TryGetValue(agentID, out seeds))
179 {
180 return seeds[handle];
181 }
182 return null;
183 }
184
185 public void SetChildrenSeed(UUID agentID, Dictionary<ulong, string> seeds)
186 {
187 //Console.WriteLine(" !!! Setting child seeds in {0} to {1}", RegionInfo.RegionName, value.Count);
188 childrenSeeds[agentID] = seeds;
189 }
190
191 public void DumpChildrenSeeds(UUID agentID)
192 {
193 Console.WriteLine("================ ChildrenSeed {0} ================", m_scene.RegionInfo.RegionName);
194 foreach (KeyValuePair<ulong, string> kvp in childrenSeeds[agentID])
195 {
196 uint x, y;
197 Utils.LongToUInts(kvp.Key, out x, out y);
198 x = x / Constants.RegionSize;
199 y = y / Constants.RegionSize;
200 Console.WriteLine(" >> {0}, {1}: {2}", x, y, kvp.Value);
201 }
202 }
203 }
204} \ No newline at end of file