diff options
Diffstat (limited to 'OpenSim/Region/CoreModules/World/Estate/EstateRequestHandler.cs')
-rw-r--r-- | OpenSim/Region/CoreModules/World/Estate/EstateRequestHandler.cs | 300 |
1 files changed, 300 insertions, 0 deletions
diff --git a/OpenSim/Region/CoreModules/World/Estate/EstateRequestHandler.cs b/OpenSim/Region/CoreModules/World/Estate/EstateRequestHandler.cs new file mode 100644 index 0000000..5eda8ab --- /dev/null +++ b/OpenSim/Region/CoreModules/World/Estate/EstateRequestHandler.cs | |||
@@ -0,0 +1,300 @@ | |||
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.Generic; | ||
30 | using System.IO; | ||
31 | using System.Reflection; | ||
32 | using System.Xml; | ||
33 | |||
34 | using OpenSim.Framework; | ||
35 | using OpenSim.Server.Base; | ||
36 | using OpenSim.Framework.Servers.HttpServer; | ||
37 | using OpenSim.Region.Framework.Scenes; | ||
38 | using OpenSim.Region.Framework.Interfaces; | ||
39 | |||
40 | using OpenMetaverse; | ||
41 | using log4net; | ||
42 | |||
43 | namespace OpenSim.Region.CoreModules.World.Estate | ||
44 | { | ||
45 | public class EstateRequestHandler : BaseStreamHandler | ||
46 | { | ||
47 | private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); | ||
48 | |||
49 | protected EstateModule m_EstateModule; | ||
50 | protected Object m_RequestLock = new Object(); | ||
51 | private string token; | ||
52 | |||
53 | public EstateRequestHandler(EstateModule fmodule, string _token) | ||
54 | : base("POST", "/estate") | ||
55 | { | ||
56 | m_EstateModule = fmodule; | ||
57 | token = _token; | ||
58 | } | ||
59 | |||
60 | protected override byte[] ProcessRequest(string path, Stream requestData, | ||
61 | IOSHttpRequest httpRequest, IOSHttpResponse httpResponse) | ||
62 | { | ||
63 | string body; | ||
64 | using(StreamReader sr = new StreamReader(requestData)) | ||
65 | body = sr.ReadToEnd(); | ||
66 | |||
67 | body = body.Trim(); | ||
68 | |||
69 | // m_log.DebugFormat("[XESTATE HANDLER]: query String: {0}", body); | ||
70 | |||
71 | try | ||
72 | { | ||
73 | lock (m_RequestLock) | ||
74 | { | ||
75 | Dictionary<string, object> request = | ||
76 | ServerUtils.ParseQueryString(body); | ||
77 | |||
78 | if (!request.ContainsKey("METHOD")) | ||
79 | return FailureResult(); | ||
80 | |||
81 | if (!request.ContainsKey("TOKEN")) | ||
82 | return FailureResult(); | ||
83 | |||
84 | string reqToken = request["TOKEN"].ToString(); | ||
85 | request.Remove("TOKEN"); | ||
86 | |||
87 | if(token != reqToken) | ||
88 | return FailureResult(); | ||
89 | |||
90 | string method = request["METHOD"].ToString(); | ||
91 | request.Remove("METHOD"); | ||
92 | |||
93 | try | ||
94 | { | ||
95 | m_EstateModule.InInfoUpdate = false; | ||
96 | |||
97 | switch (method) | ||
98 | { | ||
99 | case "update_covenant": | ||
100 | return UpdateCovenant(request); | ||
101 | case "update_estate": | ||
102 | return UpdateEstate(request); | ||
103 | case "estate_message": | ||
104 | return EstateMessage(request); | ||
105 | case "teleport_home_one_user": | ||
106 | return TeleportHomeOneUser(request); | ||
107 | case "teleport_home_all_users": | ||
108 | return TeleportHomeAllUsers(request); | ||
109 | } | ||
110 | } | ||
111 | finally | ||
112 | { | ||
113 | m_EstateModule.InInfoUpdate = false; | ||
114 | } | ||
115 | } | ||
116 | } | ||
117 | catch (Exception e) | ||
118 | { | ||
119 | m_log.Debug("[XESTATE]: Exception {0}" + e.ToString()); | ||
120 | } | ||
121 | |||
122 | return FailureResult(); | ||
123 | } | ||
124 | |||
125 | byte[] TeleportHomeAllUsers(Dictionary<string, object> request) | ||
126 | { | ||
127 | UUID PreyID = UUID.Zero; | ||
128 | int EstateID = 0; | ||
129 | |||
130 | if (!request.ContainsKey("EstateID")) | ||
131 | return FailureResult(); | ||
132 | |||
133 | if (!Int32.TryParse(request["EstateID"].ToString(), out EstateID)) | ||
134 | return FailureResult(); | ||
135 | |||
136 | foreach (Scene s in m_EstateModule.Scenes) | ||
137 | { | ||
138 | if (s.RegionInfo.EstateSettings.EstateID == EstateID) | ||
139 | { | ||
140 | s.ForEachScenePresence(delegate(ScenePresence p) { | ||
141 | if (p != null && !p.IsChildAgent) | ||
142 | { | ||
143 | p.ControllingClient.SendTeleportStart(16); | ||
144 | s.TeleportClientHome(p.ControllingClient.AgentId, p.ControllingClient); | ||
145 | } | ||
146 | }); | ||
147 | } | ||
148 | } | ||
149 | |||
150 | return SuccessResult(); | ||
151 | } | ||
152 | |||
153 | byte[] TeleportHomeOneUser(Dictionary<string, object> request) | ||
154 | { | ||
155 | UUID PreyID = UUID.Zero; | ||
156 | int EstateID = 0; | ||
157 | |||
158 | if (!request.ContainsKey("PreyID") || | ||
159 | !request.ContainsKey("EstateID")) | ||
160 | { | ||
161 | return FailureResult(); | ||
162 | } | ||
163 | |||
164 | if (!UUID.TryParse(request["PreyID"].ToString(), out PreyID)) | ||
165 | return FailureResult(); | ||
166 | |||
167 | if (!Int32.TryParse(request["EstateID"].ToString(), out EstateID)) | ||
168 | return FailureResult(); | ||
169 | |||
170 | foreach (Scene s in m_EstateModule.Scenes) | ||
171 | { | ||
172 | if (s.RegionInfo.EstateSettings.EstateID == EstateID) | ||
173 | { | ||
174 | ScenePresence p = s.GetScenePresence(PreyID); | ||
175 | if (p != null && !p.IsChildAgent) | ||
176 | { | ||
177 | p.ControllingClient.SendTeleportStart(16); | ||
178 | s.TeleportClientHome(PreyID, p.ControllingClient); | ||
179 | } | ||
180 | } | ||
181 | } | ||
182 | |||
183 | return SuccessResult(); | ||
184 | } | ||
185 | |||
186 | byte[] EstateMessage(Dictionary<string, object> request) | ||
187 | { | ||
188 | UUID FromID = UUID.Zero; | ||
189 | string FromName = String.Empty; | ||
190 | string Message = String.Empty; | ||
191 | int EstateID = 0; | ||
192 | |||
193 | if (!request.ContainsKey("FromID") || | ||
194 | !request.ContainsKey("FromName") || | ||
195 | !request.ContainsKey("Message") || | ||
196 | !request.ContainsKey("EstateID")) | ||
197 | { | ||
198 | return FailureResult(); | ||
199 | } | ||
200 | |||
201 | if (!UUID.TryParse(request["FromID"].ToString(), out FromID)) | ||
202 | return FailureResult(); | ||
203 | |||
204 | if (!Int32.TryParse(request["EstateID"].ToString(), out EstateID)) | ||
205 | return FailureResult(); | ||
206 | |||
207 | FromName = request["FromName"].ToString(); | ||
208 | Message = request["Message"].ToString(); | ||
209 | |||
210 | foreach (Scene s in m_EstateModule.Scenes) | ||
211 | { | ||
212 | if (s.RegionInfo.EstateSettings.EstateID == EstateID) | ||
213 | { | ||
214 | IDialogModule dm = s.RequestModuleInterface<IDialogModule>(); | ||
215 | |||
216 | if (dm != null) | ||
217 | { | ||
218 | dm.SendNotificationToUsersInRegion(FromID, FromName, | ||
219 | Message); | ||
220 | } | ||
221 | } | ||
222 | } | ||
223 | |||
224 | return SuccessResult(); | ||
225 | } | ||
226 | |||
227 | byte[] UpdateCovenant(Dictionary<string, object> request) | ||
228 | { | ||
229 | UUID CovenantID = UUID.Zero; | ||
230 | int EstateID = 0; | ||
231 | |||
232 | if (!request.ContainsKey("CovenantID") || !request.ContainsKey("EstateID")) | ||
233 | return FailureResult(); | ||
234 | |||
235 | if (!UUID.TryParse(request["CovenantID"].ToString(), out CovenantID)) | ||
236 | return FailureResult(); | ||
237 | |||
238 | if (!Int32.TryParse(request["EstateID"].ToString(), out EstateID)) | ||
239 | return FailureResult(); | ||
240 | |||
241 | foreach (Scene s in m_EstateModule.Scenes) | ||
242 | { | ||
243 | if (s.RegionInfo.EstateSettings.EstateID == (uint)EstateID) | ||
244 | s.RegionInfo.RegionSettings.Covenant = CovenantID; | ||
245 | } | ||
246 | |||
247 | return SuccessResult(); | ||
248 | } | ||
249 | |||
250 | byte[] UpdateEstate(Dictionary<string, object> request) | ||
251 | { | ||
252 | int EstateID = 0; | ||
253 | |||
254 | if (!request.ContainsKey("EstateID")) | ||
255 | return FailureResult(); | ||
256 | if (!Int32.TryParse(request["EstateID"].ToString(), out EstateID)) | ||
257 | return FailureResult(); | ||
258 | |||
259 | foreach (Scene s in m_EstateModule.Scenes) | ||
260 | { | ||
261 | if (s.RegionInfo.EstateSettings.EstateID == (uint)EstateID) | ||
262 | s.ReloadEstateData(); | ||
263 | } | ||
264 | return SuccessResult(); | ||
265 | } | ||
266 | |||
267 | private byte[] FailureResult() | ||
268 | { | ||
269 | return BoolResult(false); | ||
270 | } | ||
271 | |||
272 | private byte[] SuccessResult() | ||
273 | { | ||
274 | return BoolResult(true); | ||
275 | } | ||
276 | |||
277 | private byte[] BoolResult(bool value) | ||
278 | { | ||
279 | XmlDocument doc = new XmlDocument(); | ||
280 | |||
281 | XmlNode xmlnode = doc.CreateNode(XmlNodeType.XmlDeclaration, | ||
282 | "", ""); | ||
283 | |||
284 | doc.AppendChild(xmlnode); | ||
285 | |||
286 | XmlElement rootElement = doc.CreateElement("", "ServerResponse", | ||
287 | ""); | ||
288 | |||
289 | doc.AppendChild(rootElement); | ||
290 | |||
291 | XmlElement result = doc.CreateElement("", "RESULT", ""); | ||
292 | result.AppendChild(doc.CreateTextNode(value.ToString())); | ||
293 | |||
294 | rootElement.AppendChild(result); | ||
295 | |||
296 | return Util.DocToBytes(doc); | ||
297 | } | ||
298 | |||
299 | } | ||
300 | } | ||