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