aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Server/Handlers/Simulation
diff options
context:
space:
mode:
authorMelanie2011-05-08 23:23:33 +0200
committerMelanie2011-05-08 23:23:33 +0200
commitade09d0fa1e4c1331bedcf2a5f99402436d8f187 (patch)
tree12185bb087bdd13b4ed7a35aa3030c06c5ca9790 /OpenSim/Server/Handlers/Simulation
parentMerge branch 'master' into careminster-presence-refactor (diff)
downloadopensim-SC_OLD-ade09d0fa1e4c1331bedcf2a5f99402436d8f187.zip
opensim-SC_OLD-ade09d0fa1e4c1331bedcf2a5f99402436d8f187.tar.gz
opensim-SC_OLD-ade09d0fa1e4c1331bedcf2a5f99402436d8f187.tar.bz2
opensim-SC_OLD-ade09d0fa1e4c1331bedcf2a5f99402436d8f187.tar.xz
Also compress the actual fatpacks
Diffstat (limited to 'OpenSim/Server/Handlers/Simulation')
-rw-r--r--OpenSim/Server/Handlers/Simulation/AgentHandlers.cs264
-rw-r--r--OpenSim/Server/Handlers/Simulation/SimulationServiceInConnector.cs1
2 files changed, 171 insertions, 94 deletions
diff --git a/OpenSim/Server/Handlers/Simulation/AgentHandlers.cs b/OpenSim/Server/Handlers/Simulation/AgentHandlers.cs
index 6d06cb8..9f581ca 100644
--- a/OpenSim/Server/Handlers/Simulation/AgentHandlers.cs
+++ b/OpenSim/Server/Handlers/Simulation/AgentHandlers.cs
@@ -90,12 +90,7 @@ namespace OpenSim.Server.Handlers.Simulation
90 90
91 // Next, let's parse the verb 91 // Next, let's parse the verb
92 string method = (string)request["http-method"]; 92 string method = (string)request["http-method"];
93 if (method.Equals("PUT")) 93 if (method.Equals("GET"))
94 {
95 DoAgentPut(request, responsedata);
96 return responsedata;
97 }
98 else if (method.Equals("GET"))
99 { 94 {
100 DoAgentGet(request, responsedata, agentID, regionID); 95 DoAgentGet(request, responsedata, agentID, regionID);
101 return responsedata; 96 return responsedata;
@@ -126,94 +121,6 @@ namespace OpenSim.Server.Handlers.Simulation
126 121
127 } 122 }
128 123
129 protected void DoAgentPut(Hashtable request, Hashtable responsedata)
130 {
131 OSDMap args = Utils.GetOSDMap((string)request["body"]);
132 if (args == null)
133 {
134 responsedata["int_response_code"] = HttpStatusCode.BadRequest;
135 responsedata["str_response_string"] = "Bad request";
136 return;
137 }
138
139 // retrieve the input arguments
140 int x = 0, y = 0;
141 UUID uuid = UUID.Zero;
142 string regionname = string.Empty;
143 if (args.ContainsKey("destination_x") && args["destination_x"] != null)
144 Int32.TryParse(args["destination_x"].AsString(), out x);
145 if (args.ContainsKey("destination_y") && args["destination_y"] != null)
146 Int32.TryParse(args["destination_y"].AsString(), out y);
147 if (args.ContainsKey("destination_uuid") && args["destination_uuid"] != null)
148 UUID.TryParse(args["destination_uuid"].AsString(), out uuid);
149 if (args.ContainsKey("destination_name") && args["destination_name"] != null)
150 regionname = args["destination_name"].ToString();
151
152 GridRegion destination = new GridRegion();
153 destination.RegionID = uuid;
154 destination.RegionLocX = x;
155 destination.RegionLocY = y;
156 destination.RegionName = regionname;
157
158 string messageType;
159 if (args["message_type"] != null)
160 messageType = args["message_type"].AsString();
161 else
162 {
163 m_log.Warn("[AGENT HANDLER]: Agent Put Message Type not found. ");
164 messageType = "AgentData";
165 }
166
167 bool result = true;
168 if ("AgentData".Equals(messageType))
169 {
170 AgentData agent = new AgentData();
171 try
172 {
173 agent.Unpack(args, m_SimulationService.GetScene(destination.RegionHandle));
174 }
175 catch (Exception ex)
176 {
177 m_log.InfoFormat("[AGENT HANDLER]: exception on unpacking ChildAgentUpdate message {0}", ex.Message);
178 responsedata["int_response_code"] = HttpStatusCode.BadRequest;
179 responsedata["str_response_string"] = "Bad request";
180 return;
181 }
182
183 //agent.Dump();
184 // This is one of the meanings of PUT agent
185 result = UpdateAgent(destination, agent);
186
187 }
188 else if ("AgentPosition".Equals(messageType))
189 {
190 AgentPosition agent = new AgentPosition();
191 try
192 {
193 agent.Unpack(args, m_SimulationService.GetScene(destination.RegionHandle));
194 }
195 catch (Exception ex)
196 {
197 m_log.InfoFormat("[AGENT HANDLER]: exception on unpacking ChildAgentUpdate message {0}", ex.Message);
198 return;
199 }
200 //agent.Dump();
201 // This is one of the meanings of PUT agent
202 result = m_SimulationService.UpdateAgent(destination, agent);
203
204 }
205
206 responsedata["int_response_code"] = HttpStatusCode.OK;
207 responsedata["str_response_string"] = result.ToString();
208 //responsedata["str_response_string"] = OSDParser.SerializeJsonString(resp); ??? instead
209 }
210
211 // subclasses can override this
212 protected virtual bool UpdateAgent(GridRegion destination, AgentData agent)
213 {
214 return m_SimulationService.UpdateAgent(destination, agent);
215 }
216
217 protected virtual void DoQueryAccess(Hashtable request, Hashtable responsedata, UUID id, UUID regionID) 124 protected virtual void DoQueryAccess(Hashtable request, Hashtable responsedata, UUID id, UUID regionID)
218 { 125 {
219 if (m_SimulationService == null) 126 if (m_SimulationService == null)
@@ -531,4 +438,173 @@ namespace OpenSim.Server.Handlers.Simulation
531 return m_SimulationService.CreateAgent(destination, aCircuit, teleportFlags, out reason); 438 return m_SimulationService.CreateAgent(destination, aCircuit, teleportFlags, out reason);
532 } 439 }
533 } 440 }
441
442 public class AgentPutHandler : BaseStreamHandler
443 {
444 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
445
446 private ISimulationService m_SimulationService;
447 protected bool m_Proxy = false;
448
449 public AgentPutHandler(ISimulationService service) :
450 base("PUT", "/agent")
451 {
452 m_SimulationService = service;
453 }
454
455 public AgentPutHandler(string path) :
456 base("PUT", path)
457 {
458 m_SimulationService = null;
459 }
460
461 public override byte[] Handle(string path, Stream request,
462 OSHttpRequest httpRequest, OSHttpResponse httpResponse)
463 {
464 m_log.DebugFormat("[SIMULATION]: Stream handler called");
465
466 Hashtable keysvals = new Hashtable();
467 Hashtable headervals = new Hashtable();
468
469 string[] querystringkeys = httpRequest.QueryString.AllKeys;
470 string[] rHeaders = httpRequest.Headers.AllKeys;
471
472 keysvals.Add("uri", httpRequest.RawUrl);
473 keysvals.Add("content-type", httpRequest.ContentType);
474 keysvals.Add("http-method", httpRequest.HttpMethod);
475
476 foreach (string queryname in querystringkeys)
477 keysvals.Add(queryname, httpRequest.QueryString[queryname]);
478
479 foreach (string headername in rHeaders)
480 headervals[headername] = httpRequest.Headers[headername];
481
482 keysvals.Add("headers", headervals);
483 keysvals.Add("querystringkeys", querystringkeys);
484
485 Stream inputStream;
486 if (httpRequest.ContentType == "application/x-gzip")
487 inputStream = new GZipStream(request, CompressionMode.Decompress);
488 else
489 inputStream = request;
490
491 Encoding encoding = Encoding.UTF8;
492 StreamReader reader = new StreamReader(inputStream, encoding);
493
494 string requestBody = reader.ReadToEnd();
495 keysvals.Add("body", requestBody);
496
497 httpResponse.StatusCode = 200;
498 httpResponse.ContentType = "text/html";
499 httpResponse.KeepAlive = false;
500
501 Hashtable responsedata = new Hashtable();
502
503 UUID agentID;
504 UUID regionID;
505 string action;
506
507 if (!Utils.GetParams((string)keysvals["uri"], out agentID, out regionID, out action))
508 {
509 m_log.InfoFormat("[AGENT HANDLER]: Invalid parameters for agent message {0}", keysvals["uri"]);
510
511 httpResponse.StatusCode = 404;
512
513 return encoding.GetBytes("false");
514 }
515
516 DoAgentPut(keysvals, responsedata);
517
518 httpResponse.StatusCode = (int)responsedata["int_response_code"];
519 return encoding.GetBytes((string)responsedata["str_response_string"]);
520 }
521
522 protected void DoAgentPut(Hashtable request, Hashtable responsedata)
523 {
524 OSDMap args = Utils.GetOSDMap((string)request["body"]);
525 if (args == null)
526 {
527 responsedata["int_response_code"] = HttpStatusCode.BadRequest;
528 responsedata["str_response_string"] = "Bad request";
529 return;
530 }
531
532 // retrieve the input arguments
533 int x = 0, y = 0;
534 UUID uuid = UUID.Zero;
535 string regionname = string.Empty;
536 if (args.ContainsKey("destination_x") && args["destination_x"] != null)
537 Int32.TryParse(args["destination_x"].AsString(), out x);
538 if (args.ContainsKey("destination_y") && args["destination_y"] != null)
539 Int32.TryParse(args["destination_y"].AsString(), out y);
540 if (args.ContainsKey("destination_uuid") && args["destination_uuid"] != null)
541 UUID.TryParse(args["destination_uuid"].AsString(), out uuid);
542 if (args.ContainsKey("destination_name") && args["destination_name"] != null)
543 regionname = args["destination_name"].ToString();
544
545 GridRegion destination = new GridRegion();
546 destination.RegionID = uuid;
547 destination.RegionLocX = x;
548 destination.RegionLocY = y;
549 destination.RegionName = regionname;
550
551 string messageType;
552 if (args["message_type"] != null)
553 messageType = args["message_type"].AsString();
554 else
555 {
556 m_log.Warn("[AGENT HANDLER]: Agent Put Message Type not found. ");
557 messageType = "AgentData";
558 }
559
560 bool result = true;
561 if ("AgentData".Equals(messageType))
562 {
563 AgentData agent = new AgentData();
564 try
565 {
566 agent.Unpack(args, m_SimulationService.GetScene(destination.RegionHandle));
567 }
568 catch (Exception ex)
569 {
570 m_log.InfoFormat("[AGENT HANDLER]: exception on unpacking ChildAgentUpdate message {0}", ex.Message);
571 responsedata["int_response_code"] = HttpStatusCode.BadRequest;
572 responsedata["str_response_string"] = "Bad request";
573 return;
574 }
575
576 //agent.Dump();
577 // This is one of the meanings of PUT agent
578 result = UpdateAgent(destination, agent);
579
580 }
581 else if ("AgentPosition".Equals(messageType))
582 {
583 AgentPosition agent = new AgentPosition();
584 try
585 {
586 agent.Unpack(args, m_SimulationService.GetScene(destination.RegionHandle));
587 }
588 catch (Exception ex)
589 {
590 m_log.InfoFormat("[AGENT HANDLER]: exception on unpacking ChildAgentUpdate message {0}", ex.Message);
591 return;
592 }
593 //agent.Dump();
594 // This is one of the meanings of PUT agent
595 result = m_SimulationService.UpdateAgent(destination, agent);
596
597 }
598
599 responsedata["int_response_code"] = HttpStatusCode.OK;
600 responsedata["str_response_string"] = result.ToString();
601 //responsedata["str_response_string"] = OSDParser.SerializeJsonString(resp); ??? instead
602 }
603
604 // subclasses can override this
605 protected virtual bool UpdateAgent(GridRegion destination, AgentData agent)
606 {
607 return m_SimulationService.UpdateAgent(destination, agent);
608 }
609 }
534} 610}
diff --git a/OpenSim/Server/Handlers/Simulation/SimulationServiceInConnector.cs b/OpenSim/Server/Handlers/Simulation/SimulationServiceInConnector.cs
index 42d8eca..0da08f8 100644
--- a/OpenSim/Server/Handlers/Simulation/SimulationServiceInConnector.cs
+++ b/OpenSim/Server/Handlers/Simulation/SimulationServiceInConnector.cs
@@ -50,6 +50,7 @@ namespace OpenSim.Server.Handlers.Simulation
50 // are pure binary and shoehorning that into a string with UTF-8 50 // are pure binary and shoehorning that into a string with UTF-8
51 // encoding breaks it 51 // encoding breaks it
52 server.AddStreamHandler(new AgentPostHandler(m_LocalSimulationService)); 52 server.AddStreamHandler(new AgentPostHandler(m_LocalSimulationService));
53 server.AddStreamHandler(new AgentPutHandler(m_LocalSimulationService));
53 server.AddHTTPHandler("/agent/", new AgentHandler(m_LocalSimulationService).Handler); 54 server.AddHTTPHandler("/agent/", new AgentHandler(m_LocalSimulationService).Handler);
54 server.AddHTTPHandler("/object/", new ObjectHandler(m_LocalSimulationService).Handler); 55 server.AddHTTPHandler("/object/", new ObjectHandler(m_LocalSimulationService).Handler);
55 } 56 }