UserAgentServiceConnector.cs 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798
  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["internal_port"] != null)
  296. {
  297. int p = 0;
  298. Int32.TryParse((string)hash["internal_port"], out p);
  299. region.InternalEndPoint = new IPEndPoint(IPAddress.Parse("0.0.0.0"), p);
  300. }
  301. if (hash["position"] != null)
  302. Vector3.TryParse((string)hash["position"], out position);
  303. if (hash["lookAt"] != null)
  304. Vector3.TryParse((string)hash["lookAt"], out lookAt);
  305. // Successful return
  306. return region;
  307. }
  308. }
  309. catch (Exception)
  310. {
  311. return null;
  312. }
  313. return null;
  314. }
  315. public bool AgentIsComingHome(UUID sessionID, string thisGridExternalName)
  316. {
  317. Hashtable hash = new Hashtable();
  318. hash["sessionID"] = sessionID.ToString();
  319. hash["externalName"] = thisGridExternalName;
  320. IList paramList = new ArrayList();
  321. paramList.Add(hash);
  322. XmlRpcRequest request = new XmlRpcRequest("agent_is_coming_home", paramList);
  323. string reason = string.Empty;
  324. return GetBoolResponse(request, out reason);
  325. }
  326. public bool VerifyAgent(UUID sessionID, string token)
  327. {
  328. Hashtable hash = new Hashtable();
  329. hash["sessionID"] = sessionID.ToString();
  330. hash["token"] = token;
  331. IList paramList = new ArrayList();
  332. paramList.Add(hash);
  333. XmlRpcRequest request = new XmlRpcRequest("verify_agent", paramList);
  334. string reason = string.Empty;
  335. return GetBoolResponse(request, out reason);
  336. }
  337. public bool VerifyClient(UUID sessionID, string token)
  338. {
  339. Hashtable hash = new Hashtable();
  340. hash["sessionID"] = sessionID.ToString();
  341. hash["token"] = token;
  342. IList paramList = new ArrayList();
  343. paramList.Add(hash);
  344. XmlRpcRequest request = new XmlRpcRequest("verify_client", paramList);
  345. string reason = string.Empty;
  346. return GetBoolResponse(request, out reason);
  347. }
  348. public void LogoutAgent(UUID userID, UUID sessionID)
  349. {
  350. Hashtable hash = new Hashtable();
  351. hash["sessionID"] = sessionID.ToString();
  352. hash["userID"] = userID.ToString();
  353. IList paramList = new ArrayList();
  354. paramList.Add(hash);
  355. XmlRpcRequest request = new XmlRpcRequest("logout_agent", paramList);
  356. string reason = string.Empty;
  357. GetBoolResponse(request, out reason);
  358. }
  359. public List<UUID> StatusNotification(List<string> friends, UUID userID, bool online)
  360. {
  361. Hashtable hash = new Hashtable();
  362. hash["userID"] = userID.ToString();
  363. hash["online"] = online.ToString();
  364. int i = 0;
  365. foreach (string s in friends)
  366. {
  367. hash["friend_" + i.ToString()] = s;
  368. i++;
  369. }
  370. IList paramList = new ArrayList();
  371. paramList.Add(hash);
  372. XmlRpcRequest request = new XmlRpcRequest("status_notification", paramList);
  373. // string reason = string.Empty;
  374. // Send and get reply
  375. List<UUID> friendsOnline = new List<UUID>();
  376. XmlRpcResponse response = null;
  377. try
  378. {
  379. response = request.Send(m_ServerURL, 6000);
  380. }
  381. catch
  382. {
  383. m_log.DebugFormat("[USER AGENT CONNECTOR]: Unable to contact remote server {0} for StatusNotification", m_ServerURL);
  384. // reason = "Exception: " + e.Message;
  385. return friendsOnline;
  386. }
  387. if (response.IsFault)
  388. {
  389. m_log.ErrorFormat("[USER AGENT CONNECTOR]: remote call to {0} for StatusNotification returned an error: {1}", m_ServerURL, response.FaultString);
  390. // reason = "XMLRPC Fault";
  391. return friendsOnline;
  392. }
  393. hash = (Hashtable)response.Value;
  394. //foreach (Object o in hash)
  395. // m_log.Debug(">> " + ((DictionaryEntry)o).Key + ":" + ((DictionaryEntry)o).Value);
  396. try
  397. {
  398. if (hash == null)
  399. {
  400. m_log.ErrorFormat("[USER AGENT CONNECTOR]: GetOnlineFriends Got null response from {0}! THIS IS BAAAAD", m_ServerURL);
  401. // reason = "Internal error 1";
  402. return friendsOnline;
  403. }
  404. // Here is the actual response
  405. foreach (object key in hash.Keys)
  406. {
  407. if (key is string && ((string)key).StartsWith("friend_") && hash[key] != null)
  408. {
  409. UUID uuid;
  410. if (UUID.TryParse(hash[key].ToString(), out uuid))
  411. friendsOnline.Add(uuid);
  412. }
  413. }
  414. }
  415. catch
  416. {
  417. m_log.ErrorFormat("[USER AGENT CONNECTOR]: Got exception on GetOnlineFriends response.");
  418. // reason = "Exception: " + e.Message;
  419. }
  420. return friendsOnline;
  421. }
  422. public List<UUID> GetOnlineFriends(UUID userID, List<string> friends)
  423. {
  424. Hashtable hash = new Hashtable();
  425. hash["userID"] = userID.ToString();
  426. int i = 0;
  427. foreach (string s in friends)
  428. {
  429. hash["friend_" + i.ToString()] = s;
  430. i++;
  431. }
  432. IList paramList = new ArrayList();
  433. paramList.Add(hash);
  434. XmlRpcRequest request = new XmlRpcRequest("get_online_friends", paramList);
  435. // string reason = string.Empty;
  436. // Send and get reply
  437. List<UUID> online = new List<UUID>();
  438. XmlRpcResponse response = null;
  439. try
  440. {
  441. response = request.Send(m_ServerURL, 10000);
  442. }
  443. catch
  444. {
  445. m_log.DebugFormat("[USER AGENT CONNECTOR]: Unable to contact remote server {0} for GetOnlineFriends", m_ServerURL);
  446. // reason = "Exception: " + e.Message;
  447. return online;
  448. }
  449. if (response.IsFault)
  450. {
  451. m_log.ErrorFormat("[USER AGENT CONNECTOR]: remote call to {0} for GetOnlineFriends returned an error: {1}", m_ServerURL, response.FaultString);
  452. // reason = "XMLRPC Fault";
  453. return online;
  454. }
  455. hash = (Hashtable)response.Value;
  456. //foreach (Object o in hash)
  457. // m_log.Debug(">> " + ((DictionaryEntry)o).Key + ":" + ((DictionaryEntry)o).Value);
  458. try
  459. {
  460. if (hash == null)
  461. {
  462. m_log.ErrorFormat("[USER AGENT CONNECTOR]: GetOnlineFriends Got null response from {0}! THIS IS BAAAAD", m_ServerURL);
  463. // reason = "Internal error 1";
  464. return online;
  465. }
  466. // Here is the actual response
  467. foreach (object key in hash.Keys)
  468. {
  469. if (key is string && ((string)key).StartsWith("friend_") && hash[key] != null)
  470. {
  471. UUID uuid;
  472. if (UUID.TryParse(hash[key].ToString(), out uuid))
  473. online.Add(uuid);
  474. }
  475. }
  476. }
  477. catch
  478. {
  479. m_log.ErrorFormat("[USER AGENT CONNECTOR]: Got exception on GetOnlineFriends response.");
  480. // reason = "Exception: " + e.Message;
  481. }
  482. return online;
  483. }
  484. public Dictionary<string, object> GetServerURLs(UUID userID)
  485. {
  486. Hashtable hash = new Hashtable();
  487. hash["userID"] = userID.ToString();
  488. IList paramList = new ArrayList();
  489. paramList.Add(hash);
  490. XmlRpcRequest request = new XmlRpcRequest("get_server_urls", paramList);
  491. // string reason = string.Empty;
  492. // Send and get reply
  493. Dictionary<string, object> serverURLs = new Dictionary<string,object>();
  494. XmlRpcResponse response = null;
  495. try
  496. {
  497. response = request.Send(m_ServerURL, 10000);
  498. }
  499. catch
  500. {
  501. m_log.DebugFormat("[USER AGENT CONNECTOR]: Unable to contact remote server {0} for GetServerURLs", m_ServerURL);
  502. // reason = "Exception: " + e.Message;
  503. return serverURLs;
  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. // reason = "XMLRPC Fault";
  509. return serverURLs;
  510. }
  511. hash = (Hashtable)response.Value;
  512. //foreach (Object o in hash)
  513. // m_log.Debug(">> " + ((DictionaryEntry)o).Key + ":" + ((DictionaryEntry)o).Value);
  514. try
  515. {
  516. if (hash == null)
  517. {
  518. m_log.ErrorFormat("[USER AGENT CONNECTOR]: GetServerURLs Got null response from {0}! THIS IS BAAAAD", m_ServerURL);
  519. // reason = "Internal error 1";
  520. return serverURLs;
  521. }
  522. // Here is the actual response
  523. foreach (object key in hash.Keys)
  524. {
  525. if (key is string && ((string)key).StartsWith("SRV_") && hash[key] != null)
  526. {
  527. string serverType = key.ToString().Substring(4); // remove "SRV_"
  528. serverURLs.Add(serverType, hash[key].ToString());
  529. }
  530. }
  531. }
  532. catch
  533. {
  534. m_log.ErrorFormat("[USER AGENT CONNECTOR]: Got exception on GetOnlineFriends response.");
  535. // reason = "Exception: " + e.Message;
  536. }
  537. return serverURLs;
  538. }
  539. public string LocateUser(UUID userID)
  540. {
  541. Hashtable hash = new Hashtable();
  542. hash["userID"] = userID.ToString();
  543. IList paramList = new ArrayList();
  544. paramList.Add(hash);
  545. XmlRpcRequest request = new XmlRpcRequest("locate_user", paramList);
  546. // string reason = string.Empty;
  547. // Send and get reply
  548. string url = string.Empty;
  549. XmlRpcResponse response = null;
  550. try
  551. {
  552. response = request.Send(m_ServerURL, 10000);
  553. }
  554. catch
  555. {
  556. m_log.DebugFormat("[USER AGENT CONNECTOR]: Unable to contact remote server {0} for LocateUser", m_ServerURL);
  557. // reason = "Exception: " + e.Message;
  558. return url;
  559. }
  560. if (response.IsFault)
  561. {
  562. m_log.ErrorFormat("[USER AGENT CONNECTOR]: remote call to {0} for LocateUser returned an error: {1}", m_ServerURL, response.FaultString);
  563. // reason = "XMLRPC Fault";
  564. return url;
  565. }
  566. hash = (Hashtable)response.Value;
  567. //foreach (Object o in hash)
  568. // m_log.Debug(">> " + ((DictionaryEntry)o).Key + ":" + ((DictionaryEntry)o).Value);
  569. try
  570. {
  571. if (hash == null)
  572. {
  573. m_log.ErrorFormat("[USER AGENT CONNECTOR]: LocateUser Got null response from {0}! THIS IS BAAAAD", m_ServerURL);
  574. // reason = "Internal error 1";
  575. return url;
  576. }
  577. // Here's the actual response
  578. if (hash.ContainsKey("URL"))
  579. url = hash["URL"].ToString();
  580. }
  581. catch
  582. {
  583. m_log.ErrorFormat("[USER AGENT CONNECTOR]: Got exception on LocateUser response.");
  584. // reason = "Exception: " + e.Message;
  585. }
  586. return url;
  587. }
  588. public string GetUUI(UUID userID, UUID targetUserID)
  589. {
  590. Hashtable hash = new Hashtable();
  591. hash["userID"] = userID.ToString();
  592. hash["targetUserID"] = targetUserID.ToString();
  593. IList paramList = new ArrayList();
  594. paramList.Add(hash);
  595. XmlRpcRequest request = new XmlRpcRequest("get_uui", paramList);
  596. // string reason = string.Empty;
  597. // Send and get reply
  598. string uui = string.Empty;
  599. XmlRpcResponse response = null;
  600. try
  601. {
  602. response = request.Send(m_ServerURL, 10000);
  603. }
  604. catch
  605. {
  606. m_log.DebugFormat("[USER AGENT CONNECTOR]: Unable to contact remote server {0} for GetUUI", m_ServerURL);
  607. // reason = "Exception: " + e.Message;
  608. return uui;
  609. }
  610. if (response.IsFault)
  611. {
  612. m_log.ErrorFormat("[USER AGENT CONNECTOR]: remote call to {0} for GetUUI returned an error: {1}", m_ServerURL, response.FaultString);
  613. // reason = "XMLRPC Fault";
  614. return uui;
  615. }
  616. hash = (Hashtable)response.Value;
  617. //foreach (Object o in hash)
  618. // m_log.Debug(">> " + ((DictionaryEntry)o).Key + ":" + ((DictionaryEntry)o).Value);
  619. try
  620. {
  621. if (hash == null)
  622. {
  623. m_log.ErrorFormat("[USER AGENT CONNECTOR]: GetUUI Got null response from {0}! THIS IS BAAAAD", m_ServerURL);
  624. // reason = "Internal error 1";
  625. return uui;
  626. }
  627. // Here's the actual response
  628. if (hash.ContainsKey("UUI"))
  629. uui = hash["UUI"].ToString();
  630. }
  631. catch
  632. {
  633. m_log.ErrorFormat("[USER AGENT CONNECTOR]: Got exception on LocateUser response.");
  634. // reason = "Exception: " + e.Message;
  635. }
  636. return uui;
  637. }
  638. private bool GetBoolResponse(XmlRpcRequest request, out string reason)
  639. {
  640. //m_log.Debug("[USER AGENT CONNECTOR]: GetBoolResponse from/to " + m_ServerURL);
  641. XmlRpcResponse response = null;
  642. try
  643. {
  644. response = request.Send(m_ServerURL, 10000);
  645. }
  646. catch (Exception e)
  647. {
  648. m_log.DebugFormat("[USER AGENT CONNECTOR]: Unable to contact remote server {0} for GetBoolResponse", m_ServerURL);
  649. reason = "Exception: " + e.Message;
  650. return false;
  651. }
  652. if (response.IsFault)
  653. {
  654. m_log.ErrorFormat("[USER AGENT CONNECTOR]: remote call to {0} for GetBoolResponse returned an error: {1}", m_ServerURL, response.FaultString);
  655. reason = "XMLRPC Fault";
  656. return false;
  657. }
  658. Hashtable hash = (Hashtable)response.Value;
  659. //foreach (Object o in hash)
  660. // m_log.Debug(">> " + ((DictionaryEntry)o).Key + ":" + ((DictionaryEntry)o).Value);
  661. try
  662. {
  663. if (hash == null)
  664. {
  665. m_log.ErrorFormat("[USER AGENT CONNECTOR]: Got null response from {0}! THIS IS BAAAAD", m_ServerURL);
  666. reason = "Internal error 1";
  667. return false;
  668. }
  669. bool success = false;
  670. reason = string.Empty;
  671. if (hash.ContainsKey("result"))
  672. Boolean.TryParse((string)hash["result"], out success);
  673. else
  674. {
  675. reason = "Internal error 2";
  676. m_log.WarnFormat("[USER AGENT CONNECTOR]: response from {0} does not have expected key 'result'", m_ServerURL);
  677. }
  678. return success;
  679. }
  680. catch (Exception e)
  681. {
  682. m_log.ErrorFormat("[USER AGENT CONNECTOR]: Got exception on GetBoolResponse response.");
  683. if (hash.ContainsKey("result") && hash["result"] != null)
  684. m_log.ErrorFormat("Reply was ", (string)hash["result"]);
  685. reason = "Exception: " + e.Message;
  686. return false;
  687. }
  688. }
  689. }
  690. }