diff options
author | Melanie | 2010-05-08 13:31:36 +0100 |
---|---|---|
committer | Melanie | 2010-05-08 13:31:36 +0100 |
commit | 14fcc2510ef9f1effc06d7e99b57f7f74de08eac (patch) | |
tree | e52f145ef2aac9a9cc7fb32a6a40e62f67991743 /OpenSim/Server/Handlers | |
parent | Merge branch 'master' into careminster-presence-refactor (diff) | |
parent | test commit for panda (diff) | |
download | opensim-SC-14fcc2510ef9f1effc06d7e99b57f7f74de08eac.zip opensim-SC-14fcc2510ef9f1effc06d7e99b57f7f74de08eac.tar.gz opensim-SC-14fcc2510ef9f1effc06d7e99b57f7f74de08eac.tar.bz2 opensim-SC-14fcc2510ef9f1effc06d7e99b57f7f74de08eac.tar.xz |
Merge branch 'master' into careminster-presence-refactor
Diffstat (limited to 'OpenSim/Server/Handlers')
3 files changed, 341 insertions, 43 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 | |||
28 | using System; | ||
29 | using Nini.Config; | ||
30 | using OpenSim.Server.Base; | ||
31 | using OpenSim.Services.Interfaces; | ||
32 | using OpenSim.Framework.Servers.HttpServer; | ||
33 | using OpenSim.Server.Handlers.Base; | ||
34 | |||
35 | namespace 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 | |||
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.Servers.HttpServer; | ||
43 | using OpenMetaverse; | ||
44 | |||
45 | namespace 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 | } | ||
diff --git a/OpenSim/Server/Handlers/Presence/PresenceServerPostHandler.cs b/OpenSim/Server/Handlers/Presence/PresenceServerPostHandler.cs index 4ebf933..3104917 100644 --- a/OpenSim/Server/Handlers/Presence/PresenceServerPostHandler.cs +++ b/OpenSim/Server/Handlers/Presence/PresenceServerPostHandler.cs | |||
@@ -90,8 +90,6 @@ namespace OpenSim.Server.Handlers.Presence | |||
90 | return GetAgent(request); | 90 | return GetAgent(request); |
91 | case "getagents": | 91 | case "getagents": |
92 | return GetAgents(request); | 92 | return GetAgents(request); |
93 | case "sethome": | ||
94 | return SetHome(request); | ||
95 | } | 93 | } |
96 | m_log.DebugFormat("[PRESENCE HANDLER]: unknown method request: {0}", method); | 94 | m_log.DebugFormat("[PRESENCE HANDLER]: unknown method request: {0}", method); |
97 | } | 95 | } |
@@ -140,12 +138,7 @@ namespace OpenSim.Server.Handlers.Presence | |||
140 | if (!UUID.TryParse(request["SessionID"].ToString(), out session)) | 138 | if (!UUID.TryParse(request["SessionID"].ToString(), out session)) |
141 | return FailureResult(); | 139 | return FailureResult(); |
142 | 140 | ||
143 | if (request.ContainsKey("Position") && request["Position"] != null) | 141 | if (m_PresenceService.LogoutAgent(session)) |
144 | Vector3.TryParse(request["Position"].ToString(), out position); | ||
145 | if (request.ContainsKey("LookAt") && request["Position"] != null) | ||
146 | Vector3.TryParse(request["LookAt"].ToString(), out lookat); | ||
147 | |||
148 | if (m_PresenceService.LogoutAgent(session, position, lookat)) | ||
149 | return SuccessResult(); | 142 | return SuccessResult(); |
150 | 143 | ||
151 | return FailureResult(); | 144 | return FailureResult(); |
@@ -171,8 +164,6 @@ namespace OpenSim.Server.Handlers.Presence | |||
171 | { | 164 | { |
172 | UUID session = UUID.Zero; | 165 | UUID session = UUID.Zero; |
173 | UUID region = UUID.Zero; | 166 | UUID region = UUID.Zero; |
174 | Vector3 position = new Vector3(128, 128, 70); | ||
175 | Vector3 look = Vector3.Zero; | ||
176 | 167 | ||
177 | if (!request.ContainsKey("SessionID") || !request.ContainsKey("RegionID")) | 168 | if (!request.ContainsKey("SessionID") || !request.ContainsKey("RegionID")) |
178 | return FailureResult(); | 169 | return FailureResult(); |
@@ -183,13 +174,7 @@ namespace OpenSim.Server.Handlers.Presence | |||
183 | if (!UUID.TryParse(request["RegionID"].ToString(), out region)) | 174 | if (!UUID.TryParse(request["RegionID"].ToString(), out region)) |
184 | return FailureResult(); | 175 | return FailureResult(); |
185 | 176 | ||
186 | if (request.ContainsKey("position")) | 177 | if (m_PresenceService.ReportAgent(session, region)) |
187 | Vector3.TryParse(request["position"].ToString(), out position); | ||
188 | |||
189 | if (request.ContainsKey("lookAt")) | ||
190 | Vector3.TryParse(request["lookAt"].ToString(), out look); | ||
191 | |||
192 | if (m_PresenceService.ReportAgent(session, region, position, look)) | ||
193 | { | 178 | { |
194 | return SuccessResult(); | 179 | return SuccessResult(); |
195 | } | 180 | } |
@@ -318,31 +303,5 @@ namespace OpenSim.Server.Handlers.Presence | |||
318 | return ms.ToArray(); | 303 | return ms.ToArray(); |
319 | } | 304 | } |
320 | 305 | ||
321 | byte[] SetHome(Dictionary<string, object> request) | ||
322 | { | ||
323 | UUID region = UUID.Zero; | ||
324 | Vector3 position = new Vector3(128, 128, 70); | ||
325 | Vector3 look = Vector3.Zero; | ||
326 | |||
327 | if (!request.ContainsKey("UserID") || !request.ContainsKey("RegionID")) | ||
328 | return FailureResult(); | ||
329 | |||
330 | string user = request["UserID"].ToString(); | ||
331 | |||
332 | if (!UUID.TryParse(request["RegionID"].ToString(), out region)) | ||
333 | return FailureResult(); | ||
334 | |||
335 | if (request.ContainsKey("position")) | ||
336 | Vector3.TryParse(request["position"].ToString(), out position); | ||
337 | |||
338 | if (request.ContainsKey("lookAt")) | ||
339 | Vector3.TryParse(request["lookAt"].ToString(), out look); | ||
340 | |||
341 | if (m_PresenceService.SetHomeLocation(user, region, position, look)) | ||
342 | return SuccessResult(); | ||
343 | |||
344 | return FailureResult(); | ||
345 | } | ||
346 | |||
347 | } | 306 | } |
348 | } | 307 | } |