RegionClient.cs 26 KB

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