AgentHandlers.cs 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665
  1. /*
  2. * Copyright (c) Contributors, http://opensimulator.org/
  3. * See CONTRIBUTORS.TXT for a full list of copyright holders.
  4. *
  5. * Redistribution and use in source and binary forms, with or without
  6. * modification, are permitted provided that the following conditions are met:
  7. * * Redistributions of source code must retain the above copyright
  8. * notice, this list of conditions and the following disclaimer.
  9. * * Redistributions in binary form must reproduce the above copyright
  10. * notice, this list of conditions and the following disclaimer in the
  11. * documentation and/or other materials provided with the distribution.
  12. * * Neither the name of the OpenSimulator Project nor the
  13. * names of its contributors may be used to endorse or promote products
  14. * derived from this software without specific prior written permission.
  15. *
  16. * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
  17. * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  18. * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  19. * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
  20. * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  21. * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  22. * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  23. * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  24. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  25. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  26. */
  27. using System;
  28. using System.Collections;
  29. using System.Collections.Generic;
  30. using System.Collections.Specialized;
  31. using System.IO;
  32. using System.IO.Compression;
  33. using System.Reflection;
  34. using System.Net;
  35. using System.Text;
  36. using System.Web;
  37. using OpenSim.Server.Base;
  38. using OpenSim.Server.Handlers.Base;
  39. using OpenSim.Services.Interfaces;
  40. using GridRegion = OpenSim.Services.Interfaces.GridRegion;
  41. using OpenSim.Framework;
  42. using OpenSim.Framework.Servers.HttpServer;
  43. using OpenMetaverse;
  44. using OpenMetaverse.StructuredData;
  45. using Nini.Config;
  46. using log4net;
  47. namespace OpenSim.Server.Handlers.Simulation
  48. {
  49. public class AgentHandler
  50. {
  51. private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
  52. private ISimulationService m_SimulationService;
  53. public AgentHandler() { }
  54. public AgentHandler(ISimulationService sim)
  55. {
  56. m_SimulationService = sim;
  57. }
  58. public Hashtable Handler(Hashtable request)
  59. {
  60. // m_log.Debug("[CONNECTION DEBUGGING]: AgentHandler Called");
  61. //
  62. // m_log.Debug("---------------------------");
  63. // m_log.Debug(" >> uri=" + request["uri"]);
  64. // m_log.Debug(" >> content-type=" + request["content-type"]);
  65. // m_log.Debug(" >> http-method=" + request["http-method"]);
  66. // m_log.Debug("---------------------------\n");
  67. Hashtable responsedata = new Hashtable();
  68. responsedata["content_type"] = "text/html";
  69. responsedata["keepalive"] = false;
  70. UUID agentID;
  71. UUID regionID;
  72. string action;
  73. if (!Utils.GetParams((string)request["uri"], out agentID, out regionID, out action))
  74. {
  75. m_log.InfoFormat("[AGENT HANDLER]: Invalid parameters for agent message {0}", request["uri"]);
  76. responsedata["int_response_code"] = 404;
  77. responsedata["str_response_string"] = "false";
  78. return responsedata;
  79. }
  80. // Next, let's parse the verb
  81. string method = (string)request["http-method"];
  82. if (method.Equals("DELETE"))
  83. {
  84. string auth_token = string.Empty;
  85. if (request.ContainsKey("auth"))
  86. auth_token = request["auth"].ToString();
  87. DoAgentDelete(request, responsedata, agentID, action, regionID, auth_token);
  88. return responsedata;
  89. }
  90. else if (method.Equals("QUERYACCESS"))
  91. {
  92. DoQueryAccess(request, responsedata, agentID, regionID);
  93. return responsedata;
  94. }
  95. else
  96. {
  97. m_log.ErrorFormat("[AGENT HANDLER]: method {0} not supported in agent message {1} (caller is {2})", method, (string)request["uri"], Util.GetCallerIP(request));
  98. responsedata["int_response_code"] = HttpStatusCode.MethodNotAllowed;
  99. responsedata["str_response_string"] = "Method not allowed";
  100. return responsedata;
  101. }
  102. }
  103. protected virtual void DoQueryAccess(Hashtable request, Hashtable responsedata, UUID agentID, UUID regionID)
  104. {
  105. if (m_SimulationService == null)
  106. {
  107. m_log.Debug("[AGENT HANDLER]: Agent QUERY called. Harmless but useless.");
  108. responsedata["content_type"] = "application/json";
  109. responsedata["int_response_code"] = HttpStatusCode.NotImplemented;
  110. responsedata["str_response_string"] = string.Empty;
  111. return;
  112. }
  113. // m_log.DebugFormat("[AGENT HANDLER]: Received QUERYACCESS with {0}", (string)request["body"]);
  114. OSDMap args = Utils.GetOSDMap((string)request["body"]);
  115. bool viaTeleport = true;
  116. if (args.ContainsKey("viaTeleport"))
  117. viaTeleport = args["viaTeleport"].AsBoolean();
  118. Vector3 position = Vector3.Zero;
  119. if (args.ContainsKey("position"))
  120. position = Vector3.Parse(args["position"].AsString());
  121. string agentHomeURI = null;
  122. if (args.ContainsKey("agent_home_uri"))
  123. agentHomeURI = args["agent_home_uri"].AsString();
  124. string theirVersion = string.Empty;
  125. if (args.ContainsKey("my_version"))
  126. theirVersion = args["my_version"].AsString();
  127. List<UUID> features = new List<UUID>();
  128. if (args.ContainsKey("features"))
  129. {
  130. OSDArray array = (OSDArray)args["features"];
  131. foreach (OSD o in array)
  132. features.Add(new UUID(o.AsString()));
  133. }
  134. GridRegion destination = new GridRegion();
  135. destination.RegionID = regionID;
  136. string reason;
  137. string version;
  138. bool result = m_SimulationService.QueryAccess(destination, agentID, agentHomeURI, viaTeleport, position, theirVersion, features, out version, out reason);
  139. responsedata["int_response_code"] = HttpStatusCode.OK;
  140. OSDMap resp = new OSDMap(3);
  141. resp["success"] = OSD.FromBoolean(result);
  142. resp["reason"] = OSD.FromString(reason);
  143. resp["version"] = OSD.FromString(version);
  144. OSDArray featuresWanted = new OSDArray();
  145. foreach (UUID feature in features)
  146. featuresWanted.Add(OSD.FromString(feature.ToString()));
  147. resp["features"] = featuresWanted;
  148. // We must preserve defaults here, otherwise a false "success" will not be put into the JSON map!
  149. responsedata["str_response_string"] = OSDParser.SerializeJsonString(resp, true);
  150. // Console.WriteLine("str_response_string [{0}]", responsedata["str_response_string"]);
  151. }
  152. protected void DoAgentDelete(Hashtable request, Hashtable responsedata, UUID id, string action, UUID regionID, string auth_token)
  153. {
  154. if (string.IsNullOrEmpty(action))
  155. m_log.DebugFormat("[AGENT HANDLER]: >>> DELETE <<< RegionID: {0}; from: {1}; auth_code: {2}", regionID, Util.GetCallerIP(request), auth_token);
  156. else
  157. m_log.DebugFormat("[AGENT HANDLER]: Release {0} to RegionID: {1}", id, regionID);
  158. GridRegion destination = new GridRegion();
  159. destination.RegionID = regionID;
  160. if (action.Equals("release"))
  161. ReleaseAgent(regionID, id);
  162. else
  163. Util.FireAndForget(
  164. o => m_SimulationService.CloseAgent(destination, id, auth_token), null, "AgentHandler.DoAgentDelete");
  165. responsedata["int_response_code"] = HttpStatusCode.OK;
  166. responsedata["str_response_string"] = "OpenSim agent " + id.ToString();
  167. //m_log.DebugFormat("[AGENT HANDLER]: Agent {0} Released/Deleted from region {1}", id, regionID);
  168. }
  169. protected virtual void ReleaseAgent(UUID regionID, UUID id)
  170. {
  171. m_SimulationService.ReleaseAgent(regionID, id, "");
  172. }
  173. }
  174. public class AgentPostHandler : BaseStreamHandler
  175. {
  176. private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
  177. private ISimulationService m_SimulationService;
  178. protected bool m_Proxy = false;
  179. public AgentPostHandler(ISimulationService service) :
  180. base("POST", "/agent")
  181. {
  182. m_SimulationService = service;
  183. }
  184. public AgentPostHandler(string path) :
  185. base("POST", path)
  186. {
  187. m_SimulationService = null;
  188. }
  189. protected override byte[] ProcessRequest(string path, Stream request,
  190. IOSHttpRequest httpRequest, IOSHttpResponse httpResponse)
  191. {
  192. // m_log.DebugFormat("[SIMULATION]: Stream handler called");
  193. Hashtable keysvals = new Hashtable();
  194. Hashtable headervals = new Hashtable();
  195. string[] querystringkeys = httpRequest.QueryString.AllKeys;
  196. string[] rHeaders = httpRequest.Headers.AllKeys;
  197. keysvals.Add("uri", httpRequest.RawUrl);
  198. keysvals.Add("content-type", httpRequest.ContentType);
  199. keysvals.Add("http-method", httpRequest.HttpMethod);
  200. foreach (string queryname in querystringkeys)
  201. keysvals.Add(queryname, httpRequest.QueryString[queryname]);
  202. foreach (string headername in rHeaders)
  203. headervals[headername] = httpRequest.Headers[headername];
  204. keysvals.Add("headers", headervals);
  205. keysvals.Add("querystringkeys", querystringkeys);
  206. httpResponse.StatusCode = 200;
  207. httpResponse.ContentType = "text/html";
  208. httpResponse.KeepAlive = false;
  209. Encoding encoding = Encoding.UTF8;
  210. if (httpRequest.ContentType != "application/json")
  211. {
  212. httpResponse.StatusCode = 406;
  213. return encoding.GetBytes("false");
  214. }
  215. string requestBody;
  216. Stream inputStream = request;
  217. Stream innerStream = null;
  218. try
  219. {
  220. if ((httpRequest.ContentType == "application/x-gzip" || httpRequest.Headers["Content-Encoding"] == "gzip") || (httpRequest.Headers["X-Content-Encoding"] == "gzip"))
  221. {
  222. innerStream = inputStream;
  223. inputStream = new GZipStream(innerStream, CompressionMode.Decompress);
  224. }
  225. using (StreamReader reader = new StreamReader(inputStream, encoding))
  226. {
  227. requestBody = reader.ReadToEnd();
  228. }
  229. }
  230. finally
  231. {
  232. if (innerStream != null)
  233. innerStream.Dispose();
  234. inputStream.Dispose();
  235. }
  236. keysvals.Add("body", requestBody);
  237. Hashtable responsedata = new Hashtable();
  238. UUID agentID;
  239. UUID regionID;
  240. string action;
  241. if (!Utils.GetParams((string)keysvals["uri"], out agentID, out regionID, out action))
  242. {
  243. m_log.InfoFormat("[AGENT HANDLER]: Invalid parameters for agent message {0}", keysvals["uri"]);
  244. httpResponse.StatusCode = 404;
  245. return encoding.GetBytes("false");
  246. }
  247. DoAgentPost(keysvals, responsedata, agentID);
  248. httpResponse.StatusCode = (int)responsedata["int_response_code"];
  249. return encoding.GetBytes((string)responsedata["str_response_string"]);
  250. }
  251. protected void DoAgentPost(Hashtable request, Hashtable responsedata, UUID id)
  252. {
  253. OSDMap args = Utils.GetOSDMap((string)request["body"]);
  254. if (args == null)
  255. {
  256. responsedata["int_response_code"] = HttpStatusCode.BadRequest;
  257. responsedata["str_response_string"] = "Bad request";
  258. return;
  259. }
  260. AgentDestinationData data = CreateAgentDestinationData();
  261. UnpackData(args, data, request);
  262. GridRegion destination = new GridRegion();
  263. destination.RegionID = data.uuid;
  264. destination.RegionLocX = data.x;
  265. destination.RegionLocY = data.y;
  266. destination.RegionName = data.name;
  267. GridRegion gatekeeper = ExtractGatekeeper(data);
  268. AgentCircuitData aCircuit = new AgentCircuitData();
  269. try
  270. {
  271. aCircuit.UnpackAgentCircuitData(args);
  272. }
  273. catch (Exception ex)
  274. {
  275. m_log.InfoFormat("[AGENT HANDLER]: exception on unpacking ChildCreate message {0}", ex.Message);
  276. responsedata["int_response_code"] = HttpStatusCode.BadRequest;
  277. responsedata["str_response_string"] = "Bad request";
  278. return;
  279. }
  280. GridRegion source = null;
  281. if (args.ContainsKey("source_uuid"))
  282. {
  283. source = new GridRegion();
  284. source.RegionLocX = Int32.Parse(args["source_x"].AsString());
  285. source.RegionLocY = Int32.Parse(args["source_y"].AsString());
  286. source.RegionName = args["source_name"].AsString();
  287. source.RegionID = UUID.Parse(args["source_uuid"].AsString());
  288. if (args.ContainsKey("source_server_uri"))
  289. source.RawServerURI = args["source_server_uri"].AsString();
  290. else
  291. source.RawServerURI = null;
  292. }
  293. OSDMap resp = new OSDMap(2);
  294. string reason = String.Empty;
  295. // This is the meaning of POST agent
  296. //m_regionClient.AdjustUserInformation(aCircuit);
  297. //bool result = m_SimulationService.CreateAgent(destination, aCircuit, teleportFlags, out reason);
  298. bool result = CreateAgent(source, gatekeeper, destination, aCircuit, data.flags, data.fromLogin, out reason);
  299. resp["reason"] = OSD.FromString(reason);
  300. resp["success"] = OSD.FromBoolean(result);
  301. // Let's also send out the IP address of the caller back to the caller (HG 1.5)
  302. resp["your_ip"] = OSD.FromString(GetCallerIP(request));
  303. // TODO: add reason if not String.Empty?
  304. responsedata["int_response_code"] = HttpStatusCode.OK;
  305. responsedata["str_response_string"] = OSDParser.SerializeJsonString(resp);
  306. }
  307. protected virtual AgentDestinationData CreateAgentDestinationData()
  308. {
  309. return new AgentDestinationData();
  310. }
  311. protected virtual void UnpackData(OSDMap args, AgentDestinationData data, Hashtable request)
  312. {
  313. // retrieve the input arguments
  314. if (args.ContainsKey("destination_x") && args["destination_x"] != null)
  315. Int32.TryParse(args["destination_x"].AsString(), out data.x);
  316. else
  317. m_log.WarnFormat(" -- request didn't have destination_x");
  318. if (args.ContainsKey("destination_y") && args["destination_y"] != null)
  319. Int32.TryParse(args["destination_y"].AsString(), out data.y);
  320. else
  321. m_log.WarnFormat(" -- request didn't have destination_y");
  322. if (args.ContainsKey("destination_uuid") && args["destination_uuid"] != null)
  323. UUID.TryParse(args["destination_uuid"].AsString(), out data.uuid);
  324. if (args.ContainsKey("destination_name") && args["destination_name"] != null)
  325. data.name = args["destination_name"].ToString();
  326. if (args.ContainsKey("teleport_flags") && args["teleport_flags"] != null)
  327. data.flags = args["teleport_flags"].AsUInteger();
  328. }
  329. protected virtual GridRegion ExtractGatekeeper(AgentDestinationData data)
  330. {
  331. return null;
  332. }
  333. protected string GetCallerIP(Hashtable request)
  334. {
  335. if (!m_Proxy)
  336. return Util.GetCallerIP(request);
  337. // We're behind a proxy
  338. Hashtable headers = (Hashtable)request["headers"];
  339. //// DEBUG
  340. //foreach (object o in headers.Keys)
  341. // m_log.DebugFormat("XXX {0} = {1}", o.ToString(), (headers[o] == null? "null" : headers[o].ToString()));
  342. string xff = "X-Forwarded-For";
  343. if (headers.ContainsKey(xff.ToLower()))
  344. xff = xff.ToLower();
  345. if (!headers.ContainsKey(xff) || headers[xff] == null)
  346. {
  347. m_log.WarnFormat("[AGENT HANDLER]: No XFF header");
  348. return Util.GetCallerIP(request);
  349. }
  350. m_log.DebugFormat("[AGENT HANDLER]: XFF is {0}", headers[xff]);
  351. IPEndPoint ep = Util.GetClientIPFromXFF((string)headers[xff]);
  352. if (ep != null)
  353. return ep.Address.ToString();
  354. // Oops
  355. return Util.GetCallerIP(request);
  356. }
  357. // subclasses can override this
  358. protected virtual bool CreateAgent(GridRegion source, GridRegion gatekeeper, GridRegion destination,
  359. AgentCircuitData aCircuit, uint teleportFlags, bool fromLogin, out string reason)
  360. {
  361. reason = String.Empty;
  362. if ((teleportFlags & (uint)TeleportFlags.ViaLogin) == 0)
  363. {
  364. Util.FireAndForget(x =>
  365. {
  366. string r;
  367. m_SimulationService.CreateAgent(source, destination, aCircuit, teleportFlags, out r);
  368. m_log.DebugFormat("[AGENT HANDLER]: ASYNC CreateAgent {0}", r);
  369. });
  370. return true;
  371. }
  372. else
  373. {
  374. bool ret = m_SimulationService.CreateAgent(source, destination, aCircuit, teleportFlags, out reason);
  375. m_log.DebugFormat("[AGENT HANDLER]: SYNC CreateAgent {0} {1}", ret.ToString(), reason);
  376. return ret;
  377. }
  378. }
  379. }
  380. public class AgentPutHandler : BaseStreamHandler
  381. {
  382. private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
  383. private ISimulationService m_SimulationService;
  384. protected bool m_Proxy = false;
  385. public AgentPutHandler(ISimulationService service) :
  386. base("PUT", "/agent")
  387. {
  388. m_SimulationService = service;
  389. }
  390. public AgentPutHandler(string path) :
  391. base("PUT", path)
  392. {
  393. m_SimulationService = null;
  394. }
  395. protected override byte[] ProcessRequest(string path, Stream request,
  396. IOSHttpRequest httpRequest, IOSHttpResponse httpResponse)
  397. {
  398. // m_log.DebugFormat("[SIMULATION]: Stream handler called");
  399. Hashtable keysvals = new Hashtable();
  400. Hashtable headervals = new Hashtable();
  401. string[] querystringkeys = httpRequest.QueryString.AllKeys;
  402. string[] rHeaders = httpRequest.Headers.AllKeys;
  403. keysvals.Add("uri", httpRequest.RawUrl);
  404. keysvals.Add("content-type", httpRequest.ContentType);
  405. keysvals.Add("http-method", httpRequest.HttpMethod);
  406. foreach (string queryname in querystringkeys)
  407. keysvals.Add(queryname, httpRequest.QueryString[queryname]);
  408. foreach (string headername in rHeaders)
  409. headervals[headername] = httpRequest.Headers[headername];
  410. keysvals.Add("headers", headervals);
  411. keysvals.Add("querystringkeys", querystringkeys);
  412. String requestBody;
  413. Encoding encoding = Encoding.UTF8;
  414. Stream inputStream = request;
  415. Stream innerStream = null;
  416. try
  417. {
  418. if ((httpRequest.ContentType == "application/x-gzip" || httpRequest.Headers["Content-Encoding"] == "gzip") || (httpRequest.Headers["X-Content-Encoding"] == "gzip"))
  419. {
  420. innerStream = inputStream;
  421. inputStream = new GZipStream(innerStream, CompressionMode.Decompress);
  422. }
  423. using (StreamReader reader = new StreamReader(inputStream, encoding))
  424. {
  425. requestBody = reader.ReadToEnd();
  426. }
  427. }
  428. finally
  429. {
  430. if (innerStream != null)
  431. innerStream.Dispose();
  432. inputStream.Dispose();
  433. }
  434. keysvals.Add("body", requestBody);
  435. httpResponse.StatusCode = 200;
  436. httpResponse.ContentType = "text/html";
  437. httpResponse.KeepAlive = false;
  438. Hashtable responsedata = new Hashtable();
  439. UUID agentID;
  440. UUID regionID;
  441. string action;
  442. if (!Utils.GetParams((string)keysvals["uri"], out agentID, out regionID, out action))
  443. {
  444. m_log.InfoFormat("[AGENT HANDLER]: Invalid parameters for agent message {0}", keysvals["uri"]);
  445. httpResponse.StatusCode = 404;
  446. return encoding.GetBytes("false");
  447. }
  448. DoAgentPut(keysvals, responsedata);
  449. httpResponse.StatusCode = (int)responsedata["int_response_code"];
  450. return encoding.GetBytes((string)responsedata["str_response_string"]);
  451. }
  452. protected void DoAgentPut(Hashtable request, Hashtable responsedata)
  453. {
  454. OSDMap args = Utils.GetOSDMap((string)request["body"]);
  455. if (args == null)
  456. {
  457. responsedata["int_response_code"] = HttpStatusCode.BadRequest;
  458. responsedata["str_response_string"] = "Bad request";
  459. return;
  460. }
  461. // retrieve the input arguments
  462. int x = 0, y = 0;
  463. UUID uuid = UUID.Zero;
  464. string regionname = string.Empty;
  465. if (args.ContainsKey("destination_x") && args["destination_x"] != null)
  466. Int32.TryParse(args["destination_x"].AsString(), out x);
  467. if (args.ContainsKey("destination_y") && args["destination_y"] != null)
  468. Int32.TryParse(args["destination_y"].AsString(), out y);
  469. if (args.ContainsKey("destination_uuid") && args["destination_uuid"] != null)
  470. UUID.TryParse(args["destination_uuid"].AsString(), out uuid);
  471. if (args.ContainsKey("destination_name") && args["destination_name"] != null)
  472. regionname = args["destination_name"].ToString();
  473. GridRegion destination = new GridRegion();
  474. destination.RegionID = uuid;
  475. destination.RegionLocX = x;
  476. destination.RegionLocY = y;
  477. destination.RegionName = regionname;
  478. string messageType;
  479. if (args["message_type"] != null)
  480. messageType = args["message_type"].AsString();
  481. else
  482. {
  483. m_log.Warn("[AGENT HANDLER]: Agent Put Message Type not found. ");
  484. messageType = "AgentData";
  485. }
  486. bool result = true;
  487. if ("AgentData".Equals(messageType))
  488. {
  489. AgentData agent = new AgentData();
  490. try
  491. {
  492. agent.Unpack(args, m_SimulationService.GetScene(destination.RegionID));
  493. }
  494. catch (Exception ex)
  495. {
  496. m_log.InfoFormat("[AGENT HANDLER]: exception on unpacking ChildAgentUpdate message {0}", ex.Message);
  497. responsedata["int_response_code"] = HttpStatusCode.BadRequest;
  498. responsedata["str_response_string"] = "Bad request";
  499. return;
  500. }
  501. //agent.Dump();
  502. // This is one of the meanings of PUT agent
  503. result = UpdateAgent(destination, agent);
  504. }
  505. else if ("AgentPosition".Equals(messageType))
  506. {
  507. AgentPosition agent = new AgentPosition();
  508. try
  509. {
  510. agent.Unpack(args, m_SimulationService.GetScene(destination.RegionID));
  511. }
  512. catch (Exception ex)
  513. {
  514. m_log.InfoFormat("[AGENT HANDLER]: exception on unpacking ChildAgentUpdate message {0}", ex.Message);
  515. return;
  516. }
  517. //agent.Dump();
  518. // This is one of the meanings of PUT agent
  519. result = m_SimulationService.UpdateAgent(destination, agent);
  520. }
  521. responsedata["int_response_code"] = HttpStatusCode.OK;
  522. responsedata["str_response_string"] = result.ToString();
  523. //responsedata["str_response_string"] = OSDParser.SerializeJsonString(resp); ??? instead
  524. }
  525. // subclasses can override this
  526. protected virtual bool UpdateAgent(GridRegion destination, AgentData agent)
  527. {
  528. return m_SimulationService.UpdateAgent(destination, agent);
  529. }
  530. }
  531. public class AgentDestinationData
  532. {
  533. public int x;
  534. public int y;
  535. public string name;
  536. public UUID uuid;
  537. public uint flags;
  538. public bool fromLogin;
  539. }
  540. }