aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Server/Handlers/Simulation
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--OpenSim/Server/Handlers/Simulation/AgentHandlers.cs182
1 files changed, 67 insertions, 115 deletions
diff --git a/OpenSim/Server/Handlers/Simulation/AgentHandlers.cs b/OpenSim/Server/Handlers/Simulation/AgentHandlers.cs
index 0bd8269..964ccf8 100644
--- a/OpenSim/Server/Handlers/Simulation/AgentHandlers.cs
+++ b/OpenSim/Server/Handlers/Simulation/AgentHandlers.cs
@@ -27,11 +27,13 @@
27 27
28using System; 28using System;
29using System.Collections; 29using System.Collections;
30using System.Collections.Specialized;
30using System.IO; 31using System.IO;
31using System.IO.Compression; 32using System.IO.Compression;
32using System.Reflection; 33using System.Reflection;
33using System.Net; 34using System.Net;
34using System.Text; 35using System.Text;
36using System.Web;
35 37
36using OpenSim.Server.Base; 38using OpenSim.Server.Base;
37using OpenSim.Server.Handlers.Base; 39using OpenSim.Server.Handlers.Base;
@@ -90,19 +92,13 @@ namespace OpenSim.Server.Handlers.Simulation
90 92
91 // Next, let's parse the verb 93 // Next, let's parse the verb
92 string method = (string)request["http-method"]; 94 string method = (string)request["http-method"];
93 if (method.Equals("GET")) 95 if (method.Equals("DELETE"))
94 { 96 {
95 DoAgentGet(request, responsedata, agentID, regionID); 97 string auth_token = string.Empty;
96 return responsedata; 98 if (request.ContainsKey("auth"))
97 } 99 auth_token = request["auth"].ToString();
98 else if (method.Equals("DELETE")) 100
99 { 101 DoAgentDelete(request, responsedata, agentID, action, regionID, auth_token);
100 DoAgentDelete(request, responsedata, agentID, action, regionID);
101 return responsedata;
102 }
103 else if (method.Equals("DELETECHILD"))
104 {
105 DoChildAgentDelete(request, responsedata, agentID, action, regionID);
106 return responsedata; 102 return responsedata;
107 } 103 }
108 else if (method.Equals("QUERYACCESS")) 104 else if (method.Equals("QUERYACCESS"))
@@ -112,7 +108,7 @@ namespace OpenSim.Server.Handlers.Simulation
112 } 108 }
113 else 109 else
114 { 110 {
115 m_log.InfoFormat("[AGENT HANDLER]: method {0} not supported in agent message", method); 111 m_log.ErrorFormat("[AGENT HANDLER]: method {0} not supported in agent message {1} (caller is {2})", method, (string)request["uri"], Util.GetCallerIP(request));
116 responsedata["int_response_code"] = HttpStatusCode.MethodNotAllowed; 112 responsedata["int_response_code"] = HttpStatusCode.MethodNotAllowed;
117 responsedata["str_response_string"] = "Method not allowed"; 113 responsedata["str_response_string"] = "Method not allowed";
118 114
@@ -161,79 +157,12 @@ namespace OpenSim.Server.Handlers.Simulation
161// Console.WriteLine("str_response_string [{0}]", responsedata["str_response_string"]); 157// Console.WriteLine("str_response_string [{0}]", responsedata["str_response_string"]);
162 } 158 }
163 159
164 protected virtual void DoAgentGet(Hashtable request, Hashtable responsedata, UUID id, UUID regionID) 160 protected void DoAgentDelete(Hashtable request, Hashtable responsedata, UUID id, string action, UUID regionID, string auth_token)
165 { 161 {
166 if (m_SimulationService == null) 162 if (string.IsNullOrEmpty(action))
167 { 163 m_log.DebugFormat("[AGENT HANDLER]: >>> DELETE <<< RegionID: {0}; from: {1}; auth_code: {2}", regionID, Util.GetCallerIP(request), auth_token);
168 m_log.Debug("[AGENT HANDLER]: Agent GET called. Harmless but useless.");
169 responsedata["content_type"] = "application/json";
170 responsedata["int_response_code"] = HttpStatusCode.NotImplemented;
171 responsedata["str_response_string"] = string.Empty;
172
173 return;
174 }
175
176 GridRegion destination = new GridRegion();
177 destination.RegionID = regionID;
178
179 IAgentData agent = null;
180 bool result = m_SimulationService.RetrieveAgent(destination, id, out agent);
181 OSDMap map = null;
182 if (result)
183 {
184 if (agent != null) // just to make sure
185 {
186 map = agent.Pack();
187 string strBuffer = "";
188 try
189 {
190 strBuffer = OSDParser.SerializeJsonString(map);
191 }
192 catch (Exception e)
193 {
194 m_log.WarnFormat("[AGENT HANDLER]: Exception thrown on serialization of DoAgentGet: {0}", e.Message);
195 responsedata["int_response_code"] = HttpStatusCode.InternalServerError;
196 // ignore. buffer will be empty, caller should check.
197 }
198
199 responsedata["content_type"] = "application/json";
200 responsedata["int_response_code"] = HttpStatusCode.OK;
201 responsedata["str_response_string"] = strBuffer;
202 }
203 else
204 {
205 responsedata["int_response_code"] = HttpStatusCode.InternalServerError;
206 responsedata["str_response_string"] = "Internal error";
207 }
208 }
209 else
210 {
211 responsedata["int_response_code"] = HttpStatusCode.NotFound;
212 responsedata["str_response_string"] = "Not Found";
213 }
214 }
215
216 protected void DoChildAgentDelete(Hashtable request, Hashtable responsedata, UUID id, string action, UUID regionID)
217 {
218 m_log.Debug(" >>> DoChildAgentDelete action:" + action + "; RegionID:" + regionID);
219
220 GridRegion destination = new GridRegion();
221 destination.RegionID = regionID;
222
223 if (action.Equals("release"))
224 ReleaseAgent(regionID, id);
225 else 164 else
226 m_SimulationService.CloseChildAgent(destination, id); 165 m_log.DebugFormat("[AGENT HANDLER]: Release {0} to RegionID: {1}", id, regionID);
227
228 responsedata["int_response_code"] = HttpStatusCode.OK;
229 responsedata["str_response_string"] = "OpenSim agent " + id.ToString();
230
231 m_log.Debug("[AGENT HANDLER]: Child Agent Released/Deleted.");
232 }
233
234 protected void DoAgentDelete(Hashtable request, Hashtable responsedata, UUID id, string action, UUID regionID)
235 {
236 m_log.Debug(" >>> DoDelete action:" + action + "; RegionID:" + regionID);
237 166
238 GridRegion destination = new GridRegion(); 167 GridRegion destination = new GridRegion();
239 destination.RegionID = regionID; 168 destination.RegionID = regionID;
@@ -241,12 +170,12 @@ namespace OpenSim.Server.Handlers.Simulation
241 if (action.Equals("release")) 170 if (action.Equals("release"))
242 ReleaseAgent(regionID, id); 171 ReleaseAgent(regionID, id);
243 else 172 else
244 m_SimulationService.CloseAgent(destination, id); 173 Util.FireAndForget(delegate { m_SimulationService.CloseAgent(destination, id, auth_token); });
245 174
246 responsedata["int_response_code"] = HttpStatusCode.OK; 175 responsedata["int_response_code"] = HttpStatusCode.OK;
247 responsedata["str_response_string"] = "OpenSim agent " + id.ToString(); 176 responsedata["str_response_string"] = "OpenSim agent " + id.ToString();
248 177
249 m_log.DebugFormat("[AGENT HANDLER]: Agent {0} Released/Deleted from region {1}", id, regionID); 178 //m_log.DebugFormat("[AGENT HANDLER]: Agent {0} Released/Deleted from region {1}", id, regionID);
250 } 179 }
251 180
252 protected virtual void ReleaseAgent(UUID regionID, UUID id) 181 protected virtual void ReleaseAgent(UUID regionID, UUID id)
@@ -274,7 +203,7 @@ namespace OpenSim.Server.Handlers.Simulation
274 m_SimulationService = null; 203 m_SimulationService = null;
275 } 204 }
276 205
277 public override byte[] Handle(string path, Stream request, 206 protected override byte[] ProcessRequest(string path, Stream request,
278 IOSHttpRequest httpRequest, IOSHttpResponse httpResponse) 207 IOSHttpRequest httpRequest, IOSHttpResponse httpResponse)
279 { 208 {
280// m_log.DebugFormat("[SIMULATION]: Stream handler called"); 209// m_log.DebugFormat("[SIMULATION]: Stream handler called");
@@ -351,31 +280,16 @@ namespace OpenSim.Server.Handlers.Simulation
351 return; 280 return;
352 } 281 }
353 282
354 // retrieve the input arguments 283 AgentDestinationData data = CreateAgentDestinationData();
355 int x = 0, y = 0; 284 UnpackData(args, data, request);
356 UUID uuid = UUID.Zero;
357 string regionname = string.Empty;
358 uint teleportFlags = 0;
359 if (args.ContainsKey("destination_x") && args["destination_x"] != null)
360 Int32.TryParse(args["destination_x"].AsString(), out x);
361 else
362 m_log.WarnFormat(" -- request didn't have destination_x");
363 if (args.ContainsKey("destination_y") && args["destination_y"] != null)
364 Int32.TryParse(args["destination_y"].AsString(), out y);
365 else
366 m_log.WarnFormat(" -- request didn't have destination_y");
367 if (args.ContainsKey("destination_uuid") && args["destination_uuid"] != null)
368 UUID.TryParse(args["destination_uuid"].AsString(), out uuid);
369 if (args.ContainsKey("destination_name") && args["destination_name"] != null)
370 regionname = args["destination_name"].ToString();
371 if (args.ContainsKey("teleport_flags") && args["teleport_flags"] != null)
372 teleportFlags = args["teleport_flags"].AsUInteger();
373 285
374 GridRegion destination = new GridRegion(); 286 GridRegion destination = new GridRegion();
375 destination.RegionID = uuid; 287 destination.RegionID = data.uuid;
376 destination.RegionLocX = x; 288 destination.RegionLocX = data.x;
377 destination.RegionLocY = y; 289 destination.RegionLocY = data.y;
378 destination.RegionName = regionname; 290 destination.RegionName = data.name;
291
292 GridRegion gatekeeper = ExtractGatekeeper(data);
379 293
380 AgentCircuitData aCircuit = new AgentCircuitData(); 294 AgentCircuitData aCircuit = new AgentCircuitData();
381 try 295 try
@@ -396,7 +310,7 @@ namespace OpenSim.Server.Handlers.Simulation
396 // This is the meaning of POST agent 310 // This is the meaning of POST agent
397 //m_regionClient.AdjustUserInformation(aCircuit); 311 //m_regionClient.AdjustUserInformation(aCircuit);
398 //bool result = m_SimulationService.CreateAgent(destination, aCircuit, teleportFlags, out reason); 312 //bool result = m_SimulationService.CreateAgent(destination, aCircuit, teleportFlags, out reason);
399 bool result = CreateAgent(destination, aCircuit, teleportFlags, out reason); 313 bool result = CreateAgent(gatekeeper, destination, aCircuit, data.flags, data.fromLogin, out reason);
400 314
401 resp["reason"] = OSD.FromString(reason); 315 resp["reason"] = OSD.FromString(reason);
402 resp["success"] = OSD.FromBoolean(result); 316 resp["success"] = OSD.FromBoolean(result);
@@ -408,7 +322,36 @@ namespace OpenSim.Server.Handlers.Simulation
408 responsedata["str_response_string"] = OSDParser.SerializeJsonString(resp); 322 responsedata["str_response_string"] = OSDParser.SerializeJsonString(resp);
409 } 323 }
410 324
411 private string GetCallerIP(Hashtable request) 325 protected virtual AgentDestinationData CreateAgentDestinationData()
326 {
327 return new AgentDestinationData();
328 }
329
330 protected virtual void UnpackData(OSDMap args, AgentDestinationData data, Hashtable request)
331 {
332 // retrieve the input arguments
333 if (args.ContainsKey("destination_x") && args["destination_x"] != null)
334 Int32.TryParse(args["destination_x"].AsString(), out data.x);
335 else
336 m_log.WarnFormat(" -- request didn't have destination_x");
337 if (args.ContainsKey("destination_y") && args["destination_y"] != null)
338 Int32.TryParse(args["destination_y"].AsString(), out data.y);
339 else
340 m_log.WarnFormat(" -- request didn't have destination_y");
341 if (args.ContainsKey("destination_uuid") && args["destination_uuid"] != null)
342 UUID.TryParse(args["destination_uuid"].AsString(), out data.uuid);
343 if (args.ContainsKey("destination_name") && args["destination_name"] != null)
344 data.name = args["destination_name"].ToString();
345 if (args.ContainsKey("teleport_flags") && args["teleport_flags"] != null)
346 data.flags = args["teleport_flags"].AsUInteger();
347 }
348
349 protected virtual GridRegion ExtractGatekeeper(AgentDestinationData data)
350 {
351 return null;
352 }
353
354 protected string GetCallerIP(Hashtable request)
412 { 355 {
413 if (!m_Proxy) 356 if (!m_Proxy)
414 return Util.GetCallerIP(request); 357 return Util.GetCallerIP(request);
@@ -441,7 +384,7 @@ namespace OpenSim.Server.Handlers.Simulation
441 } 384 }
442 385
443 // subclasses can override this 386 // subclasses can override this
444 protected virtual bool CreateAgent(GridRegion destination, AgentCircuitData aCircuit, uint teleportFlags, out string reason) 387 protected virtual bool CreateAgent(GridRegion gatekeeper, GridRegion destination, AgentCircuitData aCircuit, uint teleportFlags, bool fromLogin, out string reason)
445 { 388 {
446 reason = String.Empty; 389 reason = String.Empty;
447 390
@@ -474,7 +417,7 @@ namespace OpenSim.Server.Handlers.Simulation
474 m_SimulationService = null; 417 m_SimulationService = null;
475 } 418 }
476 419
477 public override byte[] Handle(string path, Stream request, 420 protected override byte[] ProcessRequest(string path, Stream request,
478 IOSHttpRequest httpRequest, IOSHttpResponse httpResponse) 421 IOSHttpRequest httpRequest, IOSHttpResponse httpResponse)
479 { 422 {
480// m_log.DebugFormat("[SIMULATION]: Stream handler called"); 423// m_log.DebugFormat("[SIMULATION]: Stream handler called");
@@ -593,7 +536,6 @@ namespace OpenSim.Server.Handlers.Simulation
593 //agent.Dump(); 536 //agent.Dump();
594 // This is one of the meanings of PUT agent 537 // This is one of the meanings of PUT agent
595 result = UpdateAgent(destination, agent); 538 result = UpdateAgent(destination, agent);
596
597 } 539 }
598 else if ("AgentPosition".Equals(messageType)) 540 else if ("AgentPosition".Equals(messageType))
599 { 541 {
@@ -624,4 +566,14 @@ namespace OpenSim.Server.Handlers.Simulation
624 return m_SimulationService.UpdateAgent(destination, agent); 566 return m_SimulationService.UpdateAgent(destination, agent);
625 } 567 }
626 } 568 }
569
570 public class AgentDestinationData
571 {
572 public int x;
573 public int y;
574 public string name;
575 public UUID uuid;
576 public uint flags;
577 public bool fromLogin;
578 }
627} 579}