diff options
Diffstat (limited to 'OpenSim/Server/Handlers/Presence/PresenceServerPostHandler.cs')
-rw-r--r-- | OpenSim/Server/Handlers/Presence/PresenceServerPostHandler.cs | 208 |
1 files changed, 187 insertions, 21 deletions
diff --git a/OpenSim/Server/Handlers/Presence/PresenceServerPostHandler.cs b/OpenSim/Server/Handlers/Presence/PresenceServerPostHandler.cs index b5ae54a..4ebf933 100644 --- a/OpenSim/Server/Handlers/Presence/PresenceServerPostHandler.cs +++ b/OpenSim/Server/Handlers/Presence/PresenceServerPostHandler.cs | |||
@@ -65,7 +65,7 @@ namespace OpenSim.Server.Handlers.Presence | |||
65 | body = body.Trim(); | 65 | body = body.Trim(); |
66 | 66 | ||
67 | //m_log.DebugFormat("[XXX]: query String: {0}", body); | 67 | //m_log.DebugFormat("[XXX]: query String: {0}", body); |
68 | 68 | string method = string.Empty; | |
69 | try | 69 | try |
70 | { | 70 | { |
71 | Dictionary<string, object> request = | 71 | Dictionary<string, object> request = |
@@ -74,56 +74,195 @@ namespace OpenSim.Server.Handlers.Presence | |||
74 | if (!request.ContainsKey("METHOD")) | 74 | if (!request.ContainsKey("METHOD")) |
75 | return FailureResult(); | 75 | return FailureResult(); |
76 | 76 | ||
77 | string method = request["METHOD"].ToString(); | 77 | method = request["METHOD"].ToString(); |
78 | 78 | ||
79 | switch (method) | 79 | switch (method) |
80 | { | 80 | { |
81 | case "login": | ||
82 | return LoginAgent(request); | ||
83 | case "logout": | ||
84 | return LogoutAgent(request); | ||
85 | case "logoutregion": | ||
86 | return LogoutRegionAgents(request); | ||
81 | case "report": | 87 | case "report": |
82 | return Report(request); | 88 | return Report(request); |
89 | case "getagent": | ||
90 | return GetAgent(request); | ||
91 | case "getagents": | ||
92 | return GetAgents(request); | ||
93 | case "sethome": | ||
94 | return SetHome(request); | ||
83 | } | 95 | } |
84 | m_log.DebugFormat("[PRESENCE HANDLER]: unknown method request: {0}", method); | 96 | m_log.DebugFormat("[PRESENCE HANDLER]: unknown method request: {0}", method); |
85 | } | 97 | } |
86 | catch (Exception e) | 98 | catch (Exception e) |
87 | { | 99 | { |
88 | m_log.Debug("[PRESENCE HANDLER]: Exception {0}" + e); | 100 | m_log.DebugFormat("[PRESENCE HANDLER]: Exception in method {0}: {1}", method, e); |
89 | } | 101 | } |
90 | 102 | ||
91 | return FailureResult(); | 103 | return FailureResult(); |
92 | 104 | ||
93 | } | 105 | } |
94 | 106 | ||
107 | byte[] LoginAgent(Dictionary<string, object> request) | ||
108 | { | ||
109 | string user = String.Empty; | ||
110 | UUID session = UUID.Zero; | ||
111 | UUID ssession = UUID.Zero; | ||
112 | |||
113 | if (!request.ContainsKey("UserID") || !request.ContainsKey("SessionID")) | ||
114 | return FailureResult(); | ||
115 | |||
116 | user = request["UserID"].ToString(); | ||
117 | |||
118 | if (!UUID.TryParse(request["SessionID"].ToString(), out session)) | ||
119 | return FailureResult(); | ||
120 | |||
121 | if (request.ContainsKey("SecureSessionID")) | ||
122 | // If it's malformed, we go on with a Zero on it | ||
123 | UUID.TryParse(request["SecureSessionID"].ToString(), out ssession); | ||
124 | |||
125 | if (m_PresenceService.LoginAgent(user, session, ssession)) | ||
126 | return SuccessResult(); | ||
127 | |||
128 | return FailureResult(); | ||
129 | } | ||
130 | |||
131 | byte[] LogoutAgent(Dictionary<string, object> request) | ||
132 | { | ||
133 | UUID session = UUID.Zero; | ||
134 | Vector3 position = Vector3.Zero; | ||
135 | Vector3 lookat = Vector3.Zero; | ||
136 | |||
137 | if (!request.ContainsKey("SessionID")) | ||
138 | return FailureResult(); | ||
139 | |||
140 | if (!UUID.TryParse(request["SessionID"].ToString(), out session)) | ||
141 | return FailureResult(); | ||
142 | |||
143 | if (request.ContainsKey("Position") && request["Position"] != null) | ||
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(); | ||
150 | |||
151 | return FailureResult(); | ||
152 | } | ||
153 | |||
154 | byte[] LogoutRegionAgents(Dictionary<string, object> request) | ||
155 | { | ||
156 | UUID region = UUID.Zero; | ||
157 | |||
158 | if (!request.ContainsKey("RegionID")) | ||
159 | return FailureResult(); | ||
160 | |||
161 | if (!UUID.TryParse(request["RegionID"].ToString(), out region)) | ||
162 | return FailureResult(); | ||
163 | |||
164 | if (m_PresenceService.LogoutRegionAgents(region)) | ||
165 | return SuccessResult(); | ||
166 | |||
167 | return FailureResult(); | ||
168 | } | ||
169 | |||
95 | byte[] Report(Dictionary<string, object> request) | 170 | byte[] Report(Dictionary<string, object> request) |
96 | { | 171 | { |
97 | PresenceInfo info = new PresenceInfo(); | 172 | UUID session = UUID.Zero; |
98 | info.Data = new Dictionary<string, string>(); | 173 | UUID region = UUID.Zero; |
174 | Vector3 position = new Vector3(128, 128, 70); | ||
175 | Vector3 look = Vector3.Zero; | ||
99 | 176 | ||
100 | if (!request.ContainsKey("PrincipalID") || !request.ContainsKey("RegionID")) | 177 | if (!request.ContainsKey("SessionID") || !request.ContainsKey("RegionID")) |
101 | return FailureResult(); | 178 | return FailureResult(); |
102 | 179 | ||
103 | if (!UUID.TryParse(request["PrincipalID"].ToString(), | 180 | if (!UUID.TryParse(request["SessionID"].ToString(), out session)) |
104 | out info.PrincipalID)) | ||
105 | return FailureResult(); | 181 | return FailureResult(); |
106 | 182 | ||
107 | if (!UUID.TryParse(request["RegionID"].ToString(), | 183 | if (!UUID.TryParse(request["RegionID"].ToString(), out region)) |
108 | out info.RegionID)) | ||
109 | return FailureResult(); | 184 | return FailureResult(); |
110 | 185 | ||
111 | foreach (KeyValuePair<string, object> kvp in request) | 186 | if (request.ContainsKey("position")) |
112 | { | 187 | Vector3.TryParse(request["position"].ToString(), out position); |
113 | if (kvp.Key == "METHOD" || | ||
114 | kvp.Key == "PrincipalID" || | ||
115 | kvp.Key == "RegionID") | ||
116 | continue; | ||
117 | 188 | ||
118 | info.Data[kvp.Key] = kvp.Value.ToString(); | 189 | if (request.ContainsKey("lookAt")) |
119 | } | 190 | Vector3.TryParse(request["lookAt"].ToString(), out look); |
120 | 191 | ||
121 | if (m_PresenceService.Report(info)) | 192 | if (m_PresenceService.ReportAgent(session, region, position, look)) |
193 | { | ||
122 | return SuccessResult(); | 194 | return SuccessResult(); |
195 | } | ||
123 | 196 | ||
124 | return FailureResult(); | 197 | return FailureResult(); |
125 | } | 198 | } |
126 | 199 | ||
200 | byte[] GetAgent(Dictionary<string, object> request) | ||
201 | { | ||
202 | UUID session = UUID.Zero; | ||
203 | |||
204 | if (!request.ContainsKey("SessionID")) | ||
205 | return FailureResult(); | ||
206 | |||
207 | if (!UUID.TryParse(request["SessionID"].ToString(), out session)) | ||
208 | return FailureResult(); | ||
209 | |||
210 | PresenceInfo pinfo = m_PresenceService.GetAgent(session); | ||
211 | |||
212 | Dictionary<string, object> result = new Dictionary<string, object>(); | ||
213 | if (pinfo == null) | ||
214 | result["result"] = "null"; | ||
215 | else | ||
216 | result["result"] = pinfo.ToKeyValuePairs(); | ||
217 | |||
218 | string xmlString = ServerUtils.BuildXmlResponse(result); | ||
219 | //m_log.DebugFormat("[GRID HANDLER]: resp string: {0}", xmlString); | ||
220 | UTF8Encoding encoding = new UTF8Encoding(); | ||
221 | return encoding.GetBytes(xmlString); | ||
222 | } | ||
223 | |||
224 | byte[] GetAgents(Dictionary<string, object> request) | ||
225 | { | ||
226 | |||
227 | string[] userIDs; | ||
228 | |||
229 | if (!request.ContainsKey("uuids")) | ||
230 | { | ||
231 | m_log.DebugFormat("[PRESENCE HANDLER]: GetAgents called without required uuids argument"); | ||
232 | return FailureResult(); | ||
233 | } | ||
234 | |||
235 | if (!(request["uuids"] is List<string>)) | ||
236 | { | ||
237 | m_log.DebugFormat("[PRESENCE HANDLER]: GetAgents input argument was of unexpected type {0}", request["uuids"].GetType().ToString()); | ||
238 | return FailureResult(); | ||
239 | } | ||
240 | |||
241 | userIDs = ((List<string>)request["uuids"]).ToArray(); | ||
242 | |||
243 | PresenceInfo[] pinfos = m_PresenceService.GetAgents(userIDs); | ||
244 | |||
245 | Dictionary<string, object> result = new Dictionary<string, object>(); | ||
246 | if ((pinfos == null) || ((pinfos != null) && (pinfos.Length == 0))) | ||
247 | result["result"] = "null"; | ||
248 | else | ||
249 | { | ||
250 | int i = 0; | ||
251 | foreach (PresenceInfo pinfo in pinfos) | ||
252 | { | ||
253 | Dictionary<string, object> rinfoDict = pinfo.ToKeyValuePairs(); | ||
254 | result["presence" + i] = rinfoDict; | ||
255 | i++; | ||
256 | } | ||
257 | } | ||
258 | |||
259 | string xmlString = ServerUtils.BuildXmlResponse(result); | ||
260 | //m_log.DebugFormat("[GRID HANDLER]: resp string: {0}", xmlString); | ||
261 | UTF8Encoding encoding = new UTF8Encoding(); | ||
262 | return encoding.GetBytes(xmlString); | ||
263 | } | ||
264 | |||
265 | |||
127 | private byte[] SuccessResult() | 266 | private byte[] SuccessResult() |
128 | { | 267 | { |
129 | XmlDocument doc = new XmlDocument(); | 268 | XmlDocument doc = new XmlDocument(); |
@@ -138,7 +277,7 @@ namespace OpenSim.Server.Handlers.Presence | |||
138 | 277 | ||
139 | doc.AppendChild(rootElement); | 278 | doc.AppendChild(rootElement); |
140 | 279 | ||
141 | XmlElement result = doc.CreateElement("", "Result", ""); | 280 | XmlElement result = doc.CreateElement("", "result", ""); |
142 | result.AppendChild(doc.CreateTextNode("Success")); | 281 | result.AppendChild(doc.CreateTextNode("Success")); |
143 | 282 | ||
144 | rootElement.AppendChild(result); | 283 | rootElement.AppendChild(result); |
@@ -160,7 +299,7 @@ namespace OpenSim.Server.Handlers.Presence | |||
160 | 299 | ||
161 | doc.AppendChild(rootElement); | 300 | doc.AppendChild(rootElement); |
162 | 301 | ||
163 | XmlElement result = doc.CreateElement("", "Result", ""); | 302 | XmlElement result = doc.CreateElement("", "result", ""); |
164 | result.AppendChild(doc.CreateTextNode("Failure")); | 303 | result.AppendChild(doc.CreateTextNode("Failure")); |
165 | 304 | ||
166 | rootElement.AppendChild(result); | 305 | rootElement.AppendChild(result); |
@@ -178,5 +317,32 @@ namespace OpenSim.Server.Handlers.Presence | |||
178 | 317 | ||
179 | return ms.ToArray(); | 318 | return ms.ToArray(); |
180 | } | 319 | } |
320 | |||
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 | |||
181 | } | 347 | } |
182 | } | 348 | } |