aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/CoreModules/Framework/Caps/CapabilitiesModule.cs
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim/Region/CoreModules/Framework/Caps/CapabilitiesModule.cs')
-rw-r--r--OpenSim/Region/CoreModules/Framework/Caps/CapabilitiesModule.cs249
1 files changed, 249 insertions, 0 deletions
diff --git a/OpenSim/Region/CoreModules/Framework/Caps/CapabilitiesModule.cs b/OpenSim/Region/CoreModules/Framework/Caps/CapabilitiesModule.cs
new file mode 100644
index 0000000..111d808
--- /dev/null
+++ b/OpenSim/Region/CoreModules/Framework/Caps/CapabilitiesModule.cs
@@ -0,0 +1,249 @@
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
28using System;
29using System.Collections;
30using System.Collections.Generic;
31using System.Reflection;
32using log4net;
33using Nini.Config;
34using Mono.Addins;
35using OpenMetaverse;
36using OpenSim.Framework;
37using OpenSim.Framework.Console;
38using OpenSim.Region.Framework.Interfaces;
39using OpenSim.Region.Framework.Scenes;
40using Caps=OpenSim.Framework.Capabilities.Caps;
41
42namespace OpenSim.Region.CoreModules.Framework
43{
44 [Extension(Path = "/OpenSim/RegionModules", NodeName = "RegionModule")]
45 public class CapabilitiesModule : INonSharedRegionModule, ICapabilitiesModule
46 {
47 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
48
49 protected Scene m_scene;
50
51 /// <summary>
52 /// Each agent has its own capabilities handler.
53 /// </summary>
54 protected Dictionary<UUID, Caps> m_capsObjects = new Dictionary<UUID, Caps>();
55
56 protected Dictionary<UUID, string> capsPaths = new Dictionary<UUID, string>();
57 protected Dictionary<UUID, Dictionary<ulong, string>> childrenSeeds
58 = new Dictionary<UUID, Dictionary<ulong, string>>();
59
60 public void Initialise(IConfigSource source)
61 {
62 }
63
64 public void AddRegion(Scene scene)
65 {
66 m_scene = scene;
67 m_scene.RegisterModuleInterface<ICapabilitiesModule>(this);
68 MainConsole.Instance.Commands.AddCommand("Capabilities", false, "show caps",
69 "show capabilities",
70 "Shows all registered capabilities", CapabilitiesCommand);
71 }
72
73 public void RegionLoaded(Scene scene)
74 {
75 }
76
77 public void RemoveRegion(Scene scene)
78 {
79 m_scene.UnregisterModuleInterface<ICapabilitiesModule>(this);
80 }
81
82 public void PostInitialise()
83 {
84 }
85
86 public void Close() {}
87
88 public string Name
89 {
90 get { return "Capabilities Module"; }
91 }
92
93 public Type ReplaceableInterface
94 {
95 get { return null; }
96 }
97
98 public void CreateCaps(UUID agentId)
99 {
100 if (m_scene.RegionInfo.EstateSettings.IsBanned(agentId))
101 return;
102
103 String capsObjectPath = GetCapsPath(agentId);
104
105 if (m_capsObjects.ContainsKey(agentId))
106 {
107 Caps oldCaps = m_capsObjects[agentId];
108
109 m_log.DebugFormat(
110 "[CAPS]: Recreating caps for agent {0}. Old caps path {1}, new caps path {2}. ",
111 agentId, oldCaps.CapsObjectPath, capsObjectPath);
112 // This should not happen. The caller code is confused. We need to fix that.
113 // CAPs can never be reregistered, or the client will be confused.
114 // Hence this return here.
115 //return;
116 }
117
118 Caps caps = new Caps(MainServer.Instance, m_scene.RegionInfo.ExternalHostName,
119 (MainServer.Instance == null) ? 0: MainServer.Instance.Port,
120 capsObjectPath, agentId, m_scene.RegionInfo.RegionName);
121
122 m_capsObjects[agentId] = caps;
123
124 m_scene.EventManager.TriggerOnRegisterCaps(agentId, caps);
125 }
126
127 public void RemoveCaps(UUID agentId)
128 {
129 if (childrenSeeds.ContainsKey(agentId))
130 {
131 childrenSeeds.Remove(agentId);
132 }
133
134 lock (m_capsObjects)
135 {
136 if (m_capsObjects.ContainsKey(agentId))
137 {
138 m_capsObjects[agentId].DeregisterHandlers();
139 m_scene.EventManager.TriggerOnDeregisterCaps(agentId, m_capsObjects[agentId]);
140 m_capsObjects.Remove(agentId);
141 }
142 else
143 {
144 m_log.WarnFormat(
145 "[CAPS]: Received request to remove CAPS handler for root agent {0} in {1}, but no such CAPS handler found!",
146 agentId, m_scene.RegionInfo.RegionName);
147 }
148 }
149 }
150
151 public Caps GetCapsForUser(UUID agentId)
152 {
153 lock (m_capsObjects)
154 {
155 if (m_capsObjects.ContainsKey(agentId))
156 {
157 return m_capsObjects[agentId];
158 }
159 }
160
161 return null;
162 }
163
164 public void SetAgentCapsSeeds(AgentCircuitData agent)
165 {
166 capsPaths[agent.AgentID] = agent.CapsPath;
167 childrenSeeds[agent.AgentID]
168 = ((agent.ChildrenCapSeeds == null) ? new Dictionary<ulong, string>() : agent.ChildrenCapSeeds);
169 }
170
171 public string GetCapsPath(UUID agentId)
172 {
173 if (capsPaths.ContainsKey(agentId))
174 {
175 return capsPaths[agentId];
176 }
177
178 return null;
179 }
180
181 public Dictionary<ulong, string> GetChildrenSeeds(UUID agentID)
182 {
183 Dictionary<ulong, string> seeds = null;
184 if (childrenSeeds.TryGetValue(agentID, out seeds))
185 return seeds;
186 return new Dictionary<ulong, string>();
187 }
188
189 public void DropChildSeed(UUID agentID, ulong handle)
190 {
191 Dictionary<ulong, string> seeds;
192 if (childrenSeeds.TryGetValue(agentID, out seeds))
193 {
194 seeds.Remove(handle);
195 }
196 }
197
198 public string GetChildSeed(UUID agentID, ulong handle)
199 {
200 Dictionary<ulong, string> seeds;
201 string returnval;
202 if (childrenSeeds.TryGetValue(agentID, out seeds))
203 {
204 if (seeds.TryGetValue(handle, out returnval))
205 return returnval;
206 }
207 return null;
208 }
209
210 public void SetChildrenSeed(UUID agentID, Dictionary<ulong, string> seeds)
211 {
212 //m_log.DebugFormat(" !!! Setting child seeds in {0} to {1}", m_scene.RegionInfo.RegionName, seeds.Count);
213 childrenSeeds[agentID] = seeds;
214 }
215
216 public void DumpChildrenSeeds(UUID agentID)
217 {
218 m_log.Info("================ ChildrenSeed "+m_scene.RegionInfo.RegionName+" ================");
219 foreach (KeyValuePair<ulong, string> kvp in childrenSeeds[agentID])
220 {
221 uint x, y;
222 Utils.LongToUInts(kvp.Key, out x, out y);
223 x = x / Constants.RegionSize;
224 y = y / Constants.RegionSize;
225 m_log.Info(" >> "+x+", "+y+": "+kvp.Value);
226 }
227 }
228
229 private void CapabilitiesCommand(string module, string[] cmdparams)
230 {
231 System.Text.StringBuilder caps = new System.Text.StringBuilder();
232 caps.AppendFormat("Region {0}:\n", m_scene.RegionInfo.RegionName);
233
234 foreach (KeyValuePair<UUID, Caps> kvp in m_capsObjects)
235 {
236 caps.AppendFormat("** User {0}:\n", kvp.Key);
237 for (IDictionaryEnumerator kvp2 = kvp.Value.CapsHandlers.CapsDetails.GetEnumerator(); kvp2.MoveNext(); )
238 {
239 Uri uri = new Uri(kvp2.Value.ToString());
240 caps.AppendFormat(" {0} = {1}\n", kvp2.Key, uri.PathAndQuery);
241 }
242 foreach (KeyValuePair<string, string> kvp3 in kvp.Value.ExternalCapsHandlers)
243 caps.AppendFormat(" {0} = {1}\n", kvp3.Key, kvp3.Value);
244 }
245
246 MainConsole.Instance.Output(caps.ToString());
247 }
248 }
249}