UserAgentServiceConnector.cs 34 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916
  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. [Obsolete]
  362. public List<UUID> StatusNotification(List<string> friends, UUID userID, bool online)
  363. {
  364. Hashtable hash = new Hashtable();
  365. hash["userID"] = userID.ToString();
  366. hash["online"] = online.ToString();
  367. int i = 0;
  368. foreach (string s in friends)
  369. {
  370. hash["friend_" + i.ToString()] = s;
  371. i++;
  372. }
  373. IList paramList = new ArrayList();
  374. paramList.Add(hash);
  375. XmlRpcRequest request = new XmlRpcRequest("status_notification", paramList);
  376. // string reason = string.Empty;
  377. // Send and get reply
  378. List<UUID> friendsOnline = new List<UUID>();
  379. XmlRpcResponse response = null;
  380. try
  381. {
  382. response = request.Send(m_ServerURL, 6000);
  383. }
  384. catch
  385. {
  386. m_log.DebugFormat("[USER AGENT CONNECTOR]: Unable to contact remote server {0} for StatusNotification", m_ServerURL);
  387. // reason = "Exception: " + e.Message;
  388. return friendsOnline;
  389. }
  390. if (response.IsFault)
  391. {
  392. m_log.ErrorFormat("[USER AGENT CONNECTOR]: remote call to {0} for StatusNotification returned an error: {1}", m_ServerURL, response.FaultString);
  393. // reason = "XMLRPC Fault";
  394. return friendsOnline;
  395. }
  396. hash = (Hashtable)response.Value;
  397. //foreach (Object o in hash)
  398. // m_log.Debug(">> " + ((DictionaryEntry)o).Key + ":" + ((DictionaryEntry)o).Value);
  399. try
  400. {
  401. if (hash == null)
  402. {
  403. m_log.ErrorFormat("[USER AGENT CONNECTOR]: GetOnlineFriends Got null response from {0}! THIS IS BAAAAD", m_ServerURL);
  404. // reason = "Internal error 1";
  405. return friendsOnline;
  406. }
  407. // Here is the actual response
  408. foreach (object key in hash.Keys)
  409. {
  410. if (key is string && ((string)key).StartsWith("friend_") && hash[key] != null)
  411. {
  412. UUID uuid;
  413. if (UUID.TryParse(hash[key].ToString(), out uuid))
  414. friendsOnline.Add(uuid);
  415. }
  416. }
  417. }
  418. catch
  419. {
  420. m_log.ErrorFormat("[USER AGENT CONNECTOR]: Got exception on GetOnlineFriends response.");
  421. // reason = "Exception: " + e.Message;
  422. }
  423. return friendsOnline;
  424. }
  425. [Obsolete]
  426. public List<UUID> GetOnlineFriends(UUID userID, List<string> friends)
  427. {
  428. Hashtable hash = new Hashtable();
  429. hash["userID"] = userID.ToString();
  430. int i = 0;
  431. foreach (string s in friends)
  432. {
  433. hash["friend_" + i.ToString()] = s;
  434. i++;
  435. }
  436. IList paramList = new ArrayList();
  437. paramList.Add(hash);
  438. XmlRpcRequest request = new XmlRpcRequest("get_online_friends", paramList);
  439. // string reason = string.Empty;
  440. // Send and get reply
  441. List<UUID> online = new List<UUID>();
  442. XmlRpcResponse response = null;
  443. try
  444. {
  445. response = request.Send(m_ServerURL, 10000);
  446. }
  447. catch
  448. {
  449. m_log.DebugFormat("[USER AGENT CONNECTOR]: Unable to contact remote server {0} for GetOnlineFriends", m_ServerURL);
  450. // reason = "Exception: " + e.Message;
  451. return online;
  452. }
  453. if (response.IsFault)
  454. {
  455. m_log.ErrorFormat("[USER AGENT CONNECTOR]: remote call to {0} for GetOnlineFriends returned an error: {1}", m_ServerURL, response.FaultString);
  456. // reason = "XMLRPC Fault";
  457. return online;
  458. }
  459. hash = (Hashtable)response.Value;
  460. //foreach (Object o in hash)
  461. // m_log.Debug(">> " + ((DictionaryEntry)o).Key + ":" + ((DictionaryEntry)o).Value);
  462. try
  463. {
  464. if (hash == null)
  465. {
  466. m_log.ErrorFormat("[USER AGENT CONNECTOR]: GetOnlineFriends Got null response from {0}! THIS IS BAAAAD", m_ServerURL);
  467. // reason = "Internal error 1";
  468. return online;
  469. }
  470. // Here is the actual response
  471. foreach (object key in hash.Keys)
  472. {
  473. if (key is string && ((string)key).StartsWith("friend_") && hash[key] != null)
  474. {
  475. UUID uuid;
  476. if (UUID.TryParse(hash[key].ToString(), out uuid))
  477. online.Add(uuid);
  478. }
  479. }
  480. }
  481. catch
  482. {
  483. m_log.ErrorFormat("[USER AGENT CONNECTOR]: Got exception on GetOnlineFriends response.");
  484. // reason = "Exception: " + e.Message;
  485. }
  486. return online;
  487. }
  488. public Dictionary<string,object> GetUserInfo (UUID userID)
  489. {
  490. Hashtable hash = new Hashtable();
  491. hash["userID"] = userID.ToString();
  492. IList paramList = new ArrayList();
  493. paramList.Add(hash);
  494. XmlRpcRequest request = new XmlRpcRequest("get_user_info", paramList);
  495. Dictionary<string, object> info = new Dictionary<string, object>();
  496. XmlRpcResponse response = null;
  497. try
  498. {
  499. response = request.Send(m_ServerURL, 10000);
  500. }
  501. catch
  502. {
  503. m_log.DebugFormat("[USER AGENT CONNECTOR]: Unable to contact remote server {0} for GetUserInfo", m_ServerURL);
  504. return info;
  505. }
  506. if (response.IsFault)
  507. {
  508. m_log.ErrorFormat("[USER AGENT CONNECTOR]: remote call to {0} for GetServerURLs returned an error: {1}", m_ServerURL, response.FaultString);
  509. return info;
  510. }
  511. hash = (Hashtable)response.Value;
  512. try
  513. {
  514. if (hash == null)
  515. {
  516. m_log.ErrorFormat("[USER AGENT CONNECTOR]: GetUserInfo Got null response from {0}! THIS IS BAAAAD", m_ServerURL);
  517. return info;
  518. }
  519. // Here is the actual response
  520. foreach (object key in hash.Keys)
  521. {
  522. if (hash[key] != null)
  523. {
  524. info.Add(key.ToString(), hash[key]);
  525. }
  526. }
  527. }
  528. catch
  529. {
  530. m_log.ErrorFormat("[USER AGENT CONNECTOR]: Got exception on GetOnlineFriends response.");
  531. }
  532. return info;
  533. }
  534. public Dictionary<string, object> GetServerURLs(UUID userID)
  535. {
  536. Hashtable hash = new Hashtable();
  537. hash["userID"] = userID.ToString();
  538. IList paramList = new ArrayList();
  539. paramList.Add(hash);
  540. XmlRpcRequest request = new XmlRpcRequest("get_server_urls", paramList);
  541. // string reason = string.Empty;
  542. // Send and get reply
  543. Dictionary<string, object> serverURLs = new Dictionary<string,object>();
  544. XmlRpcResponse response = null;
  545. try
  546. {
  547. response = request.Send(m_ServerURL, 10000);
  548. }
  549. catch
  550. {
  551. m_log.DebugFormat("[USER AGENT CONNECTOR]: Unable to contact remote server {0} for GetServerURLs", m_ServerURL);
  552. // reason = "Exception: " + e.Message;
  553. return serverURLs;
  554. }
  555. if (response.IsFault)
  556. {
  557. m_log.ErrorFormat("[USER AGENT CONNECTOR]: remote call to {0} for GetServerURLs returned an error: {1}", m_ServerURL, response.FaultString);
  558. // reason = "XMLRPC Fault";
  559. return serverURLs;
  560. }
  561. hash = (Hashtable)response.Value;
  562. //foreach (Object o in hash)
  563. // m_log.Debug(">> " + ((DictionaryEntry)o).Key + ":" + ((DictionaryEntry)o).Value);
  564. try
  565. {
  566. if (hash == null)
  567. {
  568. m_log.ErrorFormat("[USER AGENT CONNECTOR]: GetServerURLs Got null response from {0}! THIS IS BAAAAD", m_ServerURL);
  569. // reason = "Internal error 1";
  570. return serverURLs;
  571. }
  572. // Here is the actual response
  573. foreach (object key in hash.Keys)
  574. {
  575. if (key is string && ((string)key).StartsWith("SRV_") && hash[key] != null)
  576. {
  577. string serverType = key.ToString().Substring(4); // remove "SRV_"
  578. serverURLs.Add(serverType, hash[key].ToString());
  579. }
  580. }
  581. }
  582. catch
  583. {
  584. m_log.ErrorFormat("[USER AGENT CONNECTOR]: Got exception on GetOnlineFriends response.");
  585. // reason = "Exception: " + e.Message;
  586. }
  587. return serverURLs;
  588. }
  589. public string LocateUser(UUID userID)
  590. {
  591. Hashtable hash = new Hashtable();
  592. hash["userID"] = userID.ToString();
  593. IList paramList = new ArrayList();
  594. paramList.Add(hash);
  595. XmlRpcRequest request = new XmlRpcRequest("locate_user", paramList);
  596. // string reason = string.Empty;
  597. // Send and get reply
  598. string url = 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 LocateUser", m_ServerURL);
  607. // reason = "Exception: " + e.Message;
  608. return url;
  609. }
  610. if (response.IsFault)
  611. {
  612. m_log.ErrorFormat("[USER AGENT CONNECTOR]: remote call to {0} for LocateUser returned an error: {1}", m_ServerURL, response.FaultString);
  613. // reason = "XMLRPC Fault";
  614. return url;
  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]: LocateUser Got null response from {0}! THIS IS BAAAAD", m_ServerURL);
  624. // reason = "Internal error 1";
  625. return url;
  626. }
  627. // Here's the actual response
  628. if (hash.ContainsKey("URL"))
  629. url = hash["URL"].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 url;
  637. }
  638. public string GetUUI(UUID userID, UUID targetUserID)
  639. {
  640. Hashtable hash = new Hashtable();
  641. hash["userID"] = userID.ToString();
  642. hash["targetUserID"] = targetUserID.ToString();
  643. IList paramList = new ArrayList();
  644. paramList.Add(hash);
  645. XmlRpcRequest request = new XmlRpcRequest("get_uui", paramList);
  646. // string reason = string.Empty;
  647. // Send and get reply
  648. string uui = string.Empty;
  649. XmlRpcResponse response = null;
  650. try
  651. {
  652. response = request.Send(m_ServerURL, 10000);
  653. }
  654. catch
  655. {
  656. m_log.DebugFormat("[USER AGENT CONNECTOR]: Unable to contact remote server {0} for GetUUI", m_ServerURL);
  657. // reason = "Exception: " + e.Message;
  658. return uui;
  659. }
  660. if (response.IsFault)
  661. {
  662. m_log.ErrorFormat("[USER AGENT CONNECTOR]: remote call to {0} for GetUUI returned an error: {1}", m_ServerURL, response.FaultString);
  663. // reason = "XMLRPC Fault";
  664. return uui;
  665. }
  666. hash = (Hashtable)response.Value;
  667. //foreach (Object o in hash)
  668. // m_log.Debug(">> " + ((DictionaryEntry)o).Key + ":" + ((DictionaryEntry)o).Value);
  669. try
  670. {
  671. if (hash == null)
  672. {
  673. m_log.ErrorFormat("[USER AGENT CONNECTOR]: GetUUI Got null response from {0}! THIS IS BAAAAD", m_ServerURL);
  674. // reason = "Internal error 1";
  675. return uui;
  676. }
  677. // Here's the actual response
  678. if (hash.ContainsKey("UUI"))
  679. uui = hash["UUI"].ToString();
  680. }
  681. catch
  682. {
  683. m_log.ErrorFormat("[USER AGENT CONNECTOR]: Got exception on GetUUI response.");
  684. // reason = "Exception: " + e.Message;
  685. }
  686. return uui;
  687. }
  688. public UUID GetUUID(String first, String last)
  689. {
  690. Hashtable hash = new Hashtable();
  691. hash["first"] = first;
  692. hash["last"] = last;
  693. IList paramList = new ArrayList();
  694. paramList.Add(hash);
  695. XmlRpcRequest request = new XmlRpcRequest("get_uuid", paramList);
  696. // string reason = string.Empty;
  697. // Send and get reply
  698. UUID uuid = UUID.Zero;
  699. XmlRpcResponse response = null;
  700. try
  701. {
  702. response = request.Send(m_ServerURL, 10000);
  703. }
  704. catch
  705. {
  706. m_log.DebugFormat("[USER AGENT CONNECTOR]: Unable to contact remote server {0} for GetUUID", m_ServerURL);
  707. // reason = "Exception: " + e.Message;
  708. return uuid;
  709. }
  710. if (response.IsFault)
  711. {
  712. m_log.ErrorFormat("[USER AGENT CONNECTOR]: remote call to {0} for GetUUID returned an error: {1}", m_ServerURL, response.FaultString);
  713. // reason = "XMLRPC Fault";
  714. return uuid;
  715. }
  716. hash = (Hashtable)response.Value;
  717. //foreach (Object o in hash)
  718. // m_log.Debug(">> " + ((DictionaryEntry)o).Key + ":" + ((DictionaryEntry)o).Value);
  719. try
  720. {
  721. if (hash == null)
  722. {
  723. m_log.ErrorFormat("[USER AGENT CONNECTOR]: GetUUDI Got null response from {0}! THIS IS BAAAAD", m_ServerURL);
  724. // reason = "Internal error 1";
  725. return uuid;
  726. }
  727. // Here's the actual response
  728. if (hash.ContainsKey("UUID"))
  729. UUID.TryParse(hash["UUID"].ToString(), out uuid);
  730. }
  731. catch
  732. {
  733. m_log.ErrorFormat("[USER AGENT CONNECTOR]: Got exception on UUID response.");
  734. // reason = "Exception: " + e.Message;
  735. }
  736. return uuid;
  737. }
  738. private bool GetBoolResponse(XmlRpcRequest request, out string reason)
  739. {
  740. //m_log.Debug("[USER AGENT CONNECTOR]: GetBoolResponse from/to " + m_ServerURL);
  741. XmlRpcResponse response = null;
  742. try
  743. {
  744. response = request.Send(m_ServerURL, 10000);
  745. }
  746. catch (Exception e)
  747. {
  748. m_log.DebugFormat("[USER AGENT CONNECTOR]: Unable to contact remote server {0} for GetBoolResponse", m_ServerURL);
  749. reason = "Exception: " + e.Message;
  750. return false;
  751. }
  752. if (response.IsFault)
  753. {
  754. m_log.ErrorFormat("[USER AGENT CONNECTOR]: remote call to {0} for GetBoolResponse returned an error: {1}", m_ServerURL, response.FaultString);
  755. reason = "XMLRPC Fault";
  756. return false;
  757. }
  758. Hashtable hash = (Hashtable)response.Value;
  759. //foreach (Object o in hash)
  760. // m_log.Debug(">> " + ((DictionaryEntry)o).Key + ":" + ((DictionaryEntry)o).Value);
  761. try
  762. {
  763. if (hash == null)
  764. {
  765. m_log.ErrorFormat("[USER AGENT CONNECTOR]: Got null response from {0}! THIS IS BAAAAD", m_ServerURL);
  766. reason = "Internal error 1";
  767. return false;
  768. }
  769. bool success = false;
  770. reason = string.Empty;
  771. if (hash.ContainsKey("result"))
  772. Boolean.TryParse((string)hash["result"], out success);
  773. else
  774. {
  775. reason = "Internal error 2";
  776. m_log.WarnFormat("[USER AGENT CONNECTOR]: response from {0} does not have expected key 'result'", m_ServerURL);
  777. }
  778. return success;
  779. }
  780. catch (Exception e)
  781. {
  782. m_log.ErrorFormat("[USER AGENT CONNECTOR]: Got exception on GetBoolResponse response.");
  783. if (hash.ContainsKey("result") && hash["result"] != null)
  784. m_log.ErrorFormat("Reply was ", (string)hash["result"]);
  785. reason = "Exception: " + e.Message;
  786. return false;
  787. }
  788. }
  789. }
  790. }