diff options
Diffstat (limited to 'OpenSim')
-rw-r--r-- | OpenSim/Region/ClientStack/Linden/Caps/EstateAccess.cs | 226 |
1 files changed, 226 insertions, 0 deletions
diff --git a/OpenSim/Region/ClientStack/Linden/Caps/EstateAccess.cs b/OpenSim/Region/ClientStack/Linden/Caps/EstateAccess.cs new file mode 100644 index 0000000..c76e047 --- /dev/null +++ b/OpenSim/Region/ClientStack/Linden/Caps/EstateAccess.cs | |||
@@ -0,0 +1,226 @@ | |||
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 copyright | ||
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 | |||
28 | using System; | ||
29 | using System.Collections; | ||
30 | using System.Collections.Generic; | ||
31 | using System.Text; | ||
32 | |||
33 | using log4net; | ||
34 | using Nini.Config; | ||
35 | using OpenMetaverse; | ||
36 | using Mono.Addins; | ||
37 | using OpenSim.Framework; | ||
38 | using OpenSim.Framework.Servers.HttpServer; | ||
39 | using OpenSim.Region.Framework.Interfaces; | ||
40 | using OpenSim.Region.Framework.Scenes; | ||
41 | using Caps=OpenSim.Framework.Capabilities.Caps; | ||
42 | |||
43 | namespace OpenSim.Region.ClientStack.Linden | ||
44 | { | ||
45 | [Extension(Path = "/OpenSim/RegionModules", NodeName = "RegionModule", Id = "EstateAcessCapModule")] | ||
46 | public class EstateAccessCapModule : INonSharedRegionModule | ||
47 | { | ||
48 | // private static readonly ILog m_log = | ||
49 | // LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); | ||
50 | |||
51 | private Scene m_scene; | ||
52 | private bool m_Enabled = false; | ||
53 | private string m_capUrl; | ||
54 | IEstateModule m_EstateModule; | ||
55 | |||
56 | #region INonSharedRegionModule Members | ||
57 | |||
58 | public void Initialise(IConfigSource pSource) | ||
59 | { | ||
60 | IConfig config = pSource.Configs["ClientStack.LindenCaps"]; | ||
61 | if (config == null) | ||
62 | return; | ||
63 | |||
64 | m_capUrl = config.GetString("Cap_EstateAccess", string.Empty); | ||
65 | if (!String.IsNullOrEmpty(m_capUrl) && m_capUrl.Equals("localhost")) | ||
66 | m_Enabled = true; | ||
67 | } | ||
68 | |||
69 | public void AddRegion(Scene scene) | ||
70 | { | ||
71 | if (!m_Enabled) | ||
72 | return; | ||
73 | |||
74 | m_scene = scene; | ||
75 | } | ||
76 | |||
77 | public void RemoveRegion(Scene scene) | ||
78 | { | ||
79 | if (!m_Enabled) | ||
80 | return; | ||
81 | |||
82 | if (m_scene == scene) | ||
83 | { | ||
84 | m_scene.EventManager.OnRegisterCaps -= RegisterCaps; | ||
85 | m_scene = null; | ||
86 | } | ||
87 | } | ||
88 | |||
89 | public void RegionLoaded(Scene scene) | ||
90 | { | ||
91 | if (!m_Enabled) | ||
92 | return; | ||
93 | |||
94 | if (scene.RegionInfo == null || scene.RegionInfo.EstateSettings == null) | ||
95 | { | ||
96 | m_Enabled = false; | ||
97 | return; | ||
98 | } | ||
99 | |||
100 | IEstateModule m_EstateModule = scene.RequestModuleInterface<IEstateModule>(); | ||
101 | if(m_EstateModule == null) | ||
102 | { | ||
103 | m_Enabled = false; | ||
104 | return; | ||
105 | } | ||
106 | |||
107 | scene.EventManager.OnRegisterCaps += RegisterCaps; | ||
108 | } | ||
109 | |||
110 | public void Close() | ||
111 | { | ||
112 | } | ||
113 | |||
114 | public string Name | ||
115 | { | ||
116 | get { return "EstateAccessCapModule"; } | ||
117 | } | ||
118 | |||
119 | public Type ReplaceableInterface | ||
120 | { | ||
121 | get { return null; } | ||
122 | } | ||
123 | |||
124 | #endregion | ||
125 | |||
126 | public void RegisterCaps(UUID agentID, Caps caps) | ||
127 | { | ||
128 | string capUrl = "/CAPS/" + UUID.Random() + "/"; | ||
129 | |||
130 | caps.RegisterHandler( | ||
131 | "EstateAccess", | ||
132 | new RestHTTPHandler( | ||
133 | "GET", | ||
134 | capUrl, | ||
135 | httpMethod => ProcessRequest(httpMethod, agentID, caps), | ||
136 | "EstateAccess", | ||
137 | agentID.ToString())); ; | ||
138 | } | ||
139 | |||
140 | public Hashtable ProcessRequest(Hashtable request, UUID AgentId, Caps cap) | ||
141 | { | ||
142 | Hashtable responsedata = new Hashtable(); | ||
143 | responsedata["int_response_code"] = 400; //501; //410; //404; | ||
144 | responsedata["content_type"] = "text/plain"; | ||
145 | responsedata["keepalive"] = false; | ||
146 | responsedata["str_response_string"] = "Request wasn't what was expected"; | ||
147 | ScenePresence avatar; | ||
148 | |||
149 | if (!m_scene.TryGetScenePresence(AgentId, out avatar)) | ||
150 | return responsedata; | ||
151 | |||
152 | responsedata["int_response_code"] = 200; //501; //410; //404; | ||
153 | responsedata["content_type"] = "text/plain"; | ||
154 | responsedata["keepalive"] = true; | ||
155 | |||
156 | if (m_scene.RegionInfo == null | ||
157 | || m_scene.RegionInfo.EstateSettings == null | ||
158 | ||!m_scene.Permissions.CanIssueEstateCommand(AgentId, false)) | ||
159 | { | ||
160 | responsedata["str_response_string"] = "<llsd><array /></llsd>"; ; | ||
161 | return responsedata; | ||
162 | } | ||
163 | |||
164 | EstateSettings regionSettings = m_scene.RegionInfo.EstateSettings; | ||
165 | UUID[] managers = regionSettings.EstateManagers; | ||
166 | UUID[] allowed = regionSettings.EstateAccess; | ||
167 | UUID[] groups = regionSettings.EstateGroups; | ||
168 | EstateBan[] EstateBans = regionSettings.EstateBans; | ||
169 | |||
170 | StringBuilder sb = LLSDxmlEncode.Start(); | ||
171 | LLSDxmlEncode.AddArray(sb); | ||
172 | |||
173 | if (allowed != null && allowed.Length > 0) | ||
174 | { | ||
175 | LLSDxmlEncode.AddMap("AllowedAgents", sb); | ||
176 | for (int i = 0; i < allowed.Length; ++i) | ||
177 | { | ||
178 | UUID id = allowed[i]; | ||
179 | if (id == UUID.Zero) | ||
180 | continue; | ||
181 | LLSDxmlEncode.AddElem("id", id, sb); | ||
182 | } | ||
183 | LLSDxmlEncode.AddEndMap(sb); | ||
184 | } | ||
185 | |||
186 | if (groups != null && groups.Length > 0) | ||
187 | { | ||
188 | LLSDxmlEncode.AddMap("AllowedGroups", sb); | ||
189 | for (int i = 0; i < groups.Length; ++i) | ||
190 | { | ||
191 | UUID id = groups[i]; | ||
192 | if (id == UUID.Zero) | ||
193 | continue; | ||
194 | LLSDxmlEncode.AddElem("id", id, sb); | ||
195 | } | ||
196 | LLSDxmlEncode.AddEndMap(sb); | ||
197 | } | ||
198 | |||
199 | if (EstateBans != null && EstateBans.Length > 0) | ||
200 | { | ||
201 | LLSDxmlEncode.AddMap("BannedAgents", sb); | ||
202 | for (int i = 0; i < EstateBans.Length; ++i) | ||
203 | { | ||
204 | UUID id = EstateBans[i].BannedUserID; | ||
205 | if (id == UUID.Zero) | ||
206 | continue; | ||
207 | LLSDxmlEncode.AddElem("id", id, sb); | ||
208 | } | ||
209 | LLSDxmlEncode.AddEndMap(sb); | ||
210 | } | ||
211 | |||
212 | if (managers != null && managers.Length > 0) | ||
213 | { | ||
214 | LLSDxmlEncode.AddMap("Managers", sb); | ||
215 | for (int i = 0; i < managers.Length; ++i) | ||
216 | LLSDxmlEncode.AddElem("id", managers[i], sb); | ||
217 | LLSDxmlEncode.AddEndMap(sb); | ||
218 | } | ||
219 | |||
220 | LLSDxmlEncode.AddEndArray(sb); | ||
221 | responsedata["str_response_string"] = LLSDxmlEncode.End(sb); | ||
222 | |||
223 | return responsedata; | ||
224 | } | ||
225 | } | ||
226 | } | ||