UserAgentServiceConnector.cs 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849
  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["size_x"] != null)
  214. {
  215. Int32.TryParse((string)hash["x"], out n);
  216. region.RegionSizeX = n;
  217. //m_log.Debug(">> HERE, x: " + region.RegionLocX);
  218. }
  219. if (hash["size_y"] != null)
  220. {
  221. Int32.TryParse((string)hash["y"], out n);
  222. region.RegionSizeY = n;
  223. //m_log.Debug(">> HERE, y: " + region.RegionLocY);
  224. }
  225. if (hash["region_name"] != null)
  226. {
  227. region.RegionName = (string)hash["region_name"];
  228. //m_log.Debug(">> HERE, name: " + region.RegionName);
  229. }
  230. if (hash["hostname"] != null)
  231. region.ExternalHostName = (string)hash["hostname"];
  232. if (hash["http_port"] != null)
  233. {
  234. uint p = 0;
  235. UInt32.TryParse((string)hash["http_port"], out p);
  236. region.HttpPort = p;
  237. }
  238. if (hash.ContainsKey("server_uri") && hash["server_uri"] != null)
  239. region.ServerURI = (string)hash["server_uri"];
  240. if (hash["internal_port"] != null)
  241. {
  242. int p = 0;
  243. Int32.TryParse((string)hash["internal_port"], out p);
  244. region.InternalEndPoint = new IPEndPoint(IPAddress.Parse("0.0.0.0"), p);
  245. }
  246. if (hash["position"] != null)
  247. Vector3.TryParse((string)hash["position"], out position);
  248. if (hash["lookAt"] != null)
  249. Vector3.TryParse((string)hash["lookAt"], out lookAt);
  250. // Successful return
  251. return region;
  252. }
  253. }
  254. catch (Exception)
  255. {
  256. return null;
  257. }
  258. return null;
  259. }
  260. public bool IsAgentComingHome(UUID sessionID, string thisGridExternalName)
  261. {
  262. Hashtable hash = new Hashtable();
  263. hash["sessionID"] = sessionID.ToString();
  264. hash["externalName"] = thisGridExternalName;
  265. IList paramList = new ArrayList();
  266. paramList.Add(hash);
  267. XmlRpcRequest request = new XmlRpcRequest("agent_is_coming_home", paramList);
  268. string reason = string.Empty;
  269. return GetBoolResponse(request, out reason);
  270. }
  271. public bool VerifyAgent(UUID sessionID, string token)
  272. {
  273. Hashtable hash = new Hashtable();
  274. hash["sessionID"] = sessionID.ToString();
  275. hash["token"] = token;
  276. IList paramList = new ArrayList();
  277. paramList.Add(hash);
  278. XmlRpcRequest request = new XmlRpcRequest("verify_agent", paramList);
  279. string reason = string.Empty;
  280. return GetBoolResponse(request, out reason);
  281. }
  282. public bool VerifyClient(UUID sessionID, string token)
  283. {
  284. Hashtable hash = new Hashtable();
  285. hash["sessionID"] = sessionID.ToString();
  286. hash["token"] = token;
  287. IList paramList = new ArrayList();
  288. paramList.Add(hash);
  289. XmlRpcRequest request = new XmlRpcRequest("verify_client", paramList);
  290. string reason = string.Empty;
  291. return GetBoolResponse(request, out reason);
  292. }
  293. public void LogoutAgent(UUID userID, UUID sessionID)
  294. {
  295. Hashtable hash = new Hashtable();
  296. hash["sessionID"] = sessionID.ToString();
  297. hash["userID"] = userID.ToString();
  298. IList paramList = new ArrayList();
  299. paramList.Add(hash);
  300. XmlRpcRequest request = new XmlRpcRequest("logout_agent", paramList);
  301. string reason = string.Empty;
  302. GetBoolResponse(request, out reason);
  303. }
  304. [Obsolete]
  305. public List<UUID> StatusNotification(List<string> friends, UUID userID, bool online)
  306. {
  307. Hashtable hash = new Hashtable();
  308. hash["userID"] = userID.ToString();
  309. hash["online"] = online.ToString();
  310. int i = 0;
  311. foreach (string s in friends)
  312. {
  313. hash["friend_" + i.ToString()] = s;
  314. i++;
  315. }
  316. IList paramList = new ArrayList();
  317. paramList.Add(hash);
  318. XmlRpcRequest request = new XmlRpcRequest("status_notification", paramList);
  319. // string reason = string.Empty;
  320. // Send and get reply
  321. List<UUID> friendsOnline = new List<UUID>();
  322. XmlRpcResponse response = null;
  323. try
  324. {
  325. response = request.Send(m_ServerURL, 6000);
  326. }
  327. catch
  328. {
  329. m_log.DebugFormat("[USER AGENT CONNECTOR]: Unable to contact remote server {0} for StatusNotification", m_ServerURL);
  330. // reason = "Exception: " + e.Message;
  331. return friendsOnline;
  332. }
  333. if (response.IsFault)
  334. {
  335. m_log.ErrorFormat("[USER AGENT CONNECTOR]: remote call to {0} for StatusNotification returned an error: {1}", m_ServerURL, response.FaultString);
  336. // reason = "XMLRPC Fault";
  337. return friendsOnline;
  338. }
  339. hash = (Hashtable)response.Value;
  340. //foreach (Object o in hash)
  341. // m_log.Debug(">> " + ((DictionaryEntry)o).Key + ":" + ((DictionaryEntry)o).Value);
  342. try
  343. {
  344. if (hash == null)
  345. {
  346. m_log.ErrorFormat("[USER AGENT CONNECTOR]: GetOnlineFriends Got null response from {0}! THIS IS BAAAAD", m_ServerURL);
  347. // reason = "Internal error 1";
  348. return friendsOnline;
  349. }
  350. // Here is the actual response
  351. foreach (object key in hash.Keys)
  352. {
  353. if (key is string && ((string)key).StartsWith("friend_") && hash[key] != null)
  354. {
  355. UUID uuid;
  356. if (UUID.TryParse(hash[key].ToString(), out uuid))
  357. friendsOnline.Add(uuid);
  358. }
  359. }
  360. }
  361. catch
  362. {
  363. m_log.ErrorFormat("[USER AGENT CONNECTOR]: Got exception on GetOnlineFriends response.");
  364. // reason = "Exception: " + e.Message;
  365. }
  366. return friendsOnline;
  367. }
  368. [Obsolete]
  369. public List<UUID> GetOnlineFriends(UUID userID, List<string> friends)
  370. {
  371. Hashtable hash = new Hashtable();
  372. hash["userID"] = userID.ToString();
  373. int i = 0;
  374. foreach (string s in friends)
  375. {
  376. hash["friend_" + i.ToString()] = s;
  377. i++;
  378. }
  379. IList paramList = new ArrayList();
  380. paramList.Add(hash);
  381. XmlRpcRequest request = new XmlRpcRequest("get_online_friends", paramList);
  382. // string reason = string.Empty;
  383. // Send and get reply
  384. List<UUID> online = new List<UUID>();
  385. XmlRpcResponse response = null;
  386. try
  387. {
  388. response = request.Send(m_ServerURL, 10000);
  389. }
  390. catch
  391. {
  392. m_log.DebugFormat("[USER AGENT CONNECTOR]: Unable to contact remote server {0} for GetOnlineFriends", m_ServerURL);
  393. // reason = "Exception: " + e.Message;
  394. return online;
  395. }
  396. if (response.IsFault)
  397. {
  398. m_log.ErrorFormat("[USER AGENT CONNECTOR]: remote call to {0} for GetOnlineFriends returned an error: {1}", m_ServerURL, response.FaultString);
  399. // reason = "XMLRPC Fault";
  400. return online;
  401. }
  402. hash = (Hashtable)response.Value;
  403. //foreach (Object o in hash)
  404. // m_log.Debug(">> " + ((DictionaryEntry)o).Key + ":" + ((DictionaryEntry)o).Value);
  405. try
  406. {
  407. if (hash == null)
  408. {
  409. m_log.ErrorFormat("[USER AGENT CONNECTOR]: GetOnlineFriends Got null response from {0}! THIS IS BAAAAD", m_ServerURL);
  410. // reason = "Internal error 1";
  411. return online;
  412. }
  413. // Here is the actual response
  414. foreach (object key in hash.Keys)
  415. {
  416. if (key is string && ((string)key).StartsWith("friend_") && hash[key] != null)
  417. {
  418. UUID uuid;
  419. if (UUID.TryParse(hash[key].ToString(), out uuid))
  420. online.Add(uuid);
  421. }
  422. }
  423. }
  424. catch
  425. {
  426. m_log.ErrorFormat("[USER AGENT CONNECTOR]: Got exception on GetOnlineFriends response.");
  427. // reason = "Exception: " + e.Message;
  428. }
  429. return online;
  430. }
  431. public Dictionary<string,object> GetUserInfo (UUID userID)
  432. {
  433. Hashtable hash = new Hashtable();
  434. hash["userID"] = userID.ToString();
  435. IList paramList = new ArrayList();
  436. paramList.Add(hash);
  437. XmlRpcRequest request = new XmlRpcRequest("get_user_info", paramList);
  438. Dictionary<string, object> info = new Dictionary<string, object>();
  439. XmlRpcResponse response = null;
  440. try
  441. {
  442. response = request.Send(m_ServerURL, 10000);
  443. }
  444. catch
  445. {
  446. m_log.DebugFormat("[USER AGENT CONNECTOR]: Unable to contact remote server {0} for GetUserInfo", m_ServerURL);
  447. return info;
  448. }
  449. if (response.IsFault)
  450. {
  451. m_log.ErrorFormat("[USER AGENT CONNECTOR]: remote call to {0} for GetServerURLs returned an error: {1}", m_ServerURL, response.FaultString);
  452. return info;
  453. }
  454. hash = (Hashtable)response.Value;
  455. try
  456. {
  457. if (hash == null)
  458. {
  459. m_log.ErrorFormat("[USER AGENT CONNECTOR]: GetUserInfo Got null response from {0}! THIS IS BAAAAD", m_ServerURL);
  460. return info;
  461. }
  462. // Here is the actual response
  463. foreach (object key in hash.Keys)
  464. {
  465. if (hash[key] != null)
  466. {
  467. info.Add(key.ToString(), hash[key]);
  468. }
  469. }
  470. }
  471. catch
  472. {
  473. m_log.ErrorFormat("[USER AGENT CONNECTOR]: Got exception on GetOnlineFriends response.");
  474. }
  475. return info;
  476. }
  477. public Dictionary<string, object> GetServerURLs(UUID userID)
  478. {
  479. Hashtable hash = new Hashtable();
  480. hash["userID"] = userID.ToString();
  481. IList paramList = new ArrayList();
  482. paramList.Add(hash);
  483. XmlRpcRequest request = new XmlRpcRequest("get_server_urls", paramList);
  484. // string reason = string.Empty;
  485. // Send and get reply
  486. Dictionary<string, object> serverURLs = new Dictionary<string,object>();
  487. XmlRpcResponse response = null;
  488. try
  489. {
  490. response = request.Send(m_ServerURL, 10000);
  491. }
  492. catch
  493. {
  494. m_log.DebugFormat("[USER AGENT CONNECTOR]: Unable to contact remote server {0} for GetServerURLs for user {1}", m_ServerURL, userID);
  495. // reason = "Exception: " + e.Message;
  496. return serverURLs;
  497. }
  498. if (response.IsFault)
  499. {
  500. m_log.ErrorFormat("[USER AGENT CONNECTOR]: remote call to {0} for GetServerURLs returned an error: {1}", m_ServerURL, response.FaultString);
  501. // reason = "XMLRPC Fault";
  502. return serverURLs;
  503. }
  504. hash = (Hashtable)response.Value;
  505. //foreach (Object o in hash)
  506. // m_log.Debug(">> " + ((DictionaryEntry)o).Key + ":" + ((DictionaryEntry)o).Value);
  507. try
  508. {
  509. if (hash == null)
  510. {
  511. m_log.ErrorFormat("[USER AGENT CONNECTOR]: GetServerURLs Got null response from {0}! THIS IS BAAAAD", m_ServerURL);
  512. // reason = "Internal error 1";
  513. return serverURLs;
  514. }
  515. // Here is the actual response
  516. foreach (object key in hash.Keys)
  517. {
  518. if (key is string && ((string)key).StartsWith("SRV_") && hash[key] != null)
  519. {
  520. string serverType = key.ToString().Substring(4); // remove "SRV_"
  521. serverURLs.Add(serverType, hash[key].ToString());
  522. }
  523. }
  524. }
  525. catch
  526. {
  527. m_log.ErrorFormat("[USER AGENT CONNECTOR]: Got exception on GetOnlineFriends response.");
  528. // reason = "Exception: " + e.Message;
  529. }
  530. return serverURLs;
  531. }
  532. public string LocateUser(UUID userID)
  533. {
  534. Hashtable hash = new Hashtable();
  535. hash["userID"] = userID.ToString();
  536. IList paramList = new ArrayList();
  537. paramList.Add(hash);
  538. XmlRpcRequest request = new XmlRpcRequest("locate_user", paramList);
  539. // string reason = string.Empty;
  540. // Send and get reply
  541. string url = string.Empty;
  542. XmlRpcResponse response = null;
  543. try
  544. {
  545. response = request.Send(m_ServerURL, 10000);
  546. }
  547. catch
  548. {
  549. m_log.DebugFormat("[USER AGENT CONNECTOR]: Unable to contact remote server {0} for LocateUser", m_ServerURL);
  550. // reason = "Exception: " + e.Message;
  551. return url;
  552. }
  553. if (response.IsFault)
  554. {
  555. m_log.ErrorFormat("[USER AGENT CONNECTOR]: remote call to {0} for LocateUser returned an error: {1}", m_ServerURL, response.FaultString);
  556. // reason = "XMLRPC Fault";
  557. return url;
  558. }
  559. hash = (Hashtable)response.Value;
  560. //foreach (Object o in hash)
  561. // m_log.Debug(">> " + ((DictionaryEntry)o).Key + ":" + ((DictionaryEntry)o).Value);
  562. try
  563. {
  564. if (hash == null)
  565. {
  566. m_log.ErrorFormat("[USER AGENT CONNECTOR]: LocateUser Got null response from {0}! THIS IS BAAAAD", m_ServerURL);
  567. // reason = "Internal error 1";
  568. return url;
  569. }
  570. // Here's the actual response
  571. if (hash.ContainsKey("URL"))
  572. url = hash["URL"].ToString();
  573. }
  574. catch
  575. {
  576. m_log.ErrorFormat("[USER AGENT CONNECTOR]: Got exception on LocateUser response.");
  577. // reason = "Exception: " + e.Message;
  578. }
  579. return url;
  580. }
  581. public string GetUUI(UUID userID, UUID targetUserID)
  582. {
  583. Hashtable hash = new Hashtable();
  584. hash["userID"] = userID.ToString();
  585. hash["targetUserID"] = targetUserID.ToString();
  586. IList paramList = new ArrayList();
  587. paramList.Add(hash);
  588. XmlRpcRequest request = new XmlRpcRequest("get_uui", paramList);
  589. // string reason = string.Empty;
  590. // Send and get reply
  591. string uui = string.Empty;
  592. XmlRpcResponse response = null;
  593. try
  594. {
  595. response = request.Send(m_ServerURL, 10000);
  596. }
  597. catch
  598. {
  599. m_log.DebugFormat("[USER AGENT CONNECTOR]: Unable to contact remote server {0} for GetUUI", m_ServerURL);
  600. // reason = "Exception: " + e.Message;
  601. return uui;
  602. }
  603. if (response.IsFault)
  604. {
  605. m_log.ErrorFormat("[USER AGENT CONNECTOR]: remote call to {0} for GetUUI returned an error: {1}", m_ServerURL, response.FaultString);
  606. // reason = "XMLRPC Fault";
  607. return uui;
  608. }
  609. hash = (Hashtable)response.Value;
  610. //foreach (Object o in hash)
  611. // m_log.Debug(">> " + ((DictionaryEntry)o).Key + ":" + ((DictionaryEntry)o).Value);
  612. try
  613. {
  614. if (hash == null)
  615. {
  616. m_log.ErrorFormat("[USER AGENT CONNECTOR]: GetUUI Got null response from {0}! THIS IS BAAAAD", m_ServerURL);
  617. // reason = "Internal error 1";
  618. return uui;
  619. }
  620. // Here's the actual response
  621. if (hash.ContainsKey("UUI"))
  622. uui = hash["UUI"].ToString();
  623. }
  624. catch
  625. {
  626. m_log.ErrorFormat("[USER AGENT CONNECTOR]: Got exception on GetUUI response.");
  627. // reason = "Exception: " + e.Message;
  628. }
  629. return uui;
  630. }
  631. public UUID GetUUID(String first, String last)
  632. {
  633. Hashtable hash = new Hashtable();
  634. hash["first"] = first;
  635. hash["last"] = last;
  636. IList paramList = new ArrayList();
  637. paramList.Add(hash);
  638. XmlRpcRequest request = new XmlRpcRequest("get_uuid", paramList);
  639. // string reason = string.Empty;
  640. // Send and get reply
  641. UUID uuid = UUID.Zero;
  642. XmlRpcResponse response = null;
  643. try
  644. {
  645. response = request.Send(m_ServerURL, 10000);
  646. }
  647. catch
  648. {
  649. m_log.DebugFormat("[USER AGENT CONNECTOR]: Unable to contact remote server {0} for GetUUID", m_ServerURL);
  650. // reason = "Exception: " + e.Message;
  651. return uuid;
  652. }
  653. if (response.IsFault)
  654. {
  655. m_log.ErrorFormat("[USER AGENT CONNECTOR]: remote call to {0} for GetUUID returned an error: {1}", m_ServerURL, response.FaultString);
  656. // reason = "XMLRPC Fault";
  657. return uuid;
  658. }
  659. hash = (Hashtable)response.Value;
  660. //foreach (Object o in hash)
  661. // m_log.Debug(">> " + ((DictionaryEntry)o).Key + ":" + ((DictionaryEntry)o).Value);
  662. try
  663. {
  664. if (hash == null)
  665. {
  666. m_log.ErrorFormat("[USER AGENT CONNECTOR]: GetUUDI Got null response from {0}! THIS IS BAAAAD", m_ServerURL);
  667. // reason = "Internal error 1";
  668. return uuid;
  669. }
  670. // Here's the actual response
  671. if (hash.ContainsKey("UUID"))
  672. UUID.TryParse(hash["UUID"].ToString(), out uuid);
  673. }
  674. catch
  675. {
  676. m_log.ErrorFormat("[USER AGENT CONNECTOR]: Got exception on UUID response.");
  677. // reason = "Exception: " + e.Message;
  678. }
  679. return uuid;
  680. }
  681. private bool GetBoolResponse(XmlRpcRequest request, out string reason)
  682. {
  683. //m_log.Debug("[USER AGENT CONNECTOR]: GetBoolResponse from/to " + m_ServerURL);
  684. XmlRpcResponse response = null;
  685. try
  686. {
  687. response = request.Send(m_ServerURL, 10000);
  688. }
  689. catch (Exception e)
  690. {
  691. m_log.DebugFormat("[USER AGENT CONNECTOR]: Unable to contact remote server {0} for GetBoolResponse", m_ServerURL);
  692. reason = "Exception: " + e.Message;
  693. return false;
  694. }
  695. if (response.IsFault)
  696. {
  697. m_log.ErrorFormat("[USER AGENT CONNECTOR]: remote call to {0} for GetBoolResponse returned an error: {1}", m_ServerURL, response.FaultString);
  698. reason = "XMLRPC Fault";
  699. return false;
  700. }
  701. Hashtable hash = (Hashtable)response.Value;
  702. //foreach (Object o in hash)
  703. // m_log.Debug(">> " + ((DictionaryEntry)o).Key + ":" + ((DictionaryEntry)o).Value);
  704. try
  705. {
  706. if (hash == null)
  707. {
  708. m_log.ErrorFormat("[USER AGENT CONNECTOR]: Got null response from {0}! THIS IS BAAAAD", m_ServerURL);
  709. reason = "Internal error 1";
  710. return false;
  711. }
  712. bool success = false;
  713. reason = string.Empty;
  714. if (hash.ContainsKey("result"))
  715. Boolean.TryParse((string)hash["result"], out success);
  716. else
  717. {
  718. reason = "Internal error 2";
  719. m_log.WarnFormat("[USER AGENT CONNECTOR]: response from {0} does not have expected key 'result'", m_ServerURL);
  720. }
  721. return success;
  722. }
  723. catch (Exception e)
  724. {
  725. m_log.ErrorFormat("[USER AGENT CONNECTOR]: Got exception on GetBoolResponse response.");
  726. if (hash.ContainsKey("result") && hash["result"] != null)
  727. m_log.ErrorFormat("Reply was ", (string)hash["result"]);
  728. reason = "Exception: " + e.Message;
  729. return false;
  730. }
  731. }
  732. }
  733. }