31 using System.Reflection;
35 using System.Text.RegularExpressions;
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;
46 namespace OpenSim.Server.Handlers.GridUser
50 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
55 base(
"POST",
"/griduser", auth)
57 m_GridUserService = service;
63 StreamReader sr =
new StreamReader(requestData);
64 string body = sr.ReadToEnd();
69 string method = string.Empty;
72 Dictionary<string, object> request =
73 ServerUtils.ParseQueryString(body);
75 if (!request.ContainsKey(
"METHOD"))
76 return FailureResult();
78 method = request[
"METHOD"].ToString();
83 return LoggedIn(request);
85 return LoggedOut(request);
87 return SetHome(request);
89 return SetPosition(request);
90 case "getgriduserinfo":
91 return GetGridUserInfo(request);
92 case "getgriduserinfos":
93 return GetGridUserInfos(request);
95 m_log.DebugFormat(
"[GRID USER HANDLER]: unknown method request: {0}", method);
99 m_log.DebugFormat(
"[GRID USER HANDLER]: Exception in method {0}: {1}", method, e);
102 return FailureResult();
106 byte[] LoggedIn(Dictionary<string, object> request)
108 string user = String.Empty;
110 if (!request.ContainsKey(
"UserID"))
111 return FailureResult();
113 user = request[
"UserID"].ToString();
117 Dictionary<string, object> result =
new Dictionary<string, object>();
118 result[
"result"] = guinfo.ToKeyValuePairs();
120 string xmlString = ServerUtils.BuildXmlResponse(result);
123 return Util.UTF8NoBomEncoding.GetBytes(xmlString);
126 byte[] LoggedOut(Dictionary<string, object> request)
128 string userID = string.Empty;
129 UUID regionID = UUID.Zero;
130 Vector3 position = Vector3.Zero;
131 Vector3 lookat = Vector3.Zero;
133 if (!UnpackArgs(request, out userID, out regionID, out position, out lookat))
134 return FailureResult();
136 if (m_GridUserService.LoggedOut(userID, UUID.Zero, regionID, position, lookat))
137 return SuccessResult();
139 return FailureResult();
142 byte[] SetHome(Dictionary<string, object> request)
144 string user = string.Empty;
145 UUID region = UUID.Zero;
146 Vector3 position =
new Vector3(128, 128, 70);
147 Vector3 look = Vector3.Zero;
149 if (!UnpackArgs(request, out user, out region, out position, out look))
150 return FailureResult();
152 if (m_GridUserService.SetHome(user, region, position, look))
153 return SuccessResult();
155 return FailureResult();
158 byte[] SetPosition(Dictionary<string, object> request)
160 string user = string.Empty;
161 UUID region = UUID.Zero;
162 Vector3 position =
new Vector3(128, 128, 70);
163 Vector3 look = Vector3.Zero;
165 if (!request.ContainsKey(
"UserID") || !request.ContainsKey(
"RegionID"))
166 return FailureResult();
168 if (!UnpackArgs(request, out user, out region, out position, out look))
169 return FailureResult();
171 if (m_GridUserService.SetLastPosition(user, UUID.Zero, region, position, look))
172 return SuccessResult();
174 return FailureResult();
177 byte[] GetGridUserInfo(Dictionary<string, object> request)
179 string user = String.Empty;
181 if (!request.ContainsKey(
"UserID"))
182 return FailureResult();
184 user = request[
"UserID"].ToString();
186 GridUserInfo guinfo = m_GridUserService.GetGridUserInfo(user);
189 return FailureResult();
191 Dictionary<string, object> result =
new Dictionary<string, object>();
193 result[
"result"] = guinfo.ToKeyValuePairs();
195 result[
"result"] =
"null";
197 string xmlString = ServerUtils.BuildXmlResponse(result);
199 return Util.UTF8NoBomEncoding.GetBytes(xmlString);
202 byte[] GetGridUserInfos(Dictionary<string, object> request)
207 if (!request.ContainsKey(
"AgentIDs"))
209 m_log.DebugFormat(
"[GRID USER HANDLER]: GetGridUserInfos called without required uuids argument");
210 return FailureResult();
213 if (!(request[
"AgentIDs"] is List<string>))
215 m_log.DebugFormat(
"[GRID USER HANDLER]: GetGridUserInfos input argument was of unexpected type {0}", request[
"uuids"].GetType().ToString());
216 return FailureResult();
219 userIDs = ((List<string>)request[
"AgentIDs"]).ToArray();
221 GridUserInfo[] pinfos = m_GridUserService.GetGridUserInfo(userIDs);
223 Dictionary<string, object> result =
new Dictionary<string, object>();
224 if ((pinfos == null) || ((pinfos != null) && (pinfos.Length == 0)))
225 result[
"result"] =
"null";
231 Dictionary<string, object> rinfoDict = pinfo.ToKeyValuePairs();
232 result[
"griduser" + i] = rinfoDict;
237 string xmlString = ServerUtils.BuildXmlResponse(result);
238 return Util.UTF8NoBomEncoding.GetBytes(xmlString);
241 private bool UnpackArgs(Dictionary<string, object> request, out
string user, out UUID region, out Vector3 position, out Vector3 lookAt)
245 position =
new Vector3(128, 128, 70);
246 lookAt = Vector3.Zero;
248 if (!request.ContainsKey(
"UserID") || !request.ContainsKey(
"RegionID"))
251 user = request[
"UserID"].ToString();
253 if (!
UUID.TryParse(request[
"RegionID"].ToString(), out region))
256 if (request.ContainsKey(
"Position"))
257 Vector3.TryParse(request[
"Position"].ToString(), out position);
259 if (request.ContainsKey(
"LookAt"))
260 Vector3.TryParse(request[
"LookAt"].ToString(), out lookAt);
266 private byte[] SuccessResult()
268 XmlDocument doc =
new XmlDocument();
270 XmlNode xmlnode = doc.CreateNode(XmlNodeType.XmlDeclaration,
273 doc.AppendChild(xmlnode);
275 XmlElement rootElement = doc.CreateElement(
"",
"ServerResponse",
278 doc.AppendChild(rootElement);
280 XmlElement result = doc.CreateElement(
"",
"result",
"");
281 result.AppendChild(doc.CreateTextNode(
"Success"));
283 rootElement.AppendChild(result);
285 return Util.DocToBytes(doc);
288 private byte[] FailureResult()
290 XmlDocument doc =
new XmlDocument();
292 XmlNode xmlnode = doc.CreateNode(XmlNodeType.XmlDeclaration,
295 doc.AppendChild(xmlnode);
297 XmlElement rootElement = doc.CreateElement(
"",
"ServerResponse",
300 doc.AppendChild(rootElement);
302 XmlElement result = doc.CreateElement(
"",
"result",
"");
303 result.AppendChild(doc.CreateTextNode(
"Failure"));
305 rootElement.AppendChild(result);
307 return Util.DocToBytes(doc);
Base streamed request handler.
override byte[] ProcessRequest(string path, Stream requestData, IOSHttpRequest httpRequest, IOSHttpResponse httpResponse)
Records user information specific to a grid but which is not part of a user's account.
GridUserServerPostHandler(IGridUserService service, IServiceAuth auth)