UserAgentServiceConnector.cs 31 KB

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