aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/CoreModules/Framework/Caps
diff options
context:
space:
mode:
authorMelanie2011-05-05 09:49:10 +0100
committerMelanie2011-05-05 09:49:10 +0100
commit4beb0c9b9b402c1e8f70a02c0efa557c1f292f1c (patch)
tree24e24cb7b424df74b13788d28be9d7588fbd99d0 /OpenSim/Region/CoreModules/Framework/Caps
parentMerge branch 'master' into careminster-presence-refactor (diff)
parentTest m_Enabled on RemoveRegion. (diff)
downloadopensim-SC_OLD-4beb0c9b9b402c1e8f70a02c0efa557c1f292f1c.zip
opensim-SC_OLD-4beb0c9b9b402c1e8f70a02c0efa557c1f292f1c.tar.gz
opensim-SC_OLD-4beb0c9b9b402c1e8f70a02c0efa557c1f292f1c.tar.bz2
opensim-SC_OLD-4beb0c9b9b402c1e8f70a02c0efa557c1f292f1c.tar.xz
Merge branch 'master' into careminster-presence-refactor
Diffstat (limited to 'OpenSim/Region/CoreModules/Framework/Caps')
-rw-r--r--OpenSim/Region/CoreModules/Framework/Caps/CapabilitiesModule.cs250
1 files changed, 250 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..b823fec
--- /dev/null
+++ b/OpenSim/Region/CoreModules/Framework/Caps/CapabilitiesModule.cs
@@ -0,0 +1,250 @@
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 int flags = m_scene.GetUserFlags(agentId);
101 if (m_scene.RegionInfo.EstateSettings.IsBanned(agentId, flags))
102 return;
103
104 String capsObjectPath = GetCapsPath(agentId);
105
106 if (m_capsObjects.ContainsKey(agentId))
107 {
108 Caps oldCaps = m_capsObjects[agentId];
109
110 m_log.DebugFormat(
111 "[CAPS]: Recreating caps for agent {0}. Old caps path {1}, new caps path {2}. ",
112 agentId, oldCaps.CapsObjectPath, capsObjectPath);
113 // This should not happen. The caller code is confused. We need to fix that.
114 // CAPs can never be reregistered, or the client will be confused.
115 // Hence this return here.
116 //return;
117 }
118
119 Caps caps = new Caps(MainServer.Instance, m_scene.RegionInfo.ExternalHostName,
120 (MainServer.Instance == null) ? 0: MainServer.Instance.Port,
121 capsObjectPath, agentId, m_scene.RegionInfo.RegionName);
122
123 m_capsObjects[agentId] = caps;
124
125 m_scene.EventManager.TriggerOnRegisterCaps(agentId, caps);
126 }
127
128 public void RemoveCaps(UUID agentId)
129 {
130 if (childrenSeeds.ContainsKey(agentId))
131 {
132 childrenSeeds.Remove(agentId);
133 }
134
135 lock (m_capsObjects)
136 {
137 if (m_capsObjects.ContainsKey(agentId))
138 {
139 m_capsObjects[agentId].DeregisterHandlers();
140 m_scene.EventManager.TriggerOnDeregisterCaps(agentId, m_capsObjects[agentId]);
141 m_capsObjects.Remove(agentId);
142 }
143 else
144 {
145 m_log.WarnFormat(
146 "[CAPS]: Received request to remove CAPS handler for root agent {0} in {1}, but no such CAPS handler found!",
147 agentId, m_scene.RegionInfo.RegionName);
148 }
149 }
150 }
151
152 public Caps GetCapsForUser(UUID agentId)
153 {
154 lock (m_capsObjects)
155 {
156 if (m_capsObjects.ContainsKey(agentId))
157 {
158 return m_capsObjects[agentId];
159 }
160 }
161
162 return null;
163 }
164
165 public void SetAgentCapsSeeds(AgentCircuitData agent)
166 {
167 capsPaths[agent.AgentID] = agent.CapsPath;
168 childrenSeeds[agent.AgentID]
169 = ((agent.ChildrenCapSeeds == null) ? new Dictionary<ulong, string>() : agent.ChildrenCapSeeds);
170 }
171
172 public string GetCapsPath(UUID agentId)
173 {
174 if (capsPaths.ContainsKey(agentId))
175 {
176 return capsPaths[agentId];
177 }
178
179 return null;
180 }
181
182 public Dictionary<ulong, string> GetChildrenSeeds(UUID agentID)
183 {
184 Dictionary<ulong, string> seeds = null;
185 if (childrenSeeds.TryGetValue(agentID, out seeds))
186 return seeds;
187 return new Dictionary<ulong, string>();
188 }
189
190 public void DropChildSeed(UUID agentID, ulong handle)
191 {
192 Dictionary<ulong, string> seeds;
193 if (childrenSeeds.TryGetValue(agentID, out seeds))
194 {
195 seeds.Remove(handle);
196 }
197 }
198
199 public string GetChildSeed(UUID agentID, ulong handle)
200 {
201 Dictionary<ulong, string> seeds;
202 string returnval;
203 if (childrenSeeds.TryGetValue(agentID, out seeds))
204 {
205 if (seeds.TryGetValue(handle, out returnval))
206 return returnval;
207 }
208 return null;
209 }
210
211 public void SetChildrenSeed(UUID agentID, Dictionary<ulong, string> seeds)
212 {
213 //m_log.DebugFormat(" !!! Setting child seeds in {0} to {1}", m_scene.RegionInfo.RegionName, seeds.Count);
214 childrenSeeds[agentID] = seeds;
215 }
216
217 public void DumpChildrenSeeds(UUID agentID)
218 {
219 m_log.Info("================ ChildrenSeed "+m_scene.RegionInfo.RegionName+" ================");
220 foreach (KeyValuePair<ulong, string> kvp in childrenSeeds[agentID])
221 {
222 uint x, y;
223 Utils.LongToUInts(kvp.Key, out x, out y);
224 x = x / Constants.RegionSize;
225 y = y / Constants.RegionSize;
226 m_log.Info(" >> "+x+", "+y+": "+kvp.Value);
227 }
228 }
229
230 private void CapabilitiesCommand(string module, string[] cmdparams)
231 {
232 System.Text.StringBuilder caps = new System.Text.StringBuilder();
233 caps.AppendFormat("Region {0}:\n", m_scene.RegionInfo.RegionName);
234
235 foreach (KeyValuePair<UUID, Caps> kvp in m_capsObjects)
236 {
237 caps.AppendFormat("** User {0}:\n", kvp.Key);
238 for (IDictionaryEnumerator kvp2 = kvp.Value.CapsHandlers.CapsDetails.GetEnumerator(); kvp2.MoveNext(); )
239 {
240 Uri uri = new Uri(kvp2.Value.ToString());
241 caps.AppendFormat(" {0} = {1}\n", kvp2.Key, uri.PathAndQuery);
242 }
243 foreach (KeyValuePair<string, string> kvp3 in kvp.Value.ExternalCapsHandlers)
244 caps.AppendFormat(" {0} = {1}\n", kvp3.Key, kvp3.Value);
245 }
246
247 MainConsole.Instance.Output(caps.ToString());
248 }
249 }
250}