UserAgentService.cs 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580
  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.Generic;
  29. using System.Net;
  30. using System.Reflection;
  31. using OpenSim.Framework;
  32. using OpenSim.Services.Connectors.Friends;
  33. using OpenSim.Services.Connectors.Hypergrid;
  34. using OpenSim.Services.Interfaces;
  35. using GridRegion = OpenSim.Services.Interfaces.GridRegion;
  36. using OpenSim.Server.Base;
  37. using FriendInfo = OpenSim.Services.Interfaces.FriendInfo;
  38. using OpenMetaverse;
  39. using log4net;
  40. using Nini.Config;
  41. namespace OpenSim.Services.HypergridService
  42. {
  43. /// <summary>
  44. /// This service is for HG1.5 only, to make up for the fact that clients don't
  45. /// keep any private information in themselves, and that their 'home service'
  46. /// needs to do it for them.
  47. /// Once we have better clients, this shouldn't be needed.
  48. /// </summary>
  49. public class UserAgentService : IUserAgentService
  50. {
  51. private static readonly ILog m_log =
  52. LogManager.GetLogger(
  53. MethodBase.GetCurrentMethod().DeclaringType);
  54. // This will need to go into a DB table
  55. static Dictionary<UUID, TravelingAgentInfo> m_TravelingAgents = new Dictionary<UUID, TravelingAgentInfo>();
  56. static bool m_Initialized = false;
  57. protected static IGridUserService m_GridUserService;
  58. protected static IGridService m_GridService;
  59. protected static GatekeeperServiceConnector m_GatekeeperConnector;
  60. protected static IGatekeeperService m_GatekeeperService;
  61. protected static IFriendsService m_FriendsService;
  62. protected static IPresenceService m_PresenceService;
  63. protected static IUserAccountService m_UserAccountService;
  64. protected static IFriendsSimConnector m_FriendsLocalSimConnector; // standalone, points to HGFriendsModule
  65. protected static FriendsSimConnector m_FriendsSimConnector; // grid
  66. protected static string m_GridName;
  67. protected static bool m_BypassClientVerification;
  68. public UserAgentService(IConfigSource config) : this(config, null)
  69. {
  70. }
  71. public UserAgentService(IConfigSource config, IFriendsSimConnector friendsConnector)
  72. {
  73. // Let's set this always, because we don't know the sequence
  74. // of instantiations
  75. if (friendsConnector != null)
  76. m_FriendsLocalSimConnector = friendsConnector;
  77. if (!m_Initialized)
  78. {
  79. m_Initialized = true;
  80. m_log.DebugFormat("[HOME USERS SECURITY]: Starting...");
  81. m_FriendsSimConnector = new FriendsSimConnector();
  82. IConfig serverConfig = config.Configs["UserAgentService"];
  83. if (serverConfig == null)
  84. throw new Exception(String.Format("No section UserAgentService in config file"));
  85. string gridService = serverConfig.GetString("GridService", String.Empty);
  86. string gridUserService = serverConfig.GetString("GridUserService", String.Empty);
  87. string gatekeeperService = serverConfig.GetString("GatekeeperService", String.Empty);
  88. string friendsService = serverConfig.GetString("FriendsService", String.Empty);
  89. string presenceService = serverConfig.GetString("PresenceService", String.Empty);
  90. string userAccountService = serverConfig.GetString("UserAccountService", String.Empty);
  91. m_BypassClientVerification = serverConfig.GetBoolean("BypassClientVerification", false);
  92. if (gridService == string.Empty || gridUserService == string.Empty || gatekeeperService == string.Empty)
  93. throw new Exception(String.Format("Incomplete specifications, UserAgent Service cannot function."));
  94. Object[] args = new Object[] { config };
  95. m_GridService = ServerUtils.LoadPlugin<IGridService>(gridService, args);
  96. m_GridUserService = ServerUtils.LoadPlugin<IGridUserService>(gridUserService, args);
  97. m_GatekeeperConnector = new GatekeeperServiceConnector();
  98. m_GatekeeperService = ServerUtils.LoadPlugin<IGatekeeperService>(gatekeeperService, args);
  99. m_FriendsService = ServerUtils.LoadPlugin<IFriendsService>(friendsService, args);
  100. m_PresenceService = ServerUtils.LoadPlugin<IPresenceService>(presenceService, args);
  101. m_UserAccountService = ServerUtils.LoadPlugin<IUserAccountService>(userAccountService, args);
  102. m_GridName = serverConfig.GetString("ExternalName", string.Empty);
  103. if (m_GridName == string.Empty)
  104. {
  105. serverConfig = config.Configs["GatekeeperService"];
  106. m_GridName = serverConfig.GetString("ExternalName", string.Empty);
  107. }
  108. if (!m_GridName.EndsWith("/"))
  109. m_GridName = m_GridName + "/";
  110. }
  111. }
  112. public GridRegion GetHomeRegion(UUID userID, out Vector3 position, out Vector3 lookAt)
  113. {
  114. position = new Vector3(128, 128, 0); lookAt = Vector3.UnitY;
  115. m_log.DebugFormat("[USER AGENT SERVICE]: Request to get home region of user {0}", userID);
  116. GridRegion home = null;
  117. GridUserInfo uinfo = m_GridUserService.GetGridUserInfo(userID.ToString());
  118. if (uinfo != null)
  119. {
  120. if (uinfo.HomeRegionID != UUID.Zero)
  121. {
  122. home = m_GridService.GetRegionByUUID(UUID.Zero, uinfo.HomeRegionID);
  123. position = uinfo.HomePosition;
  124. lookAt = uinfo.HomeLookAt;
  125. }
  126. if (home == null)
  127. {
  128. List<GridRegion> defs = m_GridService.GetDefaultRegions(UUID.Zero);
  129. if (defs != null && defs.Count > 0)
  130. home = defs[0];
  131. }
  132. }
  133. return home;
  134. }
  135. public bool LoginAgentToGrid(AgentCircuitData agentCircuit, GridRegion gatekeeper, GridRegion finalDestination, IPEndPoint clientIP, out string reason)
  136. {
  137. m_log.DebugFormat("[USER AGENT SERVICE]: Request to login user {0} {1} (@{2}) to grid {3}",
  138. agentCircuit.firstname, agentCircuit.lastname, ((clientIP == null) ? "stored IP" : clientIP.Address.ToString()), gatekeeper.ServerURI);
  139. if (m_UserAccountService.GetUserAccount(UUID.Zero, agentCircuit.AgentID) == null)
  140. {
  141. m_log.WarnFormat("[USER AGENT SERVICE]: Someone attempted to lauch a foreign user from here {0} {1}", agentCircuit.firstname, agentCircuit.lastname);
  142. reason = "Forbidden to launch your agents from here";
  143. return false;
  144. }
  145. // Take the IP address + port of the gatekeeper (reg) plus the info of finalDestination
  146. GridRegion region = new GridRegion(gatekeeper);
  147. region.ServerURI = gatekeeper.ServerURI;
  148. region.ExternalHostName = finalDestination.ExternalHostName;
  149. region.InternalEndPoint = finalDestination.InternalEndPoint;
  150. region.RegionName = finalDestination.RegionName;
  151. region.RegionID = finalDestination.RegionID;
  152. region.RegionLocX = finalDestination.RegionLocX;
  153. region.RegionLocY = finalDestination.RegionLocY;
  154. // Generate a new service session
  155. agentCircuit.ServiceSessionID = region.ServerURI + ";" + UUID.Random();
  156. TravelingAgentInfo old = UpdateTravelInfo(agentCircuit, region);
  157. bool success = false;
  158. string myExternalIP = string.Empty;
  159. string gridName = gatekeeper.ServerURI;
  160. m_log.DebugFormat("[USER AGENT SERVICE]: this grid: {0}, desired grid: {1}", m_GridName, gridName);
  161. if (m_GridName == gridName)
  162. success = m_GatekeeperService.LoginAgent(agentCircuit, finalDestination, out reason);
  163. else
  164. {
  165. success = m_GatekeeperConnector.CreateAgent(region, agentCircuit, (uint)Constants.TeleportFlags.ViaLogin, out myExternalIP, out reason);
  166. if (success)
  167. // Report them as nowhere
  168. m_PresenceService.ReportAgent(agentCircuit.SessionID, UUID.Zero);
  169. }
  170. if (!success)
  171. {
  172. m_log.DebugFormat("[USER AGENT SERVICE]: Unable to login user {0} {1} to grid {2}, reason: {3}",
  173. agentCircuit.firstname, agentCircuit.lastname, region.ServerURI, reason);
  174. // restore the old travel info
  175. lock (m_TravelingAgents)
  176. {
  177. if (old == null)
  178. m_TravelingAgents.Remove(agentCircuit.SessionID);
  179. else
  180. m_TravelingAgents[agentCircuit.SessionID] = old;
  181. }
  182. return false;
  183. }
  184. m_log.DebugFormat("[USER AGENT SERVICE]: Gatekeeper sees me as {0}", myExternalIP);
  185. // else set the IP addresses associated with this client
  186. if (clientIP != null)
  187. m_TravelingAgents[agentCircuit.SessionID].ClientIPAddress = clientIP.Address.ToString();
  188. m_TravelingAgents[agentCircuit.SessionID].MyIpAddress = myExternalIP;
  189. return true;
  190. }
  191. public bool LoginAgentToGrid(AgentCircuitData agentCircuit, GridRegion gatekeeper, GridRegion finalDestination, out string reason)
  192. {
  193. reason = string.Empty;
  194. return LoginAgentToGrid(agentCircuit, gatekeeper, finalDestination, null, out reason);
  195. }
  196. private void SetClientIP(UUID sessionID, string ip)
  197. {
  198. if (m_TravelingAgents.ContainsKey(sessionID))
  199. {
  200. m_log.DebugFormat("[USER AGENT SERVICE]: Setting IP {0} for session {1}", ip, sessionID);
  201. m_TravelingAgents[sessionID].ClientIPAddress = ip;
  202. }
  203. }
  204. TravelingAgentInfo UpdateTravelInfo(AgentCircuitData agentCircuit, GridRegion region)
  205. {
  206. TravelingAgentInfo travel = new TravelingAgentInfo();
  207. TravelingAgentInfo old = null;
  208. lock (m_TravelingAgents)
  209. {
  210. if (m_TravelingAgents.ContainsKey(agentCircuit.SessionID))
  211. {
  212. // Very important! Override whatever this agent comes with.
  213. // UserAgentService always sets the IP for every new agent
  214. // with the original IP address.
  215. agentCircuit.IPAddress = m_TravelingAgents[agentCircuit.SessionID].ClientIPAddress;
  216. old = m_TravelingAgents[agentCircuit.SessionID];
  217. }
  218. m_TravelingAgents[agentCircuit.SessionID] = travel;
  219. }
  220. travel.UserID = agentCircuit.AgentID;
  221. travel.GridExternalName = region.ServerURI;
  222. travel.ServiceToken = agentCircuit.ServiceSessionID;
  223. if (old != null)
  224. travel.ClientIPAddress = old.ClientIPAddress;
  225. return old;
  226. }
  227. public void LogoutAgent(UUID userID, UUID sessionID)
  228. {
  229. m_log.DebugFormat("[USER AGENT SERVICE]: User {0} logged out", userID);
  230. lock (m_TravelingAgents)
  231. {
  232. List<UUID> travels = new List<UUID>();
  233. foreach (KeyValuePair<UUID, TravelingAgentInfo> kvp in m_TravelingAgents)
  234. if (kvp.Value == null) // do some clean up
  235. travels.Add(kvp.Key);
  236. else if (kvp.Value.UserID == userID)
  237. travels.Add(kvp.Key);
  238. foreach (UUID session in travels)
  239. m_TravelingAgents.Remove(session);
  240. }
  241. GridUserInfo guinfo = m_GridUserService.GetGridUserInfo(userID.ToString());
  242. if (guinfo != null)
  243. m_GridUserService.LoggedOut(userID.ToString(), sessionID, guinfo.LastRegionID, guinfo.LastPosition, guinfo.LastLookAt);
  244. }
  245. // We need to prevent foreign users with the same UUID as a local user
  246. public bool IsAgentComingHome(UUID sessionID, string thisGridExternalName)
  247. {
  248. if (!m_TravelingAgents.ContainsKey(sessionID))
  249. return false;
  250. TravelingAgentInfo travel = m_TravelingAgents[sessionID];
  251. return travel.GridExternalName.ToLower() == thisGridExternalName.ToLower();
  252. }
  253. public bool VerifyClient(UUID sessionID, string reportedIP)
  254. {
  255. if (m_BypassClientVerification)
  256. return true;
  257. m_log.DebugFormat("[USER AGENT SERVICE]: Verifying Client session {0} with reported IP {1}.",
  258. sessionID, reportedIP);
  259. if (m_TravelingAgents.ContainsKey(sessionID))
  260. {
  261. bool result = m_TravelingAgents[sessionID].ClientIPAddress == reportedIP ||
  262. m_TravelingAgents[sessionID].MyIpAddress == reportedIP; // NATed
  263. m_log.DebugFormat("[USER AGENT SERVICE]: Comparing {0} with login IP {1} and MyIP {1}; result is {3}",
  264. reportedIP, m_TravelingAgents[sessionID].ClientIPAddress, m_TravelingAgents[sessionID].MyIpAddress, result);
  265. return result;
  266. }
  267. return false;
  268. }
  269. public bool VerifyAgent(UUID sessionID, string token)
  270. {
  271. if (m_TravelingAgents.ContainsKey(sessionID))
  272. {
  273. m_log.DebugFormat("[USER AGENT SERVICE]: Verifying agent token {0} against {1}", token, m_TravelingAgents[sessionID].ServiceToken);
  274. return m_TravelingAgents[sessionID].ServiceToken == token;
  275. }
  276. m_log.DebugFormat("[USER AGENT SERVICE]: Token verification for session {0}: no such session", sessionID);
  277. return false;
  278. }
  279. public List<UUID> StatusNotification(List<string> friends, UUID foreignUserID, bool online)
  280. {
  281. if (m_FriendsService == null || m_PresenceService == null)
  282. {
  283. m_log.WarnFormat("[USER AGENT SERVICE]: Unable to perform status notifications because friends or presence services are missing");
  284. return new List<UUID>();
  285. }
  286. List<UUID> localFriendsOnline = new List<UUID>();
  287. m_log.DebugFormat("[USER AGENT SERVICE]: Status notification: foreign user {0} wants to notify {1} local friends", foreignUserID, friends.Count);
  288. // First, let's double check that the reported friends are, indeed, friends of that user
  289. // And let's check that the secret matches
  290. List<string> usersToBeNotified = new List<string>();
  291. foreach (string uui in friends)
  292. {
  293. UUID localUserID;
  294. string secret = string.Empty, tmp = string.Empty;
  295. if (Util.ParseUniversalUserIdentifier(uui, out localUserID, out tmp, out tmp, out tmp, out secret))
  296. {
  297. FriendInfo[] friendInfos = m_FriendsService.GetFriends(localUserID);
  298. foreach (FriendInfo finfo in friendInfos)
  299. {
  300. if (finfo.Friend.StartsWith(foreignUserID.ToString()) && finfo.Friend.EndsWith(secret))
  301. {
  302. // great!
  303. usersToBeNotified.Add(localUserID.ToString());
  304. }
  305. }
  306. }
  307. }
  308. // Now, let's send the notifications
  309. m_log.DebugFormat("[USER AGENT SERVICE]: Status notification: user has {0} local friends", usersToBeNotified.Count);
  310. // First, let's send notifications to local users who are online in the home grid
  311. PresenceInfo[] friendSessions = m_PresenceService.GetAgents(usersToBeNotified.ToArray());
  312. if (friendSessions != null && friendSessions.Length > 0)
  313. {
  314. PresenceInfo friendSession = null;
  315. foreach (PresenceInfo pinfo in friendSessions)
  316. if (pinfo.RegionID != UUID.Zero) // let's guard against traveling agents
  317. {
  318. friendSession = pinfo;
  319. break;
  320. }
  321. if (friendSession != null)
  322. {
  323. ForwardStatusNotificationToSim(friendSession.RegionID, foreignUserID, friendSession.UserID, online);
  324. usersToBeNotified.Remove(friendSession.UserID.ToString());
  325. UUID id;
  326. if (UUID.TryParse(friendSession.UserID, out id))
  327. localFriendsOnline.Add(id);
  328. }
  329. }
  330. // Lastly, let's notify the rest who may be online somewhere else
  331. foreach (string user in usersToBeNotified)
  332. {
  333. UUID id = new UUID(user);
  334. if (m_TravelingAgents.ContainsKey(id) && m_TravelingAgents[id].GridExternalName != m_GridName)
  335. {
  336. string url = m_TravelingAgents[id].GridExternalName;
  337. // forward
  338. m_log.WarnFormat("[USER AGENT SERVICE]: User {0} is visiting {1}. HG Status notifications still not implemented.", user, url);
  339. }
  340. }
  341. // and finally, let's send the online friends
  342. if (online)
  343. {
  344. return localFriendsOnline;
  345. }
  346. else
  347. return new List<UUID>();
  348. }
  349. protected void ForwardStatusNotificationToSim(UUID regionID, UUID foreignUserID, string user, bool online)
  350. {
  351. UUID userID;
  352. if (UUID.TryParse(user, out userID))
  353. {
  354. if (m_FriendsLocalSimConnector != null)
  355. {
  356. m_log.DebugFormat("[USER AGENT SERVICE]: Local Notify, user {0} is {1}", foreignUserID, (online ? "online" : "offline"));
  357. m_FriendsLocalSimConnector.StatusNotify(foreignUserID, userID, online);
  358. }
  359. else
  360. {
  361. GridRegion region = m_GridService.GetRegionByUUID(UUID.Zero /* !!! */, regionID);
  362. if (region != null)
  363. {
  364. m_log.DebugFormat("[USER AGENT SERVICE]: Remote Notify to region {0}, user {1} is {2}", region.RegionName, foreignUserID, (online ? "online" : "offline"));
  365. m_FriendsSimConnector.StatusNotify(region, foreignUserID, userID, online);
  366. }
  367. }
  368. }
  369. }
  370. public List<UUID> GetOnlineFriends(UUID foreignUserID, List<string> friends)
  371. {
  372. List<UUID> online = new List<UUID>();
  373. if (m_FriendsService == null || m_PresenceService == null)
  374. {
  375. m_log.WarnFormat("[USER AGENT SERVICE]: Unable to get online friends because friends or presence services are missing");
  376. return online;
  377. }
  378. m_log.DebugFormat("[USER AGENT SERVICE]: Foreign user {0} wants to know status of {1} local friends", foreignUserID, friends.Count);
  379. // First, let's double check that the reported friends are, indeed, friends of that user
  380. // And let's check that the secret matches and the rights
  381. List<string> usersToBeNotified = new List<string>();
  382. foreach (string uui in friends)
  383. {
  384. UUID localUserID;
  385. string secret = string.Empty, tmp = string.Empty;
  386. if (Util.ParseUniversalUserIdentifier(uui, out localUserID, out tmp, out tmp, out tmp, out secret))
  387. {
  388. FriendInfo[] friendInfos = m_FriendsService.GetFriends(localUserID);
  389. foreach (FriendInfo finfo in friendInfos)
  390. {
  391. if (finfo.Friend.StartsWith(foreignUserID.ToString()) && finfo.Friend.EndsWith(secret) &&
  392. (finfo.TheirFlags & (int)FriendRights.CanSeeOnline) != 0 && (finfo.TheirFlags != -1))
  393. {
  394. // great!
  395. usersToBeNotified.Add(localUserID.ToString());
  396. }
  397. }
  398. }
  399. }
  400. // Now, let's find out their status
  401. m_log.DebugFormat("[USER AGENT SERVICE]: GetOnlineFriends: user has {0} local friends with status rights", usersToBeNotified.Count);
  402. // First, let's send notifications to local users who are online in the home grid
  403. PresenceInfo[] friendSessions = m_PresenceService.GetAgents(usersToBeNotified.ToArray());
  404. if (friendSessions != null && friendSessions.Length > 0)
  405. {
  406. foreach (PresenceInfo pi in friendSessions)
  407. {
  408. UUID presenceID;
  409. if (UUID.TryParse(pi.UserID, out presenceID))
  410. online.Add(presenceID);
  411. }
  412. }
  413. return online;
  414. }
  415. public Dictionary<string, object> GetUserInfo(UUID userID)
  416. {
  417. Dictionary<string, object> info = new Dictionary<string, object>();
  418. if (m_UserAccountService == null)
  419. {
  420. m_log.WarnFormat("[USER AGENT SERVICE]: Unable to get user flags because user account service is missing");
  421. info["result"] = "fail";
  422. info["message"] = "UserAccountService is missing!";
  423. return info;
  424. }
  425. UserAccount account = m_UserAccountService.GetUserAccount(UUID.Zero /*!!!*/, userID);
  426. if (account != null)
  427. {
  428. info.Add("user_flags", (object)account.UserFlags);
  429. info.Add("user_created", (object)account.Created);
  430. info.Add("user_title", (object)account.UserTitle);
  431. info.Add("result", "success");
  432. }
  433. return info;
  434. }
  435. public Dictionary<string, object> GetServerURLs(UUID userID)
  436. {
  437. if (m_UserAccountService == null)
  438. {
  439. m_log.WarnFormat("[USER AGENT SERVICE]: Unable to get server URLs because user account service is missing");
  440. return new Dictionary<string, object>();
  441. }
  442. UserAccount account = m_UserAccountService.GetUserAccount(UUID.Zero /*!!!*/, userID);
  443. if (account != null)
  444. return account.ServiceURLs;
  445. return new Dictionary<string, object>();
  446. }
  447. public string LocateUser(UUID userID)
  448. {
  449. foreach (TravelingAgentInfo t in m_TravelingAgents.Values)
  450. {
  451. if (t == null)
  452. {
  453. m_log.ErrorFormat("[USER AGENT SERVICE]: Oops! Null TravelingAgentInfo. Please report this on mantis");
  454. continue;
  455. }
  456. if (t.UserID == userID && !m_GridName.Equals(t.GridExternalName))
  457. return t.GridExternalName;
  458. }
  459. return string.Empty;
  460. }
  461. public string GetUUI(UUID userID, UUID targetUserID)
  462. {
  463. // Let's see if it's a local user
  464. UserAccount account = m_UserAccountService.GetUserAccount(UUID.Zero, targetUserID);
  465. if (account != null)
  466. return targetUserID.ToString() + ";" + m_GridName + ";" + account.FirstName + " " + account.LastName ;
  467. // Let's try the list of friends
  468. FriendInfo[] friends = m_FriendsService.GetFriends(userID);
  469. if (friends != null && friends.Length > 0)
  470. {
  471. foreach (FriendInfo f in friends)
  472. if (f.Friend.StartsWith(targetUserID.ToString()))
  473. {
  474. // Let's remove the secret
  475. UUID id; string tmp = string.Empty, secret = string.Empty;
  476. if (Util.ParseUniversalUserIdentifier(f.Friend, out id, out tmp, out tmp, out tmp, out secret))
  477. return f.Friend.Replace(secret, "0");
  478. }
  479. }
  480. return string.Empty;
  481. }
  482. }
  483. class TravelingAgentInfo
  484. {
  485. public UUID UserID;
  486. public string GridExternalName = string.Empty;
  487. public string ServiceToken = string.Empty;
  488. public string ClientIPAddress = string.Empty; // as seen from this user agent service
  489. public string MyIpAddress = string.Empty; // the user agent service's external IP, as seen from the next gatekeeper
  490. }
  491. }