diff options
Diffstat (limited to 'OpenSim/Server/Handlers/Simulation')
-rw-r--r-- | OpenSim/Server/Handlers/Simulation/AgentHandlers.cs | 369 |
1 files changed, 255 insertions, 114 deletions
diff --git a/OpenSim/Server/Handlers/Simulation/AgentHandlers.cs b/OpenSim/Server/Handlers/Simulation/AgentHandlers.cs index 012b14e..98c5312 100644 --- a/OpenSim/Server/Handlers/Simulation/AgentHandlers.cs +++ b/OpenSim/Server/Handlers/Simulation/AgentHandlers.cs | |||
@@ -27,11 +27,14 @@ | |||
27 | 27 | ||
28 | using System; | 28 | using System; |
29 | using System.Collections; | 29 | using System.Collections; |
30 | using System.Collections.Generic; | ||
31 | using System.Collections.Specialized; | ||
30 | using System.IO; | 32 | using System.IO; |
31 | using System.IO.Compression; | 33 | using System.IO.Compression; |
32 | using System.Reflection; | 34 | using System.Reflection; |
33 | using System.Net; | 35 | using System.Net; |
34 | using System.Text; | 36 | using System.Text; |
37 | using System.Web; | ||
35 | 38 | ||
36 | using OpenSim.Server.Base; | 39 | using OpenSim.Server.Base; |
37 | using OpenSim.Server.Handlers.Base; | 40 | using OpenSim.Server.Handlers.Base; |
@@ -90,14 +93,13 @@ namespace OpenSim.Server.Handlers.Simulation | |||
90 | 93 | ||
91 | // Next, let's parse the verb | 94 | // Next, let's parse the verb |
92 | string method = (string)request["http-method"]; | 95 | string method = (string)request["http-method"]; |
93 | if (method.Equals("GET")) | 96 | if (method.Equals("DELETE")) |
94 | { | 97 | { |
95 | DoAgentGet(request, responsedata, agentID, regionID); | 98 | string auth_token = string.Empty; |
96 | return responsedata; | 99 | if (request.ContainsKey("auth")) |
97 | } | 100 | auth_token = request["auth"].ToString(); |
98 | else if (method.Equals("DELETE")) | 101 | |
99 | { | 102 | DoAgentDelete(request, responsedata, agentID, action, regionID, auth_token); |
100 | DoAgentDelete(request, responsedata, agentID, action, regionID); | ||
101 | return responsedata; | 103 | return responsedata; |
102 | } | 104 | } |
103 | else if (method.Equals("QUERYACCESS")) | 105 | else if (method.Equals("QUERYACCESS")) |
@@ -107,7 +109,7 @@ namespace OpenSim.Server.Handlers.Simulation | |||
107 | } | 109 | } |
108 | else | 110 | else |
109 | { | 111 | { |
110 | m_log.InfoFormat("[AGENT HANDLER]: method {0} not supported in agent message", method); | 112 | m_log.ErrorFormat("[AGENT HANDLER]: method {0} not supported in agent message {1} (caller is {2})", method, (string)request["uri"], Util.GetCallerIP(request)); |
111 | responsedata["int_response_code"] = HttpStatusCode.MethodNotAllowed; | 113 | responsedata["int_response_code"] = HttpStatusCode.MethodNotAllowed; |
112 | responsedata["str_response_string"] = "Method not allowed"; | 114 | responsedata["str_response_string"] = "Method not allowed"; |
113 | 115 | ||
@@ -116,7 +118,7 @@ namespace OpenSim.Server.Handlers.Simulation | |||
116 | 118 | ||
117 | } | 119 | } |
118 | 120 | ||
119 | protected virtual void DoQueryAccess(Hashtable request, Hashtable responsedata, UUID id, UUID regionID) | 121 | protected virtual void DoQueryAccess(Hashtable request, Hashtable responsedata, UUID agentID, UUID regionID) |
120 | { | 122 | { |
121 | if (m_SimulationService == null) | 123 | if (m_SimulationService == null) |
122 | { | 124 | { |
@@ -131,86 +133,155 @@ namespace OpenSim.Server.Handlers.Simulation | |||
131 | // m_log.DebugFormat("[AGENT HANDLER]: Received QUERYACCESS with {0}", (string)request["body"]); | 133 | // m_log.DebugFormat("[AGENT HANDLER]: Received QUERYACCESS with {0}", (string)request["body"]); |
132 | OSDMap args = Utils.GetOSDMap((string)request["body"]); | 134 | OSDMap args = Utils.GetOSDMap((string)request["body"]); |
133 | 135 | ||
136 | bool viaTeleport = true; | ||
137 | if (args.ContainsKey("viaTeleport")) | ||
138 | viaTeleport = args["viaTeleport"].AsBoolean(); | ||
139 | |||
134 | Vector3 position = Vector3.Zero; | 140 | Vector3 position = Vector3.Zero; |
135 | if (args.ContainsKey("position")) | 141 | if (args.ContainsKey("position")) |
136 | position = Vector3.Parse(args["position"].AsString()); | 142 | position = Vector3.Parse(args["position"].AsString()); |
137 | 143 | ||
138 | GridRegion destination = new GridRegion(); | 144 | string agentHomeURI = null; |
139 | destination.RegionID = regionID; | 145 | if (args.ContainsKey("agent_home_uri")) |
146 | agentHomeURI = args["agent_home_uri"].AsString(); | ||
140 | 147 | ||
141 | string reason; | 148 | // Decode the legacy (string) version and extract the number |
142 | string version; | 149 | float theirVersion = 0f; |
143 | bool result = m_SimulationService.QueryAccess(destination, id, position, out version, out reason); | 150 | if (args.ContainsKey("my_version")) |
151 | { | ||
152 | string theirVersionStr = args["my_version"].AsString(); | ||
153 | string[] parts = theirVersionStr.Split(new char[] {'/'}); | ||
154 | if (parts.Length > 1) | ||
155 | theirVersion = float.Parse(parts[1]); | ||
156 | } | ||
144 | 157 | ||
145 | responsedata["int_response_code"] = HttpStatusCode.OK; | 158 | // Decode the new versioning data |
159 | float minVersionRequired = 0f; | ||
160 | float maxVersionRequired = 0f; | ||
161 | float minVersionProvided = 0f; | ||
162 | float maxVersionProvided = 0f; | ||
146 | 163 | ||
147 | OSDMap resp = new OSDMap(3); | 164 | if (args.ContainsKey("simulation_service_supported_min")) |
165 | minVersionProvided = (float)args["simulation_service_supported_min"].AsReal(); | ||
166 | if (args.ContainsKey("simulation_service_supported_max")) | ||
167 | maxVersionProvided = (float)args["simulation_service_supported_max"].AsReal(); | ||
148 | 168 | ||
149 | resp["success"] = OSD.FromBoolean(result); | 169 | if (args.ContainsKey("simulation_service_accepted_min")) |
150 | resp["reason"] = OSD.FromString(reason); | 170 | minVersionRequired = (float)args["simulation_service_accepted_min"].AsReal(); |
151 | resp["version"] = OSD.FromString(version); | 171 | if (args.ContainsKey("simulation_service_accepted_max")) |
172 | maxVersionRequired = (float)args["simulation_service_accepted_max"].AsReal(); | ||
152 | 173 | ||
153 | // We must preserve defaults here, otherwise a false "success" will not be put into the JSON map! | 174 | responsedata["int_response_code"] = HttpStatusCode.OK; |
154 | responsedata["str_response_string"] = OSDParser.SerializeJsonString(resp, true); | 175 | OSDMap resp = new OSDMap(3); |
155 | 176 | ||
156 | // Console.WriteLine("str_response_string [{0}]", responsedata["str_response_string"]); | 177 | float version = 0f; |
157 | } | ||
158 | 178 | ||
159 | protected virtual void DoAgentGet(Hashtable request, Hashtable responsedata, UUID id, UUID regionID) | 179 | float outboundVersion = 0f; |
160 | { | 180 | float inboundVersion = 0f; |
161 | if (m_SimulationService == null) | 181 | |
182 | if (minVersionProvided == 0f) // string version or older | ||
162 | { | 183 | { |
163 | m_log.Debug("[AGENT HANDLER]: Agent GET called. Harmless but useless."); | 184 | // If there is no version in the packet at all we're looking at 0.6 or |
164 | responsedata["content_type"] = "application/json"; | 185 | // even more ancient. Refuse it. |
165 | responsedata["int_response_code"] = HttpStatusCode.NotImplemented; | 186 | if(theirVersion == 0f) |
166 | responsedata["str_response_string"] = string.Empty; | 187 | { |
188 | resp["success"] = OSD.FromBoolean(false); | ||
189 | resp["reason"] = OSD.FromString("Your region is running a old version of opensim no longer supported. Consider updating it"); | ||
190 | responsedata["str_response_string"] = OSDParser.SerializeJsonString(resp, true); | ||
191 | return; | ||
192 | } | ||
167 | 193 | ||
168 | return; | 194 | version = theirVersion; |
195 | |||
196 | if (version < VersionInfo.SimulationServiceVersionAcceptedMin || | ||
197 | version > VersionInfo.SimulationServiceVersionAcceptedMax ) | ||
198 | { | ||
199 | resp["success"] = OSD.FromBoolean(false); | ||
200 | resp["reason"] = OSD.FromString(String.Format("Your region protocol version is {0} and we accept only {1} - {2}. No version overlap.", theirVersion, VersionInfo.SimulationServiceVersionAcceptedMin, VersionInfo.SimulationServiceVersionAcceptedMax)); | ||
201 | responsedata["str_response_string"] = OSDParser.SerializeJsonString(resp, true); | ||
202 | return; | ||
203 | } | ||
169 | } | 204 | } |
170 | 205 | else | |
171 | GridRegion destination = new GridRegion(); | ||
172 | destination.RegionID = regionID; | ||
173 | |||
174 | IAgentData agent = null; | ||
175 | bool result = m_SimulationService.RetrieveAgent(destination, id, out agent); | ||
176 | OSDMap map = null; | ||
177 | if (result) | ||
178 | { | 206 | { |
179 | if (agent != null) // just to make sure | 207 | // Test for no overlap |
208 | if (minVersionProvided > VersionInfo.SimulationServiceVersionAcceptedMax || | ||
209 | maxVersionProvided < VersionInfo.SimulationServiceVersionAcceptedMin) | ||
180 | { | 210 | { |
181 | map = agent.Pack(); | 211 | resp["success"] = OSD.FromBoolean(false); |
182 | string strBuffer = ""; | 212 | resp["reason"] = OSD.FromString(String.Format("Your region provide protocol versions {0} - {1} and we accept only {2} - {3}. No version overlap.", minVersionProvided, maxVersionProvided, VersionInfo.SimulationServiceVersionAcceptedMin, VersionInfo.SimulationServiceVersionAcceptedMax)); |
183 | try | 213 | responsedata["str_response_string"] = OSDParser.SerializeJsonString(resp, true); |
184 | { | 214 | return; |
185 | strBuffer = OSDParser.SerializeJsonString(map); | ||
186 | } | ||
187 | catch (Exception e) | ||
188 | { | ||
189 | m_log.WarnFormat("[AGENT HANDLER]: Exception thrown on serialization of DoAgentGet: {0}", e.Message); | ||
190 | responsedata["int_response_code"] = HttpStatusCode.InternalServerError; | ||
191 | // ignore. buffer will be empty, caller should check. | ||
192 | } | ||
193 | |||
194 | responsedata["content_type"] = "application/json"; | ||
195 | responsedata["int_response_code"] = HttpStatusCode.OK; | ||
196 | responsedata["str_response_string"] = strBuffer; | ||
197 | } | 215 | } |
198 | else | 216 | if (minVersionRequired > VersionInfo.SimulationServiceVersionSupportedMax || |
217 | maxVersionRequired < VersionInfo.SimulationServiceVersionSupportedMin) | ||
199 | { | 218 | { |
200 | responsedata["int_response_code"] = HttpStatusCode.InternalServerError; | 219 | resp["success"] = OSD.FromBoolean(false); |
201 | responsedata["str_response_string"] = "Internal error"; | 220 | resp["reason"] = OSD.FromString(String.Format("You require region protocol versions {0} - {1} and we provide only {2} - {3}. No version overlap.", minVersionRequired, maxVersionRequired, VersionInfo.SimulationServiceVersionSupportedMin, VersionInfo.SimulationServiceVersionSupportedMax)); |
221 | responsedata["str_response_string"] = OSDParser.SerializeJsonString(resp, true); | ||
222 | return; | ||
202 | } | 223 | } |
224 | |||
225 | // Determine versions to use | ||
226 | // This is intentionally inverted. Inbound and Outbound refer to the direction of the transfer. | ||
227 | // Therefore outbound means from the sender to the receier and inbound means from the receiver to the sender. | ||
228 | // So outbound is what we will accept and inbound is what we will send. Confused yet? | ||
229 | outboundVersion = Math.Min(maxVersionProvided, VersionInfo.SimulationServiceVersionAcceptedMax); | ||
230 | inboundVersion = Math.Min(maxVersionRequired, VersionInfo.SimulationServiceVersionSupportedMax); | ||
203 | } | 231 | } |
204 | else | 232 | |
233 | List<UUID> features = new List<UUID>(); | ||
234 | |||
235 | if (args.ContainsKey("features")) | ||
236 | { | ||
237 | OSDArray array = (OSDArray)args["features"]; | ||
238 | |||
239 | foreach (OSD o in array) | ||
240 | features.Add(new UUID(o.AsString())); | ||
241 | } | ||
242 | |||
243 | GridRegion destination = new GridRegion(); | ||
244 | destination.RegionID = regionID; | ||
245 | |||
246 | string reason; | ||
247 | // We're sending the version numbers down to the local connector to do the varregion check. | ||
248 | EntityTransferContext ctx = new EntityTransferContext(); | ||
249 | ctx.InboundVersion = inboundVersion; | ||
250 | ctx.OutboundVersion = outboundVersion; | ||
251 | if (minVersionProvided == 0f) | ||
205 | { | 252 | { |
206 | responsedata["int_response_code"] = HttpStatusCode.NotFound; | 253 | ctx.InboundVersion = version; |
207 | responsedata["str_response_string"] = "Not Found"; | 254 | ctx.OutboundVersion = version; |
208 | } | 255 | } |
256 | |||
257 | bool result = m_SimulationService.QueryAccess(destination, agentID, agentHomeURI, viaTeleport, position, features, ctx, out reason); | ||
258 | |||
259 | resp["success"] = OSD.FromBoolean(result); | ||
260 | resp["reason"] = OSD.FromString(reason); | ||
261 | string legacyVersion = String.Format("SIMULATION/{0}", version); | ||
262 | resp["version"] = OSD.FromString(legacyVersion); | ||
263 | resp["negotiated_inbound_version"] = OSD.FromReal(inboundVersion); | ||
264 | resp["negotiated_outbound_version"] = OSD.FromReal(outboundVersion); | ||
265 | resp["variable_wearables_count_supported"] = OSD.FromBoolean(true); | ||
266 | |||
267 | OSDArray featuresWanted = new OSDArray(); | ||
268 | foreach (UUID feature in features) | ||
269 | featuresWanted.Add(OSD.FromString(feature.ToString())); | ||
270 | |||
271 | resp["features"] = featuresWanted; | ||
272 | |||
273 | // We must preserve defaults here, otherwise a false "success" will not be put into the JSON map! | ||
274 | responsedata["str_response_string"] = OSDParser.SerializeJsonString(resp, true); | ||
275 | |||
276 | // Console.WriteLine("str_response_string [{0}]", responsedata["str_response_string"]); | ||
209 | } | 277 | } |
210 | 278 | ||
211 | protected void DoAgentDelete(Hashtable request, Hashtable responsedata, UUID id, string action, UUID regionID) | 279 | protected void DoAgentDelete(Hashtable request, Hashtable responsedata, UUID id, string action, UUID regionID, string auth_token) |
212 | { | 280 | { |
213 | m_log.Debug(" >>> DoDelete action:" + action + "; RegionID:" + regionID); | 281 | if (string.IsNullOrEmpty(action)) |
282 | m_log.DebugFormat("[AGENT HANDLER]: >>> DELETE <<< RegionID: {0}; from: {1}; auth_code: {2}", regionID, Util.GetCallerIP(request), auth_token); | ||
283 | else | ||
284 | m_log.DebugFormat("[AGENT HANDLER]: Release {0} to RegionID: {1}", id, regionID); | ||
214 | 285 | ||
215 | GridRegion destination = new GridRegion(); | 286 | GridRegion destination = new GridRegion(); |
216 | destination.RegionID = regionID; | 287 | destination.RegionID = regionID; |
@@ -218,12 +289,13 @@ namespace OpenSim.Server.Handlers.Simulation | |||
218 | if (action.Equals("release")) | 289 | if (action.Equals("release")) |
219 | ReleaseAgent(regionID, id); | 290 | ReleaseAgent(regionID, id); |
220 | else | 291 | else |
221 | m_SimulationService.CloseAgent(destination, id); | 292 | Util.FireAndForget( |
293 | o => m_SimulationService.CloseAgent(destination, id, auth_token), null, "AgentHandler.DoAgentDelete"); | ||
222 | 294 | ||
223 | responsedata["int_response_code"] = HttpStatusCode.OK; | 295 | responsedata["int_response_code"] = HttpStatusCode.OK; |
224 | responsedata["str_response_string"] = "OpenSim agent " + id.ToString(); | 296 | responsedata["str_response_string"] = "OpenSim agent " + id.ToString(); |
225 | 297 | ||
226 | m_log.DebugFormat("[AGENT HANDLER]: Agent {0} Released/Deleted from region {1}", id, regionID); | 298 | //m_log.DebugFormat("[AGENT HANDLER]: Agent {0} Released/Deleted from region {1}", id, regionID); |
227 | } | 299 | } |
228 | 300 | ||
229 | protected virtual void ReleaseAgent(UUID regionID, UUID id) | 301 | protected virtual void ReleaseAgent(UUID regionID, UUID id) |
@@ -251,7 +323,7 @@ namespace OpenSim.Server.Handlers.Simulation | |||
251 | m_SimulationService = null; | 323 | m_SimulationService = null; |
252 | } | 324 | } |
253 | 325 | ||
254 | public override byte[] Handle(string path, Stream request, | 326 | protected override byte[] ProcessRequest(string path, Stream request, |
255 | IOSHttpRequest httpRequest, IOSHttpResponse httpResponse) | 327 | IOSHttpRequest httpRequest, IOSHttpResponse httpResponse) |
256 | { | 328 | { |
257 | // m_log.DebugFormat("[SIMULATION]: Stream handler called"); | 329 | // m_log.DebugFormat("[SIMULATION]: Stream handler called"); |
@@ -280,21 +352,36 @@ namespace OpenSim.Server.Handlers.Simulation | |||
280 | httpResponse.KeepAlive = false; | 352 | httpResponse.KeepAlive = false; |
281 | Encoding encoding = Encoding.UTF8; | 353 | Encoding encoding = Encoding.UTF8; |
282 | 354 | ||
283 | Stream inputStream = null; | 355 | if (httpRequest.ContentType != "application/json") |
284 | if (httpRequest.ContentType == "application/x-gzip") | ||
285 | inputStream = new GZipStream(request, CompressionMode.Decompress); | ||
286 | else if (httpRequest.ContentType == "application/json") | ||
287 | inputStream = request; | ||
288 | else // no go | ||
289 | { | 356 | { |
290 | httpResponse.StatusCode = 406; | 357 | httpResponse.StatusCode = 406; |
291 | return encoding.GetBytes("false"); | 358 | return encoding.GetBytes("false"); |
292 | } | 359 | } |
293 | 360 | ||
294 | StreamReader reader = new StreamReader(inputStream, encoding); | 361 | string requestBody; |
362 | |||
363 | Stream inputStream = request; | ||
364 | Stream innerStream = null; | ||
365 | try | ||
366 | { | ||
367 | if ((httpRequest.ContentType == "application/x-gzip" || httpRequest.Headers["Content-Encoding"] == "gzip") || (httpRequest.Headers["X-Content-Encoding"] == "gzip")) | ||
368 | { | ||
369 | innerStream = inputStream; | ||
370 | inputStream = new GZipStream(innerStream, CompressionMode.Decompress); | ||
371 | } | ||
372 | |||
373 | using (StreamReader reader = new StreamReader(inputStream, encoding)) | ||
374 | { | ||
375 | requestBody = reader.ReadToEnd(); | ||
376 | } | ||
377 | } | ||
378 | finally | ||
379 | { | ||
380 | if (innerStream != null) | ||
381 | innerStream.Dispose(); | ||
382 | inputStream.Dispose(); | ||
383 | } | ||
295 | 384 | ||
296 | string requestBody = reader.ReadToEnd(); | ||
297 | reader.Close(); | ||
298 | keysvals.Add("body", requestBody); | 385 | keysvals.Add("body", requestBody); |
299 | 386 | ||
300 | Hashtable responsedata = new Hashtable(); | 387 | Hashtable responsedata = new Hashtable(); |
@@ -328,31 +415,16 @@ namespace OpenSim.Server.Handlers.Simulation | |||
328 | return; | 415 | return; |
329 | } | 416 | } |
330 | 417 | ||
331 | // retrieve the input arguments | 418 | AgentDestinationData data = CreateAgentDestinationData(); |
332 | int x = 0, y = 0; | 419 | UnpackData(args, data, request); |
333 | UUID uuid = UUID.Zero; | ||
334 | string regionname = string.Empty; | ||
335 | uint teleportFlags = 0; | ||
336 | if (args.ContainsKey("destination_x") && args["destination_x"] != null) | ||
337 | Int32.TryParse(args["destination_x"].AsString(), out x); | ||
338 | else | ||
339 | m_log.WarnFormat(" -- request didn't have destination_x"); | ||
340 | if (args.ContainsKey("destination_y") && args["destination_y"] != null) | ||
341 | Int32.TryParse(args["destination_y"].AsString(), out y); | ||
342 | else | ||
343 | m_log.WarnFormat(" -- request didn't have destination_y"); | ||
344 | if (args.ContainsKey("destination_uuid") && args["destination_uuid"] != null) | ||
345 | UUID.TryParse(args["destination_uuid"].AsString(), out uuid); | ||
346 | if (args.ContainsKey("destination_name") && args["destination_name"] != null) | ||
347 | regionname = args["destination_name"].ToString(); | ||
348 | if (args.ContainsKey("teleport_flags") && args["teleport_flags"] != null) | ||
349 | teleportFlags = args["teleport_flags"].AsUInteger(); | ||
350 | 420 | ||
351 | GridRegion destination = new GridRegion(); | 421 | GridRegion destination = new GridRegion(); |
352 | destination.RegionID = uuid; | 422 | destination.RegionID = data.uuid; |
353 | destination.RegionLocX = x; | 423 | destination.RegionLocX = data.x; |
354 | destination.RegionLocY = y; | 424 | destination.RegionLocY = data.y; |
355 | destination.RegionName = regionname; | 425 | destination.RegionName = data.name; |
426 | |||
427 | GridRegion gatekeeper = ExtractGatekeeper(data); | ||
356 | 428 | ||
357 | AgentCircuitData aCircuit = new AgentCircuitData(); | 429 | AgentCircuitData aCircuit = new AgentCircuitData(); |
358 | try | 430 | try |
@@ -367,13 +439,29 @@ namespace OpenSim.Server.Handlers.Simulation | |||
367 | return; | 439 | return; |
368 | } | 440 | } |
369 | 441 | ||
442 | GridRegion source = null; | ||
443 | |||
444 | if (args.ContainsKey("source_uuid")) | ||
445 | { | ||
446 | source = new GridRegion(); | ||
447 | source.RegionLocX = Int32.Parse(args["source_x"].AsString()); | ||
448 | source.RegionLocY = Int32.Parse(args["source_y"].AsString()); | ||
449 | source.RegionName = args["source_name"].AsString(); | ||
450 | source.RegionID = UUID.Parse(args["source_uuid"].AsString()); | ||
451 | |||
452 | if (args.ContainsKey("source_server_uri")) | ||
453 | source.RawServerURI = args["source_server_uri"].AsString(); | ||
454 | else | ||
455 | source.RawServerURI = null; | ||
456 | } | ||
457 | |||
370 | OSDMap resp = new OSDMap(2); | 458 | OSDMap resp = new OSDMap(2); |
371 | string reason = String.Empty; | 459 | string reason = String.Empty; |
372 | 460 | ||
373 | // This is the meaning of POST agent | 461 | // This is the meaning of POST agent |
374 | //m_regionClient.AdjustUserInformation(aCircuit); | 462 | //m_regionClient.AdjustUserInformation(aCircuit); |
375 | //bool result = m_SimulationService.CreateAgent(destination, aCircuit, teleportFlags, out reason); | 463 | //bool result = m_SimulationService.CreateAgent(destination, aCircuit, teleportFlags, out reason); |
376 | bool result = CreateAgent(destination, aCircuit, teleportFlags, out reason); | 464 | bool result = CreateAgent(source, gatekeeper, destination, aCircuit, data.flags, data.fromLogin, out reason); |
377 | 465 | ||
378 | resp["reason"] = OSD.FromString(reason); | 466 | resp["reason"] = OSD.FromString(reason); |
379 | resp["success"] = OSD.FromBoolean(result); | 467 | resp["success"] = OSD.FromBoolean(result); |
@@ -385,7 +473,36 @@ namespace OpenSim.Server.Handlers.Simulation | |||
385 | responsedata["str_response_string"] = OSDParser.SerializeJsonString(resp); | 473 | responsedata["str_response_string"] = OSDParser.SerializeJsonString(resp); |
386 | } | 474 | } |
387 | 475 | ||
388 | private string GetCallerIP(Hashtable request) | 476 | protected virtual AgentDestinationData CreateAgentDestinationData() |
477 | { | ||
478 | return new AgentDestinationData(); | ||
479 | } | ||
480 | |||
481 | protected virtual void UnpackData(OSDMap args, AgentDestinationData data, Hashtable request) | ||
482 | { | ||
483 | // retrieve the input arguments | ||
484 | if (args.ContainsKey("destination_x") && args["destination_x"] != null) | ||
485 | Int32.TryParse(args["destination_x"].AsString(), out data.x); | ||
486 | else | ||
487 | m_log.WarnFormat(" -- request didn't have destination_x"); | ||
488 | if (args.ContainsKey("destination_y") && args["destination_y"] != null) | ||
489 | Int32.TryParse(args["destination_y"].AsString(), out data.y); | ||
490 | else | ||
491 | m_log.WarnFormat(" -- request didn't have destination_y"); | ||
492 | if (args.ContainsKey("destination_uuid") && args["destination_uuid"] != null) | ||
493 | UUID.TryParse(args["destination_uuid"].AsString(), out data.uuid); | ||
494 | if (args.ContainsKey("destination_name") && args["destination_name"] != null) | ||
495 | data.name = args["destination_name"].ToString(); | ||
496 | if (args.ContainsKey("teleport_flags") && args["teleport_flags"] != null) | ||
497 | data.flags = args["teleport_flags"].AsUInteger(); | ||
498 | } | ||
499 | |||
500 | protected virtual GridRegion ExtractGatekeeper(AgentDestinationData data) | ||
501 | { | ||
502 | return null; | ||
503 | } | ||
504 | |||
505 | protected string GetCallerIP(Hashtable request) | ||
389 | { | 506 | { |
390 | if (!m_Proxy) | 507 | if (!m_Proxy) |
391 | return Util.GetCallerIP(request); | 508 | return Util.GetCallerIP(request); |
@@ -418,9 +535,10 @@ namespace OpenSim.Server.Handlers.Simulation | |||
418 | } | 535 | } |
419 | 536 | ||
420 | // subclasses can override this | 537 | // subclasses can override this |
421 | protected virtual bool CreateAgent(GridRegion destination, AgentCircuitData aCircuit, uint teleportFlags, out string reason) | 538 | protected virtual bool CreateAgent(GridRegion source, GridRegion gatekeeper, GridRegion destination, |
539 | AgentCircuitData aCircuit, uint teleportFlags, bool fromLogin, out string reason) | ||
422 | { | 540 | { |
423 | return m_SimulationService.CreateAgent(destination, aCircuit, teleportFlags, out reason); | 541 | return m_SimulationService.CreateAgent(source, destination, aCircuit, teleportFlags, out reason); |
424 | } | 542 | } |
425 | } | 543 | } |
426 | 544 | ||
@@ -443,7 +561,7 @@ namespace OpenSim.Server.Handlers.Simulation | |||
443 | m_SimulationService = null; | 561 | m_SimulationService = null; |
444 | } | 562 | } |
445 | 563 | ||
446 | public override byte[] Handle(string path, Stream request, | 564 | protected override byte[] ProcessRequest(string path, Stream request, |
447 | IOSHttpRequest httpRequest, IOSHttpResponse httpResponse) | 565 | IOSHttpRequest httpRequest, IOSHttpResponse httpResponse) |
448 | { | 566 | { |
449 | // m_log.DebugFormat("[SIMULATION]: Stream handler called"); | 567 | // m_log.DebugFormat("[SIMULATION]: Stream handler called"); |
@@ -467,17 +585,31 @@ namespace OpenSim.Server.Handlers.Simulation | |||
467 | keysvals.Add("headers", headervals); | 585 | keysvals.Add("headers", headervals); |
468 | keysvals.Add("querystringkeys", querystringkeys); | 586 | keysvals.Add("querystringkeys", querystringkeys); |
469 | 587 | ||
470 | Stream inputStream; | 588 | String requestBody; |
471 | if (httpRequest.ContentType == "application/x-gzip") | ||
472 | inputStream = new GZipStream(request, CompressionMode.Decompress); | ||
473 | else | ||
474 | inputStream = request; | ||
475 | |||
476 | Encoding encoding = Encoding.UTF8; | 589 | Encoding encoding = Encoding.UTF8; |
477 | StreamReader reader = new StreamReader(inputStream, encoding); | ||
478 | 590 | ||
479 | string requestBody = reader.ReadToEnd(); | 591 | Stream inputStream = request; |
480 | reader.Close(); | 592 | Stream innerStream = null; |
593 | try | ||
594 | { | ||
595 | if ((httpRequest.ContentType == "application/x-gzip" || httpRequest.Headers["Content-Encoding"] == "gzip") || (httpRequest.Headers["X-Content-Encoding"] == "gzip")) | ||
596 | { | ||
597 | innerStream = inputStream; | ||
598 | inputStream = new GZipStream(innerStream, CompressionMode.Decompress); | ||
599 | } | ||
600 | |||
601 | using (StreamReader reader = new StreamReader(inputStream, encoding)) | ||
602 | { | ||
603 | requestBody = reader.ReadToEnd(); | ||
604 | } | ||
605 | } | ||
606 | finally | ||
607 | { | ||
608 | if (innerStream != null) | ||
609 | innerStream.Dispose(); | ||
610 | inputStream.Dispose(); | ||
611 | } | ||
612 | |||
481 | keysvals.Add("body", requestBody); | 613 | keysvals.Add("body", requestBody); |
482 | 614 | ||
483 | httpResponse.StatusCode = 200; | 615 | httpResponse.StatusCode = 200; |
@@ -562,7 +694,6 @@ namespace OpenSim.Server.Handlers.Simulation | |||
562 | //agent.Dump(); | 694 | //agent.Dump(); |
563 | // This is one of the meanings of PUT agent | 695 | // This is one of the meanings of PUT agent |
564 | result = UpdateAgent(destination, agent); | 696 | result = UpdateAgent(destination, agent); |
565 | |||
566 | } | 697 | } |
567 | else if ("AgentPosition".Equals(messageType)) | 698 | else if ("AgentPosition".Equals(messageType)) |
568 | { | 699 | { |
@@ -593,4 +724,14 @@ namespace OpenSim.Server.Handlers.Simulation | |||
593 | return m_SimulationService.UpdateAgent(destination, agent); | 724 | return m_SimulationService.UpdateAgent(destination, agent); |
594 | } | 725 | } |
595 | } | 726 | } |
727 | |||
728 | public class AgentDestinationData | ||
729 | { | ||
730 | public int x; | ||
731 | public int y; | ||
732 | public string name; | ||
733 | public UUID uuid; | ||
734 | public uint flags; | ||
735 | public bool fromLogin; | ||
736 | } | ||
596 | } | 737 | } |