clockwerk-opensim – Blame information for rev 1
?pathlinks?
Rev | Author | Line No. | Line |
---|---|---|---|
1 | vero | 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 Nini.Config; |
||
29 | using log4net; |
||
30 | using System; |
||
31 | using System.Reflection; |
||
32 | using System.IO; |
||
33 | using System.Net; |
||
34 | using System.Text; |
||
35 | using System.Text.RegularExpressions; |
||
36 | using System.Xml; |
||
37 | using System.Xml.Serialization; |
||
38 | using System.Collections.Generic; |
||
39 | using OpenSim.Server.Base; |
||
40 | using OpenSim.Services.Interfaces; |
||
41 | using OpenSim.Framework; |
||
42 | using OpenSim.Framework.ServiceAuth; |
||
43 | using OpenSim.Framework.Servers.HttpServer; |
||
44 | using OpenMetaverse; |
||
45 | |||
46 | namespace OpenSim.Server.Handlers.GridUser |
||
47 | { |
||
48 | public class GridUserServerPostHandler : BaseStreamHandler |
||
49 | { |
||
50 | private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); |
||
51 | |||
52 | private IGridUserService m_GridUserService; |
||
53 | |||
54 | public GridUserServerPostHandler(IGridUserService service, IServiceAuth auth) : |
||
55 | base("POST", "/griduser", auth) |
||
56 | { |
||
57 | m_GridUserService = service; |
||
58 | } |
||
59 | |||
60 | protected override byte[] ProcessRequest(string path, Stream requestData, |
||
61 | IOSHttpRequest httpRequest, IOSHttpResponse httpResponse) |
||
62 | { |
||
63 | StreamReader sr = new StreamReader(requestData); |
||
64 | string body = sr.ReadToEnd(); |
||
65 | sr.Close(); |
||
66 | body = body.Trim(); |
||
67 | |||
68 | //m_log.DebugFormat("[XXX]: query String: {0}", body); |
||
69 | string method = string.Empty; |
||
70 | try |
||
71 | { |
||
72 | Dictionary<string, object> request = |
||
73 | ServerUtils.ParseQueryString(body); |
||
74 | |||
75 | if (!request.ContainsKey("METHOD")) |
||
76 | return FailureResult(); |
||
77 | |||
78 | method = request["METHOD"].ToString(); |
||
79 | |||
80 | switch (method) |
||
81 | { |
||
82 | case "loggedin": |
||
83 | return LoggedIn(request); |
||
84 | case "loggedout": |
||
85 | return LoggedOut(request); |
||
86 | case "sethome": |
||
87 | return SetHome(request); |
||
88 | case "setposition": |
||
89 | return SetPosition(request); |
||
90 | case "getgriduserinfo": |
||
91 | return GetGridUserInfo(request); |
||
92 | case "getgriduserinfos": |
||
93 | return GetGridUserInfos(request); |
||
94 | } |
||
95 | m_log.DebugFormat("[GRID USER HANDLER]: unknown method request: {0}", method); |
||
96 | } |
||
97 | catch (Exception e) |
||
98 | { |
||
99 | m_log.DebugFormat("[GRID USER HANDLER]: Exception in method {0}: {1}", method, e); |
||
100 | } |
||
101 | |||
102 | return FailureResult(); |
||
103 | |||
104 | } |
||
105 | |||
106 | byte[] LoggedIn(Dictionary<string, object> request) |
||
107 | { |
||
108 | string user = String.Empty; |
||
109 | |||
110 | if (!request.ContainsKey("UserID")) |
||
111 | return FailureResult(); |
||
112 | |||
113 | user = request["UserID"].ToString(); |
||
114 | |||
115 | GridUserInfo guinfo = m_GridUserService.LoggedIn(user); |
||
116 | |||
117 | Dictionary<string, object> result = new Dictionary<string, object>(); |
||
118 | result["result"] = guinfo.ToKeyValuePairs(); |
||
119 | |||
120 | string xmlString = ServerUtils.BuildXmlResponse(result); |
||
121 | |||
122 | //m_log.DebugFormat("[GRID USER HANDLER]: resp string: {0}", xmlString); |
||
123 | return Util.UTF8NoBomEncoding.GetBytes(xmlString); |
||
124 | } |
||
125 | |||
126 | byte[] LoggedOut(Dictionary<string, object> request) |
||
127 | { |
||
128 | string userID = string.Empty; |
||
129 | UUID regionID = UUID.Zero; |
||
130 | Vector3 position = Vector3.Zero; |
||
131 | Vector3 lookat = Vector3.Zero; |
||
132 | |||
133 | if (!UnpackArgs(request, out userID, out regionID, out position, out lookat)) |
||
134 | return FailureResult(); |
||
135 | |||
136 | if (m_GridUserService.LoggedOut(userID, UUID.Zero, regionID, position, lookat)) |
||
137 | return SuccessResult(); |
||
138 | |||
139 | return FailureResult(); |
||
140 | } |
||
141 | |||
142 | byte[] SetHome(Dictionary<string, object> request) |
||
143 | { |
||
144 | string user = string.Empty; |
||
145 | UUID region = UUID.Zero; |
||
146 | Vector3 position = new Vector3(128, 128, 70); |
||
147 | Vector3 look = Vector3.Zero; |
||
148 | |||
149 | if (!UnpackArgs(request, out user, out region, out position, out look)) |
||
150 | return FailureResult(); |
||
151 | |||
152 | if (m_GridUserService.SetHome(user, region, position, look)) |
||
153 | return SuccessResult(); |
||
154 | |||
155 | return FailureResult(); |
||
156 | } |
||
157 | |||
158 | byte[] SetPosition(Dictionary<string, object> request) |
||
159 | { |
||
160 | string user = string.Empty; |
||
161 | UUID region = UUID.Zero; |
||
162 | Vector3 position = new Vector3(128, 128, 70); |
||
163 | Vector3 look = Vector3.Zero; |
||
164 | |||
165 | if (!request.ContainsKey("UserID") || !request.ContainsKey("RegionID")) |
||
166 | return FailureResult(); |
||
167 | |||
168 | if (!UnpackArgs(request, out user, out region, out position, out look)) |
||
169 | return FailureResult(); |
||
170 | |||
171 | if (m_GridUserService.SetLastPosition(user, UUID.Zero, region, position, look)) |
||
172 | return SuccessResult(); |
||
173 | |||
174 | return FailureResult(); |
||
175 | } |
||
176 | |||
177 | byte[] GetGridUserInfo(Dictionary<string, object> request) |
||
178 | { |
||
179 | string user = String.Empty; |
||
180 | |||
181 | if (!request.ContainsKey("UserID")) |
||
182 | return FailureResult(); |
||
183 | |||
184 | user = request["UserID"].ToString(); |
||
185 | |||
186 | GridUserInfo guinfo = m_GridUserService.GetGridUserInfo(user); |
||
187 | |||
188 | Dictionary<string, object> result = new Dictionary<string, object>(); |
||
189 | if (guinfo != null) |
||
190 | result["result"] = guinfo.ToKeyValuePairs(); |
||
191 | else |
||
192 | result["result"] = "null"; |
||
193 | |||
194 | string xmlString = ServerUtils.BuildXmlResponse(result); |
||
195 | //m_log.DebugFormat("[GRID USER HANDLER]: resp string: {0}", xmlString); |
||
196 | return Util.UTF8NoBomEncoding.GetBytes(xmlString); |
||
197 | } |
||
198 | |||
199 | byte[] GetGridUserInfos(Dictionary<string, object> request) |
||
200 | { |
||
201 | |||
202 | string[] userIDs; |
||
203 | |||
204 | if (!request.ContainsKey("AgentIDs")) |
||
205 | { |
||
206 | m_log.DebugFormat("[GRID USER HANDLER]: GetGridUserInfos called without required uuids argument"); |
||
207 | return FailureResult(); |
||
208 | } |
||
209 | |||
210 | if (!(request["AgentIDs"] is List<string>)) |
||
211 | { |
||
212 | m_log.DebugFormat("[GRID USER HANDLER]: GetGridUserInfos input argument was of unexpected type {0}", request["uuids"].GetType().ToString()); |
||
213 | return FailureResult(); |
||
214 | } |
||
215 | |||
216 | userIDs = ((List<string>)request["AgentIDs"]).ToArray(); |
||
217 | |||
218 | GridUserInfo[] pinfos = m_GridUserService.GetGridUserInfo(userIDs); |
||
219 | |||
220 | Dictionary<string, object> result = new Dictionary<string, object>(); |
||
221 | if ((pinfos == null) || ((pinfos != null) && (pinfos.Length == 0))) |
||
222 | result["result"] = "null"; |
||
223 | else |
||
224 | { |
||
225 | int i = 0; |
||
226 | foreach (GridUserInfo pinfo in pinfos) |
||
227 | { |
||
228 | Dictionary<string, object> rinfoDict = pinfo.ToKeyValuePairs(); |
||
229 | result["griduser" + i] = rinfoDict; |
||
230 | i++; |
||
231 | } |
||
232 | } |
||
233 | |||
234 | string xmlString = ServerUtils.BuildXmlResponse(result); |
||
235 | return Util.UTF8NoBomEncoding.GetBytes(xmlString); |
||
236 | } |
||
237 | |||
238 | private bool UnpackArgs(Dictionary<string, object> request, out string user, out UUID region, out Vector3 position, out Vector3 lookAt) |
||
239 | { |
||
240 | user = string.Empty; |
||
241 | region = UUID.Zero; |
||
242 | position = new Vector3(128, 128, 70); |
||
243 | lookAt = Vector3.Zero; |
||
244 | |||
245 | if (!request.ContainsKey("UserID") || !request.ContainsKey("RegionID")) |
||
246 | return false; |
||
247 | |||
248 | user = request["UserID"].ToString(); |
||
249 | |||
250 | if (!UUID.TryParse(request["RegionID"].ToString(), out region)) |
||
251 | return false; |
||
252 | |||
253 | if (request.ContainsKey("Position")) |
||
254 | Vector3.TryParse(request["Position"].ToString(), out position); |
||
255 | |||
256 | if (request.ContainsKey("LookAt")) |
||
257 | Vector3.TryParse(request["LookAt"].ToString(), out lookAt); |
||
258 | |||
259 | return true; |
||
260 | } |
||
261 | |||
262 | |||
263 | private byte[] SuccessResult() |
||
264 | { |
||
265 | XmlDocument doc = new XmlDocument(); |
||
266 | |||
267 | XmlNode xmlnode = doc.CreateNode(XmlNodeType.XmlDeclaration, |
||
268 | "", ""); |
||
269 | |||
270 | doc.AppendChild(xmlnode); |
||
271 | |||
272 | XmlElement rootElement = doc.CreateElement("", "ServerResponse", |
||
273 | ""); |
||
274 | |||
275 | doc.AppendChild(rootElement); |
||
276 | |||
277 | XmlElement result = doc.CreateElement("", "result", ""); |
||
278 | result.AppendChild(doc.CreateTextNode("Success")); |
||
279 | |||
280 | rootElement.AppendChild(result); |
||
281 | |||
282 | return Util.DocToBytes(doc); |
||
283 | } |
||
284 | |||
285 | private byte[] FailureResult() |
||
286 | { |
||
287 | XmlDocument doc = new XmlDocument(); |
||
288 | |||
289 | XmlNode xmlnode = doc.CreateNode(XmlNodeType.XmlDeclaration, |
||
290 | "", ""); |
||
291 | |||
292 | doc.AppendChild(xmlnode); |
||
293 | |||
294 | XmlElement rootElement = doc.CreateElement("", "ServerResponse", |
||
295 | ""); |
||
296 | |||
297 | doc.AppendChild(rootElement); |
||
298 | |||
299 | XmlElement result = doc.CreateElement("", "result", ""); |
||
300 | result.AppendChild(doc.CreateTextNode("Failure")); |
||
301 | |||
302 | rootElement.AppendChild(result); |
||
303 | |||
304 | return Util.DocToBytes(doc); |
||
305 | } |
||
306 | |||
307 | } |
||
308 | } |