RegionClient.cs 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659
  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 OpenSim 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.Generic;
  29. using System.IO;
  30. using System.Net;
  31. using System.Reflection;
  32. using System.Text;
  33. using OpenMetaverse;
  34. using OpenMetaverse.StructuredData;
  35. using log4net;
  36. namespace OpenSim.Framework.Communications.Clients
  37. {
  38. public class RegionClient
  39. {
  40. private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
  41. public bool DoCreateChildAgentCall(RegionInfo region, AgentCircuitData aCircuit, string authKey, out string reason)
  42. {
  43. // Eventually, we want to use a caps url instead of the agentID
  44. string uri = "http://" + region.ExternalEndPoint.Address + ":" + region.HttpPort + "/agent/" + aCircuit.AgentID + "/";
  45. //Console.WriteLine(" >>> DoCreateChildAgentCall <<< " + uri);
  46. HttpWebRequest AgentCreateRequest = (HttpWebRequest)WebRequest.Create(uri);
  47. AgentCreateRequest.Method = "POST";
  48. AgentCreateRequest.ContentType = "application/json";
  49. AgentCreateRequest.Timeout = 10000;
  50. //AgentCreateRequest.KeepAlive = false;
  51. AgentCreateRequest.Headers.Add("Authorization", authKey);
  52. reason = String.Empty;
  53. // Fill it in
  54. OSDMap args = null;
  55. try
  56. {
  57. args = aCircuit.PackAgentCircuitData();
  58. }
  59. catch (Exception e)
  60. {
  61. m_log.Debug("[REST COMMS]: PackAgentCircuitData failed with exception: " + e.Message);
  62. }
  63. // Add the regionhandle of the destination region
  64. ulong regionHandle = GetRegionHandle(region.RegionHandle);
  65. args["destination_handle"] = OSD.FromString(regionHandle.ToString());
  66. string strBuffer = "";
  67. byte[] buffer = new byte[1];
  68. try
  69. {
  70. strBuffer = OSDParser.SerializeJsonString(args);
  71. UTF8Encoding str = new UTF8Encoding();
  72. buffer = str.GetBytes(strBuffer);
  73. }
  74. catch (Exception e)
  75. {
  76. m_log.WarnFormat("[REST COMMS]: Exception thrown on serialization of ChildCreate: {0}", e.Message);
  77. // ignore. buffer will be empty, caller should check.
  78. }
  79. Stream os = null;
  80. try
  81. { // send the Post
  82. AgentCreateRequest.ContentLength = buffer.Length; //Count bytes to send
  83. os = AgentCreateRequest.GetRequestStream();
  84. os.Write(buffer, 0, strBuffer.Length); //Send it
  85. os.Close();
  86. //m_log.InfoFormat("[REST COMMS]: Posted CreateChildAgent request to remote sim {0}", uri);
  87. }
  88. //catch (WebException ex)
  89. catch
  90. {
  91. //m_log.InfoFormat("[REST COMMS]: Bad send on ChildAgentUpdate {0}", ex.Message);
  92. reason = "cannot contact remote region";
  93. return false;
  94. }
  95. // Let's wait for the response
  96. //m_log.Info("[REST COMMS]: Waiting for a reply after DoCreateChildAgentCall");
  97. try
  98. {
  99. WebResponse webResponse = AgentCreateRequest.GetResponse();
  100. if (webResponse == null)
  101. {
  102. m_log.Info("[REST COMMS]: Null reply on DoCreateChildAgentCall post");
  103. }
  104. else
  105. {
  106. StreamReader sr = new StreamReader(webResponse.GetResponseStream());
  107. string response = sr.ReadToEnd().Trim();
  108. sr.Close();
  109. m_log.InfoFormat("[REST COMMS]: DoCreateChildAgentCall reply was {0} ", response);
  110. if (!String.IsNullOrEmpty(response))
  111. {
  112. try
  113. {
  114. // we assume we got an OSDMap back
  115. OSDMap r = GetOSDMap(response);
  116. bool success = r["success"].AsBoolean();
  117. reason = r["reason"].AsString();
  118. return success;
  119. }
  120. catch (NullReferenceException e)
  121. {
  122. m_log.InfoFormat("[REST COMMS]: exception on reply of DoCreateChildAgentCall {0}", e.Message);
  123. // check for old style response
  124. if (response.ToLower().StartsWith("true"))
  125. return true;
  126. return false;
  127. }
  128. }
  129. }
  130. }
  131. catch (WebException ex)
  132. {
  133. m_log.InfoFormat("[REST COMMS]: exception on reply of DoCreateChildAgentCall {0}", ex.Message);
  134. // ignore, really
  135. }
  136. return true;
  137. }
  138. public bool DoChildAgentUpdateCall(RegionInfo region, IAgentData cAgentData)
  139. {
  140. // Eventually, we want to use a caps url instead of the agentID
  141. string uri = "http://" + region.ExternalEndPoint.Address + ":" + region.HttpPort + "/agent/" + cAgentData.AgentID + "/";
  142. //Console.WriteLine(" >>> DoChildAgentUpdateCall <<< " + uri);
  143. HttpWebRequest ChildUpdateRequest = (HttpWebRequest)WebRequest.Create(uri);
  144. ChildUpdateRequest.Method = "PUT";
  145. ChildUpdateRequest.ContentType = "application/json";
  146. ChildUpdateRequest.Timeout = 10000;
  147. //ChildUpdateRequest.KeepAlive = false;
  148. // Fill it in
  149. OSDMap args = null;
  150. try
  151. {
  152. args = cAgentData.Pack();
  153. }
  154. catch (Exception e)
  155. {
  156. m_log.Debug("[REST COMMS]: PackUpdateMessage failed with exception: " + e.Message);
  157. }
  158. // Add the regionhandle of the destination region
  159. ulong regionHandle = GetRegionHandle(region.RegionHandle);
  160. args["destination_handle"] = OSD.FromString(regionHandle.ToString());
  161. string strBuffer = "";
  162. byte[] buffer = new byte[1];
  163. try
  164. {
  165. strBuffer = OSDParser.SerializeJsonString(args);
  166. UTF8Encoding str = new UTF8Encoding();
  167. buffer = str.GetBytes(strBuffer);
  168. }
  169. catch (Exception e)
  170. {
  171. m_log.WarnFormat("[REST COMMS]: Exception thrown on serialization of ChildUpdate: {0}", e.Message);
  172. // ignore. buffer will be empty, caller should check.
  173. }
  174. Stream os = null;
  175. try
  176. { // send the Post
  177. ChildUpdateRequest.ContentLength = buffer.Length; //Count bytes to send
  178. os = ChildUpdateRequest.GetRequestStream();
  179. os.Write(buffer, 0, strBuffer.Length); //Send it
  180. os.Close();
  181. //m_log.InfoFormat("[REST COMMS]: Posted ChildAgentUpdate request to remote sim {0}", uri);
  182. }
  183. //catch (WebException ex)
  184. catch
  185. {
  186. //m_log.InfoFormat("[REST COMMS]: Bad send on ChildAgentUpdate {0}", ex.Message);
  187. return false;
  188. }
  189. // Let's wait for the response
  190. //m_log.Info("[REST COMMS]: Waiting for a reply after ChildAgentUpdate");
  191. try
  192. {
  193. WebResponse webResponse = ChildUpdateRequest.GetResponse();
  194. if (webResponse == null)
  195. {
  196. m_log.Info("[REST COMMS]: Null reply on ChilAgentUpdate post");
  197. }
  198. StreamReader sr = new StreamReader(webResponse.GetResponseStream());
  199. //reply = sr.ReadToEnd().Trim();
  200. sr.ReadToEnd().Trim();
  201. sr.Close();
  202. //m_log.InfoFormat("[REST COMMS]: ChilAgentUpdate reply was {0} ", reply);
  203. }
  204. catch (WebException ex)
  205. {
  206. m_log.InfoFormat("[REST COMMS]: exception on reply of ChilAgentUpdate {0}", ex.Message);
  207. // ignore, really
  208. }
  209. return true;
  210. }
  211. public bool DoRetrieveRootAgentCall(RegionInfo region, UUID id, out IAgentData agent)
  212. {
  213. agent = null;
  214. // Eventually, we want to use a caps url instead of the agentID
  215. string uri = "http://" + region.ExternalEndPoint.Address + ":" + region.HttpPort + "/agent/" + id + "/" + region.RegionHandle.ToString() + "/";
  216. //Console.WriteLine(" >>> DoRetrieveRootAgentCall <<< " + uri);
  217. HttpWebRequest request = (HttpWebRequest)WebRequest.Create(uri);
  218. request.Method = "GET";
  219. request.Timeout = 10000;
  220. //request.Headers.Add("authorization", ""); // coming soon
  221. HttpWebResponse webResponse = null;
  222. string reply = string.Empty;
  223. try
  224. {
  225. webResponse = (HttpWebResponse)request.GetResponse();
  226. if (webResponse == null)
  227. {
  228. m_log.Info("[REST COMMS]: Null reply on agent get ");
  229. }
  230. StreamReader sr = new StreamReader(webResponse.GetResponseStream());
  231. reply = sr.ReadToEnd().Trim();
  232. sr.Close();
  233. //Console.WriteLine("[REST COMMS]: ChilAgentUpdate reply was " + reply);
  234. }
  235. catch (WebException ex)
  236. {
  237. m_log.InfoFormat("[REST COMMS]: exception on reply of agent get {0}", ex.Message);
  238. // ignore, really
  239. return false;
  240. }
  241. if (webResponse.StatusCode == HttpStatusCode.OK)
  242. {
  243. // we know it's jason
  244. OSDMap args = GetOSDMap(reply);
  245. if (args == null)
  246. {
  247. //Console.WriteLine("[REST COMMS]: Error getting OSDMap from reply");
  248. return false;
  249. }
  250. agent = new CompleteAgentData();
  251. agent.Unpack(args);
  252. return true;
  253. }
  254. //Console.WriteLine("[REST COMMS]: DoRetrieveRootAgentCall returned status " + webResponse.StatusCode);
  255. return false;
  256. }
  257. public bool DoReleaseAgentCall(ulong regionHandle, UUID id, string uri)
  258. {
  259. //m_log.Debug(" >>> DoReleaseAgentCall <<< " + uri);
  260. WebRequest request = WebRequest.Create(uri);
  261. request.Method = "DELETE";
  262. request.Timeout = 10000;
  263. try
  264. {
  265. WebResponse webResponse = request.GetResponse();
  266. if (webResponse == null)
  267. {
  268. m_log.Info("[REST COMMS]: Null reply on agent delete ");
  269. }
  270. StreamReader sr = new StreamReader(webResponse.GetResponseStream());
  271. //reply = sr.ReadToEnd().Trim();
  272. sr.ReadToEnd().Trim();
  273. sr.Close();
  274. //m_log.InfoFormat("[REST COMMS]: ChilAgentUpdate reply was {0} ", reply);
  275. }
  276. catch (WebException ex)
  277. {
  278. m_log.InfoFormat("[REST COMMS]: exception on reply of agent delete {0}", ex.Message);
  279. // ignore, really
  280. }
  281. return true;
  282. }
  283. public bool DoCloseAgentCall(RegionInfo region, UUID id)
  284. {
  285. string uri = "http://" + region.ExternalEndPoint.Address + ":" + region.HttpPort + "/agent/" + id + "/" + region.RegionHandle.ToString() + "/";
  286. //Console.WriteLine(" >>> DoCloseAgentCall <<< " + uri);
  287. WebRequest request = WebRequest.Create(uri);
  288. request.Method = "DELETE";
  289. request.Timeout = 10000;
  290. try
  291. {
  292. WebResponse webResponse = request.GetResponse();
  293. if (webResponse == null)
  294. {
  295. m_log.Info("[REST COMMS]: Null reply on agent delete ");
  296. }
  297. StreamReader sr = new StreamReader(webResponse.GetResponseStream());
  298. //reply = sr.ReadToEnd().Trim();
  299. sr.ReadToEnd().Trim();
  300. sr.Close();
  301. //m_log.InfoFormat("[REST COMMS]: ChilAgentUpdate reply was {0} ", reply);
  302. }
  303. catch (WebException ex)
  304. {
  305. m_log.InfoFormat("[REST COMMS]: exception on reply of agent delete {0}", ex.Message);
  306. // ignore, really
  307. }
  308. return true;
  309. }
  310. public bool DoCreateObjectCall(RegionInfo region, ISceneObject sog, string sogXml2, bool allowScriptCrossing)
  311. {
  312. ulong regionHandle = GetRegionHandle(region.RegionHandle);
  313. string uri
  314. = "http://" + region.ExternalEndPoint.Address + ":" + region.HttpPort
  315. + "/object/" + sog.UUID + "/" + regionHandle.ToString() + "/";
  316. //m_log.Debug(" >>> DoCreateChildAgentCall <<< " + uri);
  317. WebRequest ObjectCreateRequest = WebRequest.Create(uri);
  318. ObjectCreateRequest.Method = "POST";
  319. ObjectCreateRequest.ContentType = "application/json";
  320. ObjectCreateRequest.Timeout = 10000;
  321. OSDMap args = new OSDMap(2);
  322. args["sog"] = OSD.FromString(sogXml2);
  323. args["extra"] = OSD.FromString(sog.ExtraToXmlString());
  324. if (allowScriptCrossing)
  325. {
  326. string state = sog.GetStateSnapshot();
  327. if (state.Length > 0)
  328. args["state"] = OSD.FromString(state);
  329. }
  330. string strBuffer = "";
  331. byte[] buffer = new byte[1];
  332. try
  333. {
  334. strBuffer = OSDParser.SerializeJsonString(args);
  335. UTF8Encoding str = new UTF8Encoding();
  336. buffer = str.GetBytes(strBuffer);
  337. }
  338. catch (Exception e)
  339. {
  340. m_log.WarnFormat("[REST COMMS]: Exception thrown on serialization of CreateObject: {0}", e.Message);
  341. // ignore. buffer will be empty, caller should check.
  342. }
  343. Stream os = null;
  344. try
  345. { // send the Post
  346. ObjectCreateRequest.ContentLength = buffer.Length; //Count bytes to send
  347. os = ObjectCreateRequest.GetRequestStream();
  348. os.Write(buffer, 0, strBuffer.Length); //Send it
  349. os.Close();
  350. m_log.InfoFormat("[REST COMMS]: Posted ChildAgentUpdate request to remote sim {0}", uri);
  351. }
  352. //catch (WebException ex)
  353. catch
  354. {
  355. // m_log.InfoFormat("[REST COMMS]: Bad send on CreateObject {0}", ex.Message);
  356. return false;
  357. }
  358. // Let's wait for the response
  359. //m_log.Info("[REST COMMS]: Waiting for a reply after DoCreateChildAgentCall");
  360. try
  361. {
  362. WebResponse webResponse = ObjectCreateRequest.GetResponse();
  363. if (webResponse == null)
  364. {
  365. m_log.Info("[REST COMMS]: Null reply on DoCreateObjectCall post");
  366. }
  367. StreamReader sr = new StreamReader(webResponse.GetResponseStream());
  368. //reply = sr.ReadToEnd().Trim();
  369. sr.ReadToEnd().Trim();
  370. sr.Close();
  371. //m_log.InfoFormat("[REST COMMS]: DoCreateChildAgentCall reply was {0} ", reply);
  372. }
  373. catch (WebException ex)
  374. {
  375. m_log.InfoFormat("[REST COMMS]: exception on reply of DoCreateObjectCall {0}", ex.Message);
  376. // ignore, really
  377. }
  378. return true;
  379. }
  380. public bool DoCreateObjectCall(RegionInfo region, UUID userID, UUID itemID)
  381. {
  382. ulong regionHandle = GetRegionHandle(region.RegionHandle);
  383. string uri = "http://" + region.ExternalEndPoint.Address + ":" + region.HttpPort + "/object/" + UUID.Zero + "/" + regionHandle.ToString() + "/";
  384. //m_log.Debug(" >>> DoCreateChildAgentCall <<< " + uri);
  385. WebRequest ObjectCreateRequest = WebRequest.Create(uri);
  386. ObjectCreateRequest.Method = "PUT";
  387. ObjectCreateRequest.ContentType = "application/json";
  388. ObjectCreateRequest.Timeout = 10000;
  389. OSDMap args = new OSDMap(2);
  390. args["userid"] = OSD.FromUUID(userID);
  391. args["itemid"] = OSD.FromUUID(itemID);
  392. string strBuffer = "";
  393. byte[] buffer = new byte[1];
  394. try
  395. {
  396. strBuffer = OSDParser.SerializeJsonString(args);
  397. UTF8Encoding str = new UTF8Encoding();
  398. buffer = str.GetBytes(strBuffer);
  399. }
  400. catch (Exception e)
  401. {
  402. m_log.WarnFormat("[REST COMMS]: Exception thrown on serialization of CreateObject: {0}", e.Message);
  403. // ignore. buffer will be empty, caller should check.
  404. }
  405. Stream os = null;
  406. try
  407. { // send the Post
  408. ObjectCreateRequest.ContentLength = buffer.Length; //Count bytes to send
  409. os = ObjectCreateRequest.GetRequestStream();
  410. os.Write(buffer, 0, strBuffer.Length); //Send it
  411. os.Close();
  412. //m_log.InfoFormat("[REST COMMS]: Posted CreateObject request to remote sim {0}", uri);
  413. }
  414. //catch (WebException ex)
  415. catch
  416. {
  417. // m_log.InfoFormat("[REST COMMS]: Bad send on CreateObject {0}", ex.Message);
  418. return false;
  419. }
  420. // Let's wait for the response
  421. //m_log.Info("[REST COMMS]: Waiting for a reply after DoCreateChildAgentCall");
  422. try
  423. {
  424. WebResponse webResponse = ObjectCreateRequest.GetResponse();
  425. if (webResponse == null)
  426. {
  427. m_log.Info("[REST COMMS]: Null reply on DoCreateObjectCall post");
  428. }
  429. StreamReader sr = new StreamReader(webResponse.GetResponseStream());
  430. sr.ReadToEnd().Trim();
  431. sr.ReadToEnd().Trim();
  432. sr.Close();
  433. //m_log.InfoFormat("[REST COMMS]: DoCreateChildAgentCall reply was {0} ", reply);
  434. }
  435. catch (WebException ex)
  436. {
  437. m_log.InfoFormat("[REST COMMS]: exception on reply of DoCreateObjectCall {0}", ex.Message);
  438. // ignore, really
  439. }
  440. return true;
  441. }
  442. public bool DoHelloNeighbourCall(RegionInfo region, RegionInfo thisRegion)
  443. {
  444. string uri = "http://" + region.ExternalEndPoint.Address + ":" + region.HttpPort + "/region/" + thisRegion.RegionID + "/";
  445. //m_log.Debug(" >>> DoHelloNeighbourCall <<< " + uri);
  446. WebRequest HelloNeighbourRequest = WebRequest.Create(uri);
  447. HelloNeighbourRequest.Method = "POST";
  448. HelloNeighbourRequest.ContentType = "application/json";
  449. HelloNeighbourRequest.Timeout = 10000;
  450. // Fill it in
  451. OSDMap args = null;
  452. try
  453. {
  454. args = thisRegion.PackRegionInfoData();
  455. }
  456. catch (Exception e)
  457. {
  458. m_log.Debug("[REST COMMS]: PackRegionInfoData failed with exception: " + e.Message);
  459. }
  460. // Add the regionhandle of the destination region
  461. ulong regionHandle = GetRegionHandle(region.RegionHandle);
  462. args["destination_handle"] = OSD.FromString(regionHandle.ToString());
  463. string strBuffer = "";
  464. byte[] buffer = new byte[1];
  465. try
  466. {
  467. strBuffer = OSDParser.SerializeJsonString(args);
  468. UTF8Encoding str = new UTF8Encoding();
  469. buffer = str.GetBytes(strBuffer);
  470. }
  471. catch (Exception e)
  472. {
  473. m_log.WarnFormat("[REST COMMS]: Exception thrown on serialization of HelloNeighbour: {0}", e.Message);
  474. // ignore. buffer will be empty, caller should check.
  475. }
  476. Stream os = null;
  477. try
  478. { // send the Post
  479. HelloNeighbourRequest.ContentLength = buffer.Length; //Count bytes to send
  480. os = HelloNeighbourRequest.GetRequestStream();
  481. os.Write(buffer, 0, strBuffer.Length); //Send it
  482. os.Close();
  483. //m_log.InfoFormat("[REST COMMS]: Posted HelloNeighbour request to remote sim {0}", uri);
  484. }
  485. //catch (WebException ex)
  486. catch
  487. {
  488. //m_log.InfoFormat("[REST COMMS]: Bad send on HelloNeighbour {0}", ex.Message);
  489. return false;
  490. }
  491. // Let's wait for the response
  492. //m_log.Info("[REST COMMS]: Waiting for a reply after DoHelloNeighbourCall");
  493. try
  494. {
  495. WebResponse webResponse = HelloNeighbourRequest.GetResponse();
  496. if (webResponse == null)
  497. {
  498. m_log.Info("[REST COMMS]: Null reply on DoHelloNeighbourCall post");
  499. }
  500. StreamReader sr = new StreamReader(webResponse.GetResponseStream());
  501. //reply = sr.ReadToEnd().Trim();
  502. sr.ReadToEnd().Trim();
  503. sr.Close();
  504. //m_log.InfoFormat("[REST COMMS]: DoHelloNeighbourCall reply was {0} ", reply);
  505. }
  506. catch (WebException ex)
  507. {
  508. m_log.InfoFormat("[REST COMMS]: exception on reply of DoHelloNeighbourCall {0}", ex.Message);
  509. // ignore, really
  510. }
  511. return true;
  512. }
  513. #region Hyperlinks
  514. public virtual ulong GetRegionHandle(ulong handle)
  515. {
  516. return handle;
  517. }
  518. public virtual bool IsHyperlink(ulong handle)
  519. {
  520. return false;
  521. }
  522. public virtual void SendUserInformation(RegionInfo regInfo, AgentCircuitData aCircuit)
  523. {
  524. }
  525. public virtual void AdjustUserInformation(AgentCircuitData aCircuit)
  526. {
  527. }
  528. #endregion /* Hyperlinks */
  529. public static OSDMap GetOSDMap(string data)
  530. {
  531. OSDMap args = null;
  532. try
  533. {
  534. OSD buffer;
  535. // We should pay attention to the content-type, but let's assume we know it's Json
  536. buffer = OSDParser.DeserializeJson(data);
  537. if (buffer.Type == OSDType.Map)
  538. {
  539. args = (OSDMap)buffer;
  540. return args;
  541. }
  542. else
  543. {
  544. // uh?
  545. System.Console.WriteLine("[REST COMMS]: Got OSD of type " + buffer.Type.ToString());
  546. return null;
  547. }
  548. }
  549. catch (Exception ex)
  550. {
  551. System.Console.WriteLine("[REST COMMS]: exception on parse of REST message " + ex.Message);
  552. return null;
  553. }
  554. }
  555. }
  556. }