aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Server/Handlers/GridUser
diff options
context:
space:
mode:
authorDiva Canto2010-05-07 21:32:02 -0700
committerDiva Canto2010-05-07 21:32:02 -0700
commit15562017f220e2474b548f860ce1174541d7e22f (patch)
tree8290f1402454ae9c5653eaa9c49e2791fc8deee9 /OpenSim/Server/Handlers/GridUser
parentGridUserService in place. Replaces the contrived concept of storing user's ho... (diff)
downloadopensim-SC-15562017f220e2474b548f860ce1174541d7e22f.zip
opensim-SC-15562017f220e2474b548f860ce1174541d7e22f.tar.gz
opensim-SC-15562017f220e2474b548f860ce1174541d7e22f.tar.bz2
opensim-SC-15562017f220e2474b548f860ce1174541d7e22f.tar.xz
These files are part of the GridUserService write-up.
Diffstat (limited to 'OpenSim/Server/Handlers/GridUser')
-rw-r--r--OpenSim/Server/Handlers/GridUser/GridUserServerConnector.cs61
-rw-r--r--OpenSim/Server/Handlers/GridUser/GridUserServerPostHandler.cs278
2 files changed, 339 insertions, 0 deletions
diff --git a/OpenSim/Server/Handlers/GridUser/GridUserServerConnector.cs b/OpenSim/Server/Handlers/GridUser/GridUserServerConnector.cs
new file mode 100644
index 0000000..66f35e3
--- /dev/null
+++ b/OpenSim/Server/Handlers/GridUser/GridUserServerConnector.cs
@@ -0,0 +1,61 @@
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
28using System;
29using Nini.Config;
30using OpenSim.Server.Base;
31using OpenSim.Services.Interfaces;
32using OpenSim.Framework.Servers.HttpServer;
33using OpenSim.Server.Handlers.Base;
34
35namespace OpenSim.Server.Handlers.GridUser
36{
37 public class GridUserServiceConnector : ServiceConnector
38 {
39 private IGridUserService m_GridUserService;
40 private string m_ConfigName = "GridUserService";
41
42 public GridUserServiceConnector(IConfigSource config, IHttpServer server, string configName) :
43 base(config, server, configName)
44 {
45 IConfig serverConfig = config.Configs[m_ConfigName];
46 if (serverConfig == null)
47 throw new Exception(String.Format("No section {0} in config file", m_ConfigName));
48
49 string service = serverConfig.GetString("LocalServiceModule",
50 String.Empty);
51
52 if (service == String.Empty)
53 throw new Exception("No LocalServiceModule in config file");
54
55 Object[] args = new Object[] { config };
56 m_GridUserService = ServerUtils.LoadPlugin<IGridUserService>(service, args);
57
58 server.AddStreamHandler(new GridUserServerPostHandler(m_GridUserService));
59 }
60 }
61}
diff --git a/OpenSim/Server/Handlers/GridUser/GridUserServerPostHandler.cs b/OpenSim/Server/Handlers/GridUser/GridUserServerPostHandler.cs
new file mode 100644
index 0000000..f8fa429
--- /dev/null
+++ b/OpenSim/Server/Handlers/GridUser/GridUserServerPostHandler.cs
@@ -0,0 +1,278 @@
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
28using Nini.Config;
29using log4net;
30using System;
31using System.Reflection;
32using System.IO;
33using System.Net;
34using System.Text;
35using System.Text.RegularExpressions;
36using System.Xml;
37using System.Xml.Serialization;
38using System.Collections.Generic;
39using OpenSim.Server.Base;
40using OpenSim.Services.Interfaces;
41using OpenSim.Framework;
42using OpenSim.Framework.Servers.HttpServer;
43using OpenMetaverse;
44
45namespace OpenSim.Server.Handlers.GridUser
46{
47 public class GridUserServerPostHandler : BaseStreamHandler
48 {
49 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
50
51 private IGridUserService m_GridUserService;
52
53 public GridUserServerPostHandler(IGridUserService service) :
54 base("POST", "/griduser")
55 {
56 m_GridUserService = service;
57 }
58
59 public override byte[] Handle(string path, Stream requestData,
60 OSHttpRequest httpRequest, OSHttpResponse httpResponse)
61 {
62 StreamReader sr = new StreamReader(requestData);
63 string body = sr.ReadToEnd();
64 sr.Close();
65 body = body.Trim();
66
67 //m_log.DebugFormat("[XXX]: query String: {0}", body);
68 string method = string.Empty;
69 try
70 {
71 Dictionary<string, object> request =
72 ServerUtils.ParseQueryString(body);
73
74 if (!request.ContainsKey("METHOD"))
75 return FailureResult();
76
77 method = request["METHOD"].ToString();
78
79 switch (method)
80 {
81 case "loggedin":
82 return LoggedIn(request);
83 case "loggedout":
84 return LoggedOut(request);
85 case "sethome":
86 return SetHome(request);
87 case "setposition":
88 return SetPosition(request);
89 case "getgriduserinfo":
90 return GetGridUserInfo(request);
91 }
92 m_log.DebugFormat("[GRID USER HANDLER]: unknown method request: {0}", method);
93 }
94 catch (Exception e)
95 {
96 m_log.DebugFormat("[GRID USER HANDLER]: Exception in method {0}: {1}", method, e);
97 }
98
99 return FailureResult();
100
101 }
102
103 byte[] LoggedIn(Dictionary<string, object> request)
104 {
105 string user = String.Empty;
106
107 if (!request.ContainsKey("UserID"))
108 return FailureResult();
109
110 user = request["UserID"].ToString();
111
112 GridUserInfo guinfo = m_GridUserService.LoggedIn(user);
113
114 Dictionary<string, object> result = new Dictionary<string, object>();
115 result["result"] = guinfo.ToKeyValuePairs();
116
117 string xmlString = ServerUtils.BuildXmlResponse(result);
118 //m_log.DebugFormat("[GRID USER HANDLER]: resp string: {0}", xmlString);
119 UTF8Encoding encoding = new UTF8Encoding();
120 return encoding.GetBytes(xmlString);
121
122 }
123
124 byte[] LoggedOut(Dictionary<string, object> request)
125 {
126 string userID = string.Empty;
127 UUID regionID = UUID.Zero;
128 Vector3 position = Vector3.Zero;
129 Vector3 lookat = Vector3.Zero;
130
131 if (!UnpackArgs(request, out userID, out regionID, out position, out lookat))
132 return FailureResult();
133
134 if (m_GridUserService.LoggedOut(userID, regionID, position, lookat))
135 return SuccessResult();
136
137 return FailureResult();
138 }
139
140 byte[] SetHome(Dictionary<string, object> request)
141 {
142 string user = string.Empty;
143 UUID region = UUID.Zero;
144 Vector3 position = new Vector3(128, 128, 70);
145 Vector3 look = Vector3.Zero;
146
147 if (!UnpackArgs(request, out user, out region, out position, out look))
148 return FailureResult();
149
150 if (m_GridUserService.SetHome(user, region, position, look))
151 return SuccessResult();
152
153 return FailureResult();
154 }
155
156 byte[] SetPosition(Dictionary<string, object> request)
157 {
158 string user = string.Empty;
159 UUID region = UUID.Zero;
160 Vector3 position = new Vector3(128, 128, 70);
161 Vector3 look = Vector3.Zero;
162
163 if (!request.ContainsKey("UserID") || !request.ContainsKey("RegionID"))
164 return FailureResult();
165
166 if (!UnpackArgs(request, out user, out region, out position, out look))
167 return FailureResult();
168
169 if (m_GridUserService.SetLastPosition(user, region, position, look))
170 return SuccessResult();
171
172 return FailureResult();
173 }
174
175 byte[] GetGridUserInfo(Dictionary<string, object> request)
176 {
177 string user = String.Empty;
178
179 if (!request.ContainsKey("UserID"))
180 return FailureResult();
181
182 user = request["UserID"].ToString();
183
184 GridUserInfo guinfo = m_GridUserService.GetGridUserInfo(user);
185
186 Dictionary<string, object> result = new Dictionary<string, object>();
187 result["result"] = guinfo.ToKeyValuePairs();
188
189 string xmlString = ServerUtils.BuildXmlResponse(result);
190 //m_log.DebugFormat("[GRID USER HANDLER]: resp string: {0}", xmlString);
191 UTF8Encoding encoding = new UTF8Encoding();
192 return encoding.GetBytes(xmlString);
193
194 }
195
196 private bool UnpackArgs(Dictionary<string, object> request, out string user, out UUID region, out Vector3 position, out Vector3 lookAt)
197 {
198 user = string.Empty;
199 region = UUID.Zero;
200 position = new Vector3(128, 128, 70);
201 lookAt = Vector3.Zero;
202
203 if (!request.ContainsKey("UserID") || !request.ContainsKey("RegionID"))
204 return false;
205
206 user = request["UserID"].ToString();
207
208 if (!UUID.TryParse(request["RegionID"].ToString(), out region))
209 return false;
210
211 if (request.ContainsKey("Position"))
212 Vector3.TryParse(request["Position"].ToString(), out position);
213
214 if (request.ContainsKey("LookAt"))
215 Vector3.TryParse(request["LookAt"].ToString(), out lookAt);
216
217 return true;
218 }
219
220
221 private byte[] SuccessResult()
222 {
223 XmlDocument doc = new XmlDocument();
224
225 XmlNode xmlnode = doc.CreateNode(XmlNodeType.XmlDeclaration,
226 "", "");
227
228 doc.AppendChild(xmlnode);
229
230 XmlElement rootElement = doc.CreateElement("", "ServerResponse",
231 "");
232
233 doc.AppendChild(rootElement);
234
235 XmlElement result = doc.CreateElement("", "result", "");
236 result.AppendChild(doc.CreateTextNode("Success"));
237
238 rootElement.AppendChild(result);
239
240 return DocToBytes(doc);
241 }
242
243 private byte[] FailureResult()
244 {
245 XmlDocument doc = new XmlDocument();
246
247 XmlNode xmlnode = doc.CreateNode(XmlNodeType.XmlDeclaration,
248 "", "");
249
250 doc.AppendChild(xmlnode);
251
252 XmlElement rootElement = doc.CreateElement("", "ServerResponse",
253 "");
254
255 doc.AppendChild(rootElement);
256
257 XmlElement result = doc.CreateElement("", "result", "");
258 result.AppendChild(doc.CreateTextNode("Failure"));
259
260 rootElement.AppendChild(result);
261
262 return DocToBytes(doc);
263 }
264
265 private byte[] DocToBytes(XmlDocument doc)
266 {
267 MemoryStream ms = new MemoryStream();
268 XmlTextWriter xw = new XmlTextWriter(ms, null);
269 xw.Formatting = Formatting.Indented;
270 doc.WriteTo(xw);
271 xw.Flush();
272
273 return ms.ToArray();
274 }
275
276
277 }
278}