UserAgentServiceConnector.cs 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856
  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.IO;
  31. using System.Net;
  32. using System.Reflection;
  33. using System.Text;
  34. using OpenSim.Framework;
  35. using OpenSim.Services.Interfaces;
  36. using OpenSim.Services.Connectors.Simulation;
  37. using GridRegion = OpenSim.Services.Interfaces.GridRegion;
  38. using OpenMetaverse;
  39. using OpenMetaverse.StructuredData;
  40. using log4net;
  41. using Nwc.XmlRpc;
  42. using Nini.Config;
  43. namespace OpenSim.Services.Connectors.Hypergrid
  44. {
  45. public class UserAgentServiceConnector : IUserAgentService
  46. {
  47. private static readonly ILog m_log =
  48. LogManager.GetLogger(
  49. MethodBase.GetCurrentMethod().DeclaringType);
  50. string m_ServerURL;
  51. public UserAgentServiceConnector(string url) : this(url, true)
  52. {
  53. }
  54. public UserAgentServiceConnector(string url, bool dnsLookup)
  55. {
  56. m_ServerURL = url;
  57. if (dnsLookup)
  58. {
  59. // Doing this here, because XML-RPC or mono have some strong ideas about
  60. // caching DNS translations.
  61. try
  62. {
  63. Uri m_Uri = new Uri(m_ServerURL);
  64. IPAddress ip = Util.GetHostFromDNS(m_Uri.Host);
  65. m_ServerURL = m_ServerURL.Replace(m_Uri.Host, ip.ToString());
  66. if (!m_ServerURL.EndsWith("/"))
  67. m_ServerURL += "/";
  68. }
  69. catch (Exception e)
  70. {
  71. m_log.DebugFormat("[USER AGENT CONNECTOR]: Malformed Uri {0}: {1}", m_ServerURL, e.Message);
  72. }
  73. }
  74. m_log.DebugFormat("[USER AGENT CONNECTOR]: new connector to {0} ({1})", url, m_ServerURL);
  75. }
  76. public UserAgentServiceConnector(IConfigSource config)
  77. {
  78. IConfig serviceConfig = config.Configs["UserAgentService"];
  79. if (serviceConfig == null)
  80. {
  81. m_log.Error("[USER AGENT CONNECTOR]: UserAgentService missing from ini");
  82. throw new Exception("UserAgent connector init error");
  83. }
  84. string serviceURI = serviceConfig.GetString("UserAgentServerURI",
  85. String.Empty);
  86. if (serviceURI == String.Empty)
  87. {
  88. m_log.Error("[USER AGENT CONNECTOR]: No Server URI named in section UserAgentService");
  89. throw new Exception("UserAgent connector init error");
  90. }
  91. m_ServerURL = serviceURI;
  92. if (!m_ServerURL.EndsWith("/"))
  93. m_ServerURL += "/";
  94. m_log.DebugFormat("[USER AGENT CONNECTOR]: UserAgentServiceConnector started for {0}", m_ServerURL);
  95. }
  96. // The Login service calls this interface with a non-null [client] ipaddress
  97. public bool LoginAgentToGrid(AgentCircuitData aCircuit, GridRegion gatekeeper, GridRegion destination, IPEndPoint ipaddress, out string reason)
  98. {
  99. reason = String.Empty;
  100. if (destination == null)
  101. {
  102. reason = "Destination is null";
  103. m_log.Debug("[USER AGENT CONNECTOR]: Given destination is null");
  104. return false;
  105. }
  106. string uri = m_ServerURL + "homeagent/" + aCircuit.AgentID + "/";
  107. Console.WriteLine(" >>> LoginAgentToGrid <<< " + uri);
  108. HttpWebRequest AgentCreateRequest = (HttpWebRequest)WebRequest.Create(uri);
  109. AgentCreateRequest.Method = "POST";
  110. AgentCreateRequest.ContentType = "application/json";
  111. AgentCreateRequest.Timeout = 10000;
  112. //AgentCreateRequest.KeepAlive = false;
  113. //AgentCreateRequest.Headers.Add("Authorization", authKey);
  114. // Fill it in
  115. OSDMap args = PackCreateAgentArguments(aCircuit, gatekeeper, destination, ipaddress);
  116. string strBuffer = "";
  117. byte[] buffer = new byte[1];
  118. try
  119. {
  120. strBuffer = OSDParser.SerializeJsonString(args);
  121. Encoding str = Util.UTF8;
  122. buffer = str.GetBytes(strBuffer);
  123. }
  124. catch (Exception e)
  125. {
  126. m_log.WarnFormat("[USER AGENT CONNECTOR]: Exception thrown on serialization of ChildCreate: {0}", e.Message);
  127. // ignore. buffer will be empty, caller should check.
  128. }
  129. Stream os = null;
  130. try
  131. { // send the Post
  132. AgentCreateRequest.ContentLength = buffer.Length; //Count bytes to send
  133. os = AgentCreateRequest.GetRequestStream();
  134. os.Write(buffer, 0, strBuffer.Length); //Send it
  135. m_log.InfoFormat("[USER AGENT CONNECTOR]: Posted CreateAgent request to remote sim {0}, region {1}, x={2} y={3}",
  136. uri, destination.RegionName, destination.RegionLocX, destination.RegionLocY);
  137. }
  138. //catch (WebException ex)
  139. catch
  140. {
  141. //m_log.InfoFormat("[USER AGENT CONNECTOR]: Bad send on ChildAgentUpdate {0}", ex.Message);
  142. reason = "cannot contact remote region";
  143. return false;
  144. }
  145. finally
  146. {
  147. if (os != null)
  148. os.Close();
  149. }
  150. // Let's wait for the response
  151. //m_log.Info("[USER AGENT CONNECTOR]: Waiting for a reply after DoCreateChildAgentCall");
  152. WebResponse webResponse = null;
  153. StreamReader sr = null;
  154. try
  155. {
  156. webResponse = AgentCreateRequest.GetResponse();
  157. if (webResponse == null)
  158. {
  159. m_log.Info("[USER AGENT CONNECTOR]: Null reply on DoCreateChildAgentCall post");
  160. }
  161. else
  162. {
  163. sr = new StreamReader(webResponse.GetResponseStream());
  164. string response = sr.ReadToEnd().Trim();
  165. m_log.InfoFormat("[USER AGENT CONNECTOR]: DoCreateChildAgentCall reply was {0} ", response);
  166. if (!String.IsNullOrEmpty(response))
  167. {
  168. try
  169. {
  170. // we assume we got an OSDMap back
  171. OSDMap r = Util.GetOSDMap(response);
  172. bool success = r["success"].AsBoolean();
  173. reason = r["reason"].AsString();
  174. return success;
  175. }
  176. catch (NullReferenceException e)
  177. {
  178. m_log.InfoFormat("[USER AGENT CONNECTOR]: exception on reply of DoCreateChildAgentCall {0}", e.Message);
  179. // check for old style response
  180. if (response.ToLower().StartsWith("true"))
  181. return true;
  182. return false;
  183. }
  184. }
  185. }
  186. }
  187. catch (WebException ex)
  188. {
  189. m_log.InfoFormat("[USER AGENT CONNECTOR]: exception on reply of DoCreateChildAgentCall {0}", ex.Message);
  190. reason = "Destination did not reply";
  191. return false;
  192. }
  193. finally
  194. {
  195. if (sr != null)
  196. sr.Close();
  197. }
  198. return true;
  199. }
  200. // The simulators call this interface
  201. public bool LoginAgentToGrid(AgentCircuitData aCircuit, GridRegion gatekeeper, GridRegion destination, out string reason)
  202. {
  203. return LoginAgentToGrid(aCircuit, gatekeeper, destination, null, out reason);
  204. }
  205. protected OSDMap PackCreateAgentArguments(AgentCircuitData aCircuit, GridRegion gatekeeper, GridRegion destination, IPEndPoint ipaddress)
  206. {
  207. OSDMap args = null;
  208. try
  209. {
  210. args = aCircuit.PackAgentCircuitData();
  211. }
  212. catch (Exception e)
  213. {
  214. m_log.Debug("[USER AGENT CONNECTOR]: PackAgentCircuitData failed with exception: " + e.Message);
  215. }
  216. // Add the input arguments
  217. args["gatekeeper_serveruri"] = OSD.FromString(gatekeeper.ServerURI);
  218. args["gatekeeper_host"] = OSD.FromString(gatekeeper.ExternalHostName);
  219. args["gatekeeper_port"] = OSD.FromString(gatekeeper.HttpPort.ToString());
  220. args["destination_x"] = OSD.FromString(destination.RegionLocX.ToString());
  221. args["destination_y"] = OSD.FromString(destination.RegionLocY.ToString());
  222. args["destination_name"] = OSD.FromString(destination.RegionName);
  223. args["destination_uuid"] = OSD.FromString(destination.RegionID.ToString());
  224. args["destination_serveruri"] = OSD.FromString(destination.ServerURI);
  225. // 10/3/2010
  226. // I added the client_ip up to the regular AgentCircuitData, so this doesn't need to be here.
  227. // This need cleaning elsewhere...
  228. //if (ipaddress != null)
  229. // args["client_ip"] = OSD.FromString(ipaddress.Address.ToString());
  230. return args;
  231. }
  232. public void SetClientToken(UUID sessionID, string token)
  233. {
  234. // no-op
  235. }
  236. public GridRegion GetHomeRegion(UUID userID, out Vector3 position, out Vector3 lookAt)
  237. {
  238. position = Vector3.UnitY; lookAt = Vector3.UnitY;
  239. Hashtable hash = new Hashtable();
  240. hash["userID"] = userID.ToString();
  241. IList paramList = new ArrayList();
  242. paramList.Add(hash);
  243. XmlRpcRequest request = new XmlRpcRequest("get_home_region", paramList);
  244. XmlRpcResponse response = null;
  245. try
  246. {
  247. response = request.Send(m_ServerURL, 10000);
  248. }
  249. catch (Exception)
  250. {
  251. return null;
  252. }
  253. if (response.IsFault)
  254. {
  255. return null;
  256. }
  257. hash = (Hashtable)response.Value;
  258. //foreach (Object o in hash)
  259. // m_log.Debug(">> " + ((DictionaryEntry)o).Key + ":" + ((DictionaryEntry)o).Value);
  260. try
  261. {
  262. bool success = false;
  263. Boolean.TryParse((string)hash["result"], out success);
  264. if (success)
  265. {
  266. GridRegion region = new GridRegion();
  267. UUID.TryParse((string)hash["uuid"], out region.RegionID);
  268. //m_log.Debug(">> HERE, uuid: " + region.RegionID);
  269. int n = 0;
  270. if (hash["x"] != null)
  271. {
  272. Int32.TryParse((string)hash["x"], out n);
  273. region.RegionLocX = n;
  274. //m_log.Debug(">> HERE, x: " + region.RegionLocX);
  275. }
  276. if (hash["y"] != null)
  277. {
  278. Int32.TryParse((string)hash["y"], out n);
  279. region.RegionLocY = n;
  280. //m_log.Debug(">> HERE, y: " + region.RegionLocY);
  281. }
  282. if (hash["region_name"] != null)
  283. {
  284. region.RegionName = (string)hash["region_name"];
  285. //m_log.Debug(">> HERE, name: " + region.RegionName);
  286. }
  287. if (hash["hostname"] != null)
  288. region.ExternalHostName = (string)hash["hostname"];
  289. if (hash["http_port"] != null)
  290. {
  291. uint p = 0;
  292. UInt32.TryParse((string)hash["http_port"], out p);
  293. region.HttpPort = p;
  294. }
  295. if (hash.ContainsKey("server_uri") && hash["server_uri"] != null)
  296. region.ServerURI = (string)hash["server_uri"];
  297. if (hash["internal_port"] != null)
  298. {
  299. int p = 0;
  300. Int32.TryParse((string)hash["internal_port"], out p);
  301. region.InternalEndPoint = new IPEndPoint(IPAddress.Parse("0.0.0.0"), p);
  302. }
  303. if (hash["position"] != null)
  304. Vector3.TryParse((string)hash["position"], out position);
  305. if (hash["lookAt"] != null)
  306. Vector3.TryParse((string)hash["lookAt"], out lookAt);
  307. // Successful return
  308. return region;
  309. }
  310. }
  311. catch (Exception)
  312. {
  313. return null;
  314. }
  315. return null;
  316. }
  317. public bool IsAgentComingHome(UUID sessionID, string thisGridExternalName)
  318. {
  319. Hashtable hash = new Hashtable();
  320. hash["sessionID"] = sessionID.ToString();
  321. hash["externalName"] = thisGridExternalName;
  322. IList paramList = new ArrayList();
  323. paramList.Add(hash);
  324. XmlRpcRequest request = new XmlRpcRequest("agent_is_coming_home", paramList);
  325. string reason = string.Empty;
  326. return GetBoolResponse(request, out reason);
  327. }
  328. public bool VerifyAgent(UUID sessionID, string token)
  329. {
  330. Hashtable hash = new Hashtable();
  331. hash["sessionID"] = sessionID.ToString();
  332. hash["token"] = token;
  333. IList paramList = new ArrayList();
  334. paramList.Add(hash);
  335. XmlRpcRequest request = new XmlRpcRequest("verify_agent", paramList);
  336. string reason = string.Empty;
  337. return GetBoolResponse(request, out reason);
  338. }
  339. public bool VerifyClient(UUID sessionID, string token)
  340. {
  341. Hashtable hash = new Hashtable();
  342. hash["sessionID"] = sessionID.ToString();
  343. hash["token"] = token;
  344. IList paramList = new ArrayList();
  345. paramList.Add(hash);
  346. XmlRpcRequest request = new XmlRpcRequest("verify_client", paramList);
  347. string reason = string.Empty;
  348. return GetBoolResponse(request, out reason);
  349. }
  350. public void LogoutAgent(UUID userID, UUID sessionID)
  351. {
  352. Hashtable hash = new Hashtable();
  353. hash["sessionID"] = sessionID.ToString();
  354. hash["userID"] = userID.ToString();
  355. IList paramList = new ArrayList();
  356. paramList.Add(hash);
  357. XmlRpcRequest request = new XmlRpcRequest("logout_agent", paramList);
  358. string reason = string.Empty;
  359. GetBoolResponse(request, out reason);
  360. }
  361. public List<UUID> StatusNotification(List<string> friends, UUID userID, bool online)
  362. {
  363. Hashtable hash = new Hashtable();
  364. hash["userID"] = userID.ToString();
  365. hash["online"] = online.ToString();
  366. int i = 0;
  367. foreach (string s in friends)
  368. {
  369. hash["friend_" + i.ToString()] = s;
  370. i++;
  371. }
  372. IList paramList = new ArrayList();
  373. paramList.Add(hash);
  374. XmlRpcRequest request = new XmlRpcRequest("status_notification", paramList);
  375. // string reason = string.Empty;
  376. // Send and get reply
  377. List<UUID> friendsOnline = new List<UUID>();
  378. XmlRpcResponse response = null;
  379. try
  380. {
  381. response = request.Send(m_ServerURL, 6000);
  382. }
  383. catch
  384. {
  385. m_log.DebugFormat("[USER AGENT CONNECTOR]: Unable to contact remote server {0} for StatusNotification", m_ServerURL);
  386. // reason = "Exception: " + e.Message;
  387. return friendsOnline;
  388. }
  389. if (response.IsFault)
  390. {
  391. m_log.ErrorFormat("[USER AGENT CONNECTOR]: remote call to {0} for StatusNotification returned an error: {1}", m_ServerURL, response.FaultString);
  392. // reason = "XMLRPC Fault";
  393. return friendsOnline;
  394. }
  395. hash = (Hashtable)response.Value;
  396. //foreach (Object o in hash)
  397. // m_log.Debug(">> " + ((DictionaryEntry)o).Key + ":" + ((DictionaryEntry)o).Value);
  398. try
  399. {
  400. if (hash == null)
  401. {
  402. m_log.ErrorFormat("[USER AGENT CONNECTOR]: GetOnlineFriends Got null response from {0}! THIS IS BAAAAD", m_ServerURL);
  403. // reason = "Internal error 1";
  404. return friendsOnline;
  405. }
  406. // Here is the actual response
  407. foreach (object key in hash.Keys)
  408. {
  409. if (key is string && ((string)key).StartsWith("friend_") && hash[key] != null)
  410. {
  411. UUID uuid;
  412. if (UUID.TryParse(hash[key].ToString(), out uuid))
  413. friendsOnline.Add(uuid);
  414. }
  415. }
  416. }
  417. catch
  418. {
  419. m_log.ErrorFormat("[USER AGENT CONNECTOR]: Got exception on GetOnlineFriends response.");
  420. // reason = "Exception: " + e.Message;
  421. }
  422. return friendsOnline;
  423. }
  424. [Obsolete]
  425. public List<UUID> GetOnlineFriends(UUID userID, List<string> friends)
  426. {
  427. Hashtable hash = new Hashtable();
  428. hash["userID"] = userID.ToString();
  429. int i = 0;
  430. foreach (string s in friends)
  431. {
  432. hash["friend_" + i.ToString()] = s;
  433. i++;
  434. }
  435. IList paramList = new ArrayList();
  436. paramList.Add(hash);
  437. XmlRpcRequest request = new XmlRpcRequest("get_online_friends", paramList);
  438. // string reason = string.Empty;
  439. // Send and get reply
  440. List<UUID> online = new List<UUID>();
  441. XmlRpcResponse response = null;
  442. try
  443. {
  444. response = request.Send(m_ServerURL, 10000);
  445. }
  446. catch
  447. {
  448. m_log.DebugFormat("[USER AGENT CONNECTOR]: Unable to contact remote server {0} for GetOnlineFriends", m_ServerURL);
  449. // reason = "Exception: " + e.Message;
  450. return online;
  451. }
  452. if (response.IsFault)
  453. {
  454. m_log.ErrorFormat("[USER AGENT CONNECTOR]: remote call to {0} for GetOnlineFriends returned an error: {1}", m_ServerURL, response.FaultString);
  455. // reason = "XMLRPC Fault";
  456. return online;
  457. }
  458. hash = (Hashtable)response.Value;
  459. //foreach (Object o in hash)
  460. // m_log.Debug(">> " + ((DictionaryEntry)o).Key + ":" + ((DictionaryEntry)o).Value);
  461. try
  462. {
  463. if (hash == null)
  464. {
  465. m_log.ErrorFormat("[USER AGENT CONNECTOR]: GetOnlineFriends Got null response from {0}! THIS IS BAAAAD", m_ServerURL);
  466. // reason = "Internal error 1";
  467. return online;
  468. }
  469. // Here is the actual response
  470. foreach (object key in hash.Keys)
  471. {
  472. if (key is string && ((string)key).StartsWith("friend_") && hash[key] != null)
  473. {
  474. UUID uuid;
  475. if (UUID.TryParse(hash[key].ToString(), out uuid))
  476. online.Add(uuid);
  477. }
  478. }
  479. }
  480. catch
  481. {
  482. m_log.ErrorFormat("[USER AGENT CONNECTOR]: Got exception on GetOnlineFriends response.");
  483. // reason = "Exception: " + e.Message;
  484. }
  485. return online;
  486. }
  487. public Dictionary<string,object> GetUserInfo (UUID userID)
  488. {
  489. Hashtable hash = new Hashtable();
  490. hash["userID"] = userID.ToString();
  491. IList paramList = new ArrayList();
  492. paramList.Add(hash);
  493. XmlRpcRequest request = new XmlRpcRequest("get_user_info", paramList);
  494. Dictionary<string, object> info = new Dictionary<string, object>();
  495. XmlRpcResponse response = null;
  496. try
  497. {
  498. response = request.Send(m_ServerURL, 10000);
  499. }
  500. catch
  501. {
  502. m_log.DebugFormat("[USER AGENT CONNECTOR]: Unable to contact remote server {0} for GetUserInfo", m_ServerURL);
  503. return info;
  504. }
  505. if (response.IsFault)
  506. {
  507. m_log.ErrorFormat("[USER AGENT CONNECTOR]: remote call to {0} for GetServerURLs returned an error: {1}", m_ServerURL, response.FaultString);
  508. return info;
  509. }
  510. hash = (Hashtable)response.Value;
  511. try
  512. {
  513. if (hash == null)
  514. {
  515. m_log.ErrorFormat("[USER AGENT CONNECTOR]: GetUserInfo Got null response from {0}! THIS IS BAAAAD", m_ServerURL);
  516. return info;
  517. }
  518. // Here is the actual response
  519. foreach (object key in hash.Keys)
  520. {
  521. if (hash[key] != null)
  522. {
  523. info.Add(key.ToString(), hash[key]);
  524. }
  525. }
  526. }
  527. catch
  528. {
  529. m_log.ErrorFormat("[USER AGENT CONNECTOR]: Got exception on GetOnlineFriends response.");
  530. }
  531. return info;
  532. }
  533. public Dictionary<string, object> GetServerURLs(UUID userID)
  534. {
  535. Hashtable hash = new Hashtable();
  536. hash["userID"] = userID.ToString();
  537. IList paramList = new ArrayList();
  538. paramList.Add(hash);
  539. XmlRpcRequest request = new XmlRpcRequest("get_server_urls", paramList);
  540. // string reason = string.Empty;
  541. // Send and get reply
  542. Dictionary<string, object> serverURLs = new Dictionary<string,object>();
  543. XmlRpcResponse response = null;
  544. try
  545. {
  546. response = request.Send(m_ServerURL, 10000);
  547. }
  548. catch
  549. {
  550. m_log.DebugFormat("[USER AGENT CONNECTOR]: Unable to contact remote server {0} for GetServerURLs", m_ServerURL);
  551. // reason = "Exception: " + e.Message;
  552. return serverURLs;
  553. }
  554. if (response.IsFault)
  555. {
  556. m_log.ErrorFormat("[USER AGENT CONNECTOR]: remote call to {0} for GetServerURLs returned an error: {1}", m_ServerURL, response.FaultString);
  557. // reason = "XMLRPC Fault";
  558. return serverURLs;
  559. }
  560. hash = (Hashtable)response.Value;
  561. //foreach (Object o in hash)
  562. // m_log.Debug(">> " + ((DictionaryEntry)o).Key + ":" + ((DictionaryEntry)o).Value);
  563. try
  564. {
  565. if (hash == null)
  566. {
  567. m_log.ErrorFormat("[USER AGENT CONNECTOR]: GetServerURLs Got null response from {0}! THIS IS BAAAAD", m_ServerURL);
  568. // reason = "Internal error 1";
  569. return serverURLs;
  570. }
  571. // Here is the actual response
  572. foreach (object key in hash.Keys)
  573. {
  574. if (key is string && ((string)key).StartsWith("SRV_") && hash[key] != null)
  575. {
  576. string serverType = key.ToString().Substring(4); // remove "SRV_"
  577. serverURLs.Add(serverType, hash[key].ToString());
  578. }
  579. }
  580. }
  581. catch
  582. {
  583. m_log.ErrorFormat("[USER AGENT CONNECTOR]: Got exception on GetOnlineFriends response.");
  584. // reason = "Exception: " + e.Message;
  585. }
  586. return serverURLs;
  587. }
  588. public string LocateUser(UUID userID)
  589. {
  590. Hashtable hash = new Hashtable();
  591. hash["userID"] = userID.ToString();
  592. IList paramList = new ArrayList();
  593. paramList.Add(hash);
  594. XmlRpcRequest request = new XmlRpcRequest("locate_user", paramList);
  595. // string reason = string.Empty;
  596. // Send and get reply
  597. string url = string.Empty;
  598. XmlRpcResponse response = null;
  599. try
  600. {
  601. response = request.Send(m_ServerURL, 10000);
  602. }
  603. catch
  604. {
  605. m_log.DebugFormat("[USER AGENT CONNECTOR]: Unable to contact remote server {0} for LocateUser", m_ServerURL);
  606. // reason = "Exception: " + e.Message;
  607. return url;
  608. }
  609. if (response.IsFault)
  610. {
  611. m_log.ErrorFormat("[USER AGENT CONNECTOR]: remote call to {0} for LocateUser returned an error: {1}", m_ServerURL, response.FaultString);
  612. // reason = "XMLRPC Fault";
  613. return url;
  614. }
  615. hash = (Hashtable)response.Value;
  616. //foreach (Object o in hash)
  617. // m_log.Debug(">> " + ((DictionaryEntry)o).Key + ":" + ((DictionaryEntry)o).Value);
  618. try
  619. {
  620. if (hash == null)
  621. {
  622. m_log.ErrorFormat("[USER AGENT CONNECTOR]: LocateUser Got null response from {0}! THIS IS BAAAAD", m_ServerURL);
  623. // reason = "Internal error 1";
  624. return url;
  625. }
  626. // Here's the actual response
  627. if (hash.ContainsKey("URL"))
  628. url = hash["URL"].ToString();
  629. }
  630. catch
  631. {
  632. m_log.ErrorFormat("[USER AGENT CONNECTOR]: Got exception on LocateUser response.");
  633. // reason = "Exception: " + e.Message;
  634. }
  635. return url;
  636. }
  637. public string GetUUI(UUID userID, UUID targetUserID)
  638. {
  639. Hashtable hash = new Hashtable();
  640. hash["userID"] = userID.ToString();
  641. hash["targetUserID"] = targetUserID.ToString();
  642. IList paramList = new ArrayList();
  643. paramList.Add(hash);
  644. XmlRpcRequest request = new XmlRpcRequest("get_uui", paramList);
  645. // string reason = string.Empty;
  646. // Send and get reply
  647. string uui = string.Empty;
  648. XmlRpcResponse response = null;
  649. try
  650. {
  651. response = request.Send(m_ServerURL, 10000);
  652. }
  653. catch
  654. {
  655. m_log.DebugFormat("[USER AGENT CONNECTOR]: Unable to contact remote server {0} for GetUUI", m_ServerURL);
  656. // reason = "Exception: " + e.Message;
  657. return uui;
  658. }
  659. if (response.IsFault)
  660. {
  661. m_log.ErrorFormat("[USER AGENT CONNECTOR]: remote call to {0} for GetUUI returned an error: {1}", m_ServerURL, response.FaultString);
  662. // reason = "XMLRPC Fault";
  663. return uui;
  664. }
  665. hash = (Hashtable)response.Value;
  666. //foreach (Object o in hash)
  667. // m_log.Debug(">> " + ((DictionaryEntry)o).Key + ":" + ((DictionaryEntry)o).Value);
  668. try
  669. {
  670. if (hash == null)
  671. {
  672. m_log.ErrorFormat("[USER AGENT CONNECTOR]: GetUUI Got null response from {0}! THIS IS BAAAAD", m_ServerURL);
  673. // reason = "Internal error 1";
  674. return uui;
  675. }
  676. // Here's the actual response
  677. if (hash.ContainsKey("UUI"))
  678. uui = hash["UUI"].ToString();
  679. }
  680. catch
  681. {
  682. m_log.ErrorFormat("[USER AGENT CONNECTOR]: Got exception on LocateUser response.");
  683. // reason = "Exception: " + e.Message;
  684. }
  685. return uui;
  686. }
  687. private bool GetBoolResponse(XmlRpcRequest request, out string reason)
  688. {
  689. //m_log.Debug("[USER AGENT CONNECTOR]: GetBoolResponse from/to " + m_ServerURL);
  690. XmlRpcResponse response = null;
  691. try
  692. {
  693. response = request.Send(m_ServerURL, 10000);
  694. }
  695. catch (Exception e)
  696. {
  697. m_log.DebugFormat("[USER AGENT CONNECTOR]: Unable to contact remote server {0} for GetBoolResponse", m_ServerURL);
  698. reason = "Exception: " + e.Message;
  699. return false;
  700. }
  701. if (response.IsFault)
  702. {
  703. m_log.ErrorFormat("[USER AGENT CONNECTOR]: remote call to {0} for GetBoolResponse returned an error: {1}", m_ServerURL, response.FaultString);
  704. reason = "XMLRPC Fault";
  705. return false;
  706. }
  707. Hashtable hash = (Hashtable)response.Value;
  708. //foreach (Object o in hash)
  709. // m_log.Debug(">> " + ((DictionaryEntry)o).Key + ":" + ((DictionaryEntry)o).Value);
  710. try
  711. {
  712. if (hash == null)
  713. {
  714. m_log.ErrorFormat("[USER AGENT CONNECTOR]: Got null response from {0}! THIS IS BAAAAD", m_ServerURL);
  715. reason = "Internal error 1";
  716. return false;
  717. }
  718. bool success = false;
  719. reason = string.Empty;
  720. if (hash.ContainsKey("result"))
  721. Boolean.TryParse((string)hash["result"], out success);
  722. else
  723. {
  724. reason = "Internal error 2";
  725. m_log.WarnFormat("[USER AGENT CONNECTOR]: response from {0} does not have expected key 'result'", m_ServerURL);
  726. }
  727. return success;
  728. }
  729. catch (Exception e)
  730. {
  731. m_log.ErrorFormat("[USER AGENT CONNECTOR]: Got exception on GetBoolResponse response.");
  732. if (hash.ContainsKey("result") && hash["result"] != null)
  733. m_log.ErrorFormat("Reply was ", (string)hash["result"]);
  734. reason = "Exception: " + e.Message;
  735. return false;
  736. }
  737. }
  738. }
  739. }