HGFriendsModule.cs 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623
  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.Reflection;
  31. using System.Threading;
  32. using log4net;
  33. using Nini.Config;
  34. using Nwc.XmlRpc;
  35. using Mono.Addins;
  36. using OpenMetaverse;
  37. using OpenSim.Framework;
  38. using OpenSim.Region.Framework.Interfaces;
  39. using OpenSim.Region.Framework.Scenes;
  40. using OpenSim.Services.Interfaces;
  41. using OpenSim.Services.Connectors.Hypergrid;
  42. using FriendInfo = OpenSim.Services.Interfaces.FriendInfo;
  43. using PresenceInfo = OpenSim.Services.Interfaces.PresenceInfo;
  44. using GridRegion = OpenSim.Services.Interfaces.GridRegion;
  45. namespace OpenSim.Region.CoreModules.Avatar.Friends
  46. {
  47. public class HGFriendsModule : FriendsModule, ISharedRegionModule, IFriendsModule, IFriendsSimConnector
  48. {
  49. private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
  50. #region ISharedRegionModule
  51. public override string Name
  52. {
  53. get { return "HGFriendsModule"; }
  54. }
  55. public override void AddRegion(Scene scene)
  56. {
  57. if (!m_Enabled)
  58. return;
  59. base.AddRegion(scene);
  60. scene.RegisterModuleInterface<IFriendsSimConnector>(this);
  61. }
  62. #endregion
  63. #region IFriendsSimConnector
  64. /// <summary>
  65. /// Notify the user that the friend's status changed
  66. /// </summary>
  67. /// <param name="userID">user to be notified</param>
  68. /// <param name="friendID">friend whose status changed</param>
  69. /// <param name="online">status</param>
  70. /// <returns></returns>
  71. public bool StatusNotify(UUID friendID, UUID userID, bool online)
  72. {
  73. return LocalStatusNotification(friendID, userID, online);
  74. }
  75. #endregion
  76. protected override bool FetchFriendslist(IClientAPI client)
  77. {
  78. if (base.FetchFriendslist(client))
  79. {
  80. UUID agentID = client.AgentId;
  81. // we do this only for the root agent
  82. if (m_Friends[agentID].Refcount == 1)
  83. {
  84. // We need to preload the user management cache with the names
  85. // of foreign friends, just like we do with SOPs' creators
  86. foreach (FriendInfo finfo in m_Friends[agentID].Friends)
  87. {
  88. if (finfo.TheirFlags != -1)
  89. {
  90. UUID id;
  91. if (!UUID.TryParse(finfo.Friend, out id))
  92. {
  93. string url = string.Empty, first = string.Empty, last = string.Empty, tmp = string.Empty;
  94. if (Util.ParseUniversalUserIdentifier(finfo.Friend, out id, out url, out first, out last, out tmp))
  95. {
  96. IUserManagement uMan = m_Scenes[0].RequestModuleInterface<IUserManagement>();
  97. uMan.AddUser(id, url + ";" + first + " " + last);
  98. }
  99. }
  100. }
  101. }
  102. return true;
  103. }
  104. }
  105. return false;
  106. }
  107. public override bool SendFriendsOnlineIfNeeded(IClientAPI client)
  108. {
  109. if (base.SendFriendsOnlineIfNeeded(client))
  110. {
  111. AgentCircuitData aCircuit = ((Scene)client.Scene).AuthenticateHandler.GetAgentCircuitData(client.AgentId);
  112. if (aCircuit != null && (aCircuit.teleportFlags & (uint)Constants.TeleportFlags.ViaHGLogin) != 0)
  113. {
  114. UserAccount account = m_Scenes[0].UserAccountService.GetUserAccount(client.Scene.RegionInfo.ScopeID, client.AgentId);
  115. if (account == null) // foreign
  116. {
  117. FriendInfo[] friends = GetFriends(client.AgentId);
  118. foreach (FriendInfo f in friends)
  119. {
  120. client.SendChangeUserRights(new UUID(f.Friend), client.AgentId, f.TheirFlags);
  121. }
  122. }
  123. }
  124. }
  125. return false;
  126. }
  127. protected override void GetOnlineFriends(UUID userID, List<string> friendList, /*collector*/ List<UUID> online)
  128. {
  129. List<string> fList = new List<string>();
  130. foreach (string s in friendList)
  131. fList.Add(s.Substring(0, 36));
  132. PresenceInfo[] presence = PresenceService.GetAgents(fList.ToArray());
  133. foreach (PresenceInfo pi in presence)
  134. {
  135. UUID presenceID;
  136. if (UUID.TryParse(pi.UserID, out presenceID))
  137. online.Add(presenceID);
  138. }
  139. }
  140. //protected override void GetOnlineFriends(UUID userID, List<string> friendList, /*collector*/ List<UUID> online)
  141. //{
  142. // // Let's single out the UUIs
  143. // List<string> localFriends = new List<string>();
  144. // List<string> foreignFriends = new List<string>();
  145. // string tmp = string.Empty;
  146. // foreach (string s in friendList)
  147. // {
  148. // UUID id;
  149. // if (UUID.TryParse(s, out id))
  150. // localFriends.Add(s);
  151. // else if (Util.ParseUniversalUserIdentifier(s, out id, out tmp, out tmp, out tmp, out tmp))
  152. // {
  153. // foreignFriends.Add(s);
  154. // // add it here too, who knows maybe the foreign friends happens to be on this grid
  155. // localFriends.Add(id.ToString());
  156. // }
  157. // }
  158. // // OK, see who's present on this grid
  159. // List<string> toBeRemoved = new List<string>();
  160. // PresenceInfo[] presence = PresenceService.GetAgents(localFriends.ToArray());
  161. // foreach (PresenceInfo pi in presence)
  162. // {
  163. // UUID presenceID;
  164. // if (UUID.TryParse(pi.UserID, out presenceID))
  165. // {
  166. // online.Add(presenceID);
  167. // foreach (string s in foreignFriends)
  168. // if (s.StartsWith(pi.UserID))
  169. // toBeRemoved.Add(s);
  170. // }
  171. // }
  172. // foreach (string s in toBeRemoved)
  173. // foreignFriends.Remove(s);
  174. // // OK, let's send this up the stack, and leave a closure here
  175. // // collecting online friends in other grids
  176. // Util.FireAndForget(delegate { CollectOnlineFriendsElsewhere(userID, foreignFriends); });
  177. //}
  178. //private void CollectOnlineFriendsElsewhere(UUID userID, List<string> foreignFriends)
  179. //{
  180. // // let's divide the friends on a per-domain basis
  181. // Dictionary<string, List<string>> friendsPerDomain = new Dictionary<string, List<string>>();
  182. // foreach (string friend in foreignFriends)
  183. // {
  184. // UUID friendID;
  185. // if (!UUID.TryParse(friend, out friendID))
  186. // {
  187. // // it's a foreign friend
  188. // string url = string.Empty, tmp = string.Empty;
  189. // if (Util.ParseUniversalUserIdentifier(friend, out friendID, out url, out tmp, out tmp, out tmp))
  190. // {
  191. // if (!friendsPerDomain.ContainsKey(url))
  192. // friendsPerDomain[url] = new List<string>();
  193. // friendsPerDomain[url].Add(friend);
  194. // }
  195. // }
  196. // }
  197. // // Now, call those worlds
  198. // foreach (KeyValuePair<string, List<string>> kvp in friendsPerDomain)
  199. // {
  200. // List<string> ids = new List<string>();
  201. // foreach (string f in kvp.Value)
  202. // ids.Add(f);
  203. // UserAgentServiceConnector uConn = new UserAgentServiceConnector(kvp.Key);
  204. // List<UUID> online = uConn.GetOnlineFriends(userID, ids);
  205. // // Finally send the notifications to the user
  206. // // this whole process may take a while, so let's check at every
  207. // // iteration that the user is still here
  208. // IClientAPI client = LocateClientObject(userID);
  209. // if (client != null)
  210. // client.SendAgentOnline(online.ToArray());
  211. // else
  212. // break;
  213. // }
  214. //}
  215. protected override void StatusNotify(List<FriendInfo> friendList, UUID userID, bool online)
  216. {
  217. // First, let's divide the friends on a per-domain basis
  218. Dictionary<string, List<FriendInfo>> friendsPerDomain = new Dictionary<string, List<FriendInfo>>();
  219. foreach (FriendInfo friend in friendList)
  220. {
  221. UUID friendID;
  222. if (UUID.TryParse(friend.Friend, out friendID))
  223. {
  224. if (!friendsPerDomain.ContainsKey("local"))
  225. friendsPerDomain["local"] = new List<FriendInfo>();
  226. friendsPerDomain["local"].Add(friend);
  227. }
  228. else
  229. {
  230. // it's a foreign friend
  231. string url = string.Empty, tmp = string.Empty;
  232. if (Util.ParseUniversalUserIdentifier(friend.Friend, out friendID, out url, out tmp, out tmp, out tmp))
  233. {
  234. // Let's try our luck in the local sim. Who knows, maybe it's here
  235. if (LocalStatusNotification(userID, friendID, online))
  236. continue;
  237. if (!friendsPerDomain.ContainsKey(url))
  238. friendsPerDomain[url] = new List<FriendInfo>();
  239. friendsPerDomain[url].Add(friend);
  240. }
  241. }
  242. }
  243. // For the local friends, just call the base method
  244. // Let's do this first of all
  245. if (friendsPerDomain.ContainsKey("local"))
  246. base.StatusNotify(friendsPerDomain["local"], userID, online);
  247. foreach (KeyValuePair<string, List<FriendInfo>> kvp in friendsPerDomain)
  248. {
  249. if (kvp.Key != "local")
  250. {
  251. // For the others, call the user agent service
  252. List<string> ids = new List<string>();
  253. foreach (FriendInfo f in kvp.Value)
  254. ids.Add(f.Friend);
  255. UserAgentServiceConnector uConn = new UserAgentServiceConnector(kvp.Key);
  256. List<UUID> friendsOnline = uConn.StatusNotification(ids, userID, online);
  257. if (online && friendsOnline.Count > 0)
  258. {
  259. IClientAPI client = LocateClientObject(userID);
  260. if (client != null)
  261. client.SendAgentOnline(friendsOnline.ToArray());
  262. }
  263. }
  264. }
  265. }
  266. protected override bool GetAgentInfo(UUID scopeID, string fid, out UUID agentID, out string first, out string last)
  267. {
  268. first = "Unknown"; last = "User";
  269. if (base.GetAgentInfo(scopeID, fid, out agentID, out first, out last))
  270. return true;
  271. // fid is not a UUID...
  272. string url = string.Empty, tmp = string.Empty;
  273. if (Util.ParseUniversalUserIdentifier(fid, out agentID, out url, out first, out last, out tmp))
  274. {
  275. IUserManagement userMan = m_Scenes[0].RequestModuleInterface<IUserManagement>();
  276. userMan.AddUser(agentID, first, last, url);
  277. return true;
  278. }
  279. return false;
  280. }
  281. protected override string GetFriendshipRequesterName(UUID agentID)
  282. {
  283. // For the time being we assume that HG friendship requests can only happen
  284. // when avies are on the same region.
  285. IClientAPI client = LocateClientObject(agentID);
  286. if (client != null)
  287. return client.FirstName + " " + client.LastName;
  288. else
  289. return base.GetFriendshipRequesterName(agentID);
  290. }
  291. protected override string FriendshipMessage(string friendID)
  292. {
  293. UUID id;
  294. if (UUID.TryParse(friendID, out id))
  295. return base.FriendshipMessage(friendID);
  296. return "Please confirm this friendship you made while you were away.";
  297. }
  298. protected override FriendInfo GetFriend(FriendInfo[] friends, UUID friendID)
  299. {
  300. foreach (FriendInfo fi in friends)
  301. {
  302. if (fi.Friend.StartsWith(friendID.ToString()))
  303. return fi;
  304. }
  305. return null;
  306. }
  307. protected override FriendInfo[] GetFriendsFromService(IClientAPI client)
  308. {
  309. UserAccount account1 = UserAccountService.GetUserAccount(m_Scenes[0].RegionInfo.ScopeID, client.AgentId);
  310. if (account1 != null)
  311. return base.GetFriendsFromService(client);
  312. FriendInfo[] finfos = new FriendInfo[0];
  313. // Foreigner
  314. AgentCircuitData agentClientCircuit = ((Scene)(client.Scene)).AuthenticateHandler.GetAgentCircuitData(client.CircuitCode);
  315. if (agentClientCircuit != null)
  316. {
  317. string agentUUI = Util.ProduceUserUniversalIdentifier(agentClientCircuit);
  318. finfos = FriendsService.GetFriends(agentUUI);
  319. m_log.DebugFormat("[HGFRIENDS MODULE]: Fetched {0} local friends for visitor {1}", finfos.Length, agentUUI);
  320. }
  321. return finfos;
  322. }
  323. protected override bool StoreRights(UUID agentID, UUID friendID, int rights)
  324. {
  325. UserAccount account1 = UserAccountService.GetUserAccount(m_Scenes[0].RegionInfo.ScopeID, agentID);
  326. UserAccount account2 = UserAccountService.GetUserAccount(m_Scenes[0].RegionInfo.ScopeID, friendID);
  327. // Are they both local users?
  328. if (account1 != null && account2 != null)
  329. {
  330. // local grid users
  331. return base.StoreRights(agentID, friendID, rights);
  332. }
  333. if (account1 != null) // agent is local, friend is foreigner
  334. {
  335. FriendInfo[] finfos = GetFriends(agentID);
  336. FriendInfo finfo = GetFriend(finfos, friendID);
  337. if (finfo != null)
  338. {
  339. FriendsService.StoreFriend(agentID.ToString(), finfo.Friend, rights);
  340. return true;
  341. }
  342. }
  343. if (account2 != null) // agent is foreigner, friend is local
  344. {
  345. string agentUUI = GetUUI(friendID, agentID);
  346. if (agentUUI != string.Empty)
  347. {
  348. FriendsService.StoreFriend(agentUUI, friendID.ToString(), rights);
  349. return true;
  350. }
  351. }
  352. return false;
  353. }
  354. protected override void StoreBackwards(UUID friendID, UUID agentID)
  355. {
  356. UserAccount account1 = UserAccountService.GetUserAccount(m_Scenes[0].RegionInfo.ScopeID, agentID);
  357. UserAccount account2 = UserAccountService.GetUserAccount(m_Scenes[0].RegionInfo.ScopeID, friendID);
  358. // Are they both local users?
  359. if (account1 != null && account2 != null)
  360. {
  361. // local grid users
  362. m_log.DebugFormat("[HGFRIENDS MODULE]: Users are both local");
  363. base.StoreBackwards(friendID, agentID);
  364. return;
  365. }
  366. // no provision for this temporary friendship state
  367. //FriendsService.StoreFriend(friendID.ToString(), agentID.ToString(), 0);
  368. }
  369. protected override void StoreFriendships(UUID agentID, UUID friendID)
  370. {
  371. UserAccount agentAccount = UserAccountService.GetUserAccount(m_Scenes[0].RegionInfo.ScopeID, agentID);
  372. UserAccount friendAccount = UserAccountService.GetUserAccount(m_Scenes[0].RegionInfo.ScopeID, friendID);
  373. // Are they both local users?
  374. if (agentAccount != null && friendAccount != null)
  375. {
  376. // local grid users
  377. m_log.DebugFormat("[HGFRIENDS MODULE]: Users are both local");
  378. base.StoreFriendships(agentID, friendID);
  379. return;
  380. }
  381. // ok, at least one of them is foreigner, let's get their data
  382. IClientAPI agentClient = LocateClientObject(agentID);
  383. IClientAPI friendClient = LocateClientObject(friendID);
  384. AgentCircuitData agentClientCircuit = null;
  385. AgentCircuitData friendClientCircuit = null;
  386. string agentUUI = string.Empty;
  387. string friendUUI = string.Empty;
  388. string agentFriendService = string.Empty;
  389. string friendFriendService = string.Empty;
  390. if (agentClient != null)
  391. {
  392. agentClientCircuit = ((Scene)(agentClient.Scene)).AuthenticateHandler.GetAgentCircuitData(agentClient.CircuitCode);
  393. agentUUI = Util.ProduceUserUniversalIdentifier(agentClientCircuit);
  394. agentFriendService = agentClientCircuit.ServiceURLs["FriendsServerURI"].ToString();
  395. }
  396. if (friendClient != null)
  397. {
  398. friendClientCircuit = ((Scene)(friendClient.Scene)).AuthenticateHandler.GetAgentCircuitData(friendClient.CircuitCode);
  399. friendUUI = Util.ProduceUserUniversalIdentifier(friendClientCircuit);
  400. friendFriendService = friendClientCircuit.ServiceURLs["FriendsServerURI"].ToString();
  401. }
  402. m_log.DebugFormat("[HGFRIENDS MODULE] HG Friendship! thisUUI={0}; friendUUI={1}; foreignThisFriendService={2}; foreignFriendFriendService={3}",
  403. agentUUI, friendUUI, agentFriendService, friendFriendService);
  404. // Generate a random 8-character hex number that will sign this friendship
  405. string secret = UUID.Random().ToString().Substring(0, 8);
  406. if (agentAccount != null) // agent is local, 'friend' is foreigner
  407. {
  408. // This may happen when the agent returned home, in which case the friend is not there
  409. // We need to look for its information in the friends list itself
  410. bool confirming = false;
  411. if (friendUUI == string.Empty)
  412. {
  413. FriendInfo[] finfos = GetFriends(agentID);
  414. foreach (FriendInfo finfo in finfos)
  415. {
  416. if (finfo.TheirFlags == -1)
  417. {
  418. if (finfo.Friend.StartsWith(friendID.ToString()))
  419. {
  420. friendUUI = finfo.Friend;
  421. confirming = true;
  422. }
  423. }
  424. }
  425. }
  426. // If it's confirming the friendship, we already have the full friendUUI with the secret
  427. string theFriendUUID = confirming ? friendUUI : friendUUI + ";" + secret;
  428. // store in the local friends service a reference to the foreign friend
  429. FriendsService.StoreFriend(agentID.ToString(), theFriendUUID, 1);
  430. // and also the converse
  431. FriendsService.StoreFriend(theFriendUUID, agentID.ToString(), 1);
  432. if (!confirming && friendClientCircuit != null)
  433. {
  434. // store in the foreign friends service a reference to the local agent
  435. HGFriendsServicesConnector friendsConn = new HGFriendsServicesConnector(friendFriendService, friendClientCircuit.SessionID, friendClientCircuit.ServiceSessionID);
  436. friendsConn.NewFriendship(friendID, agentUUI + ";" + secret);
  437. }
  438. }
  439. else if (friendAccount != null) // 'friend' is local, agent is foreigner
  440. {
  441. // store in the local friends service a reference to the foreign agent
  442. FriendsService.StoreFriend(friendID.ToString(), agentUUI + ";" + secret, 1);
  443. // and also the converse
  444. FriendsService.StoreFriend(agentUUI + ";" + secret, friendID.ToString(), 1);
  445. if (agentClientCircuit != null)
  446. {
  447. // store in the foreign friends service a reference to the local agent
  448. HGFriendsServicesConnector friendsConn = new HGFriendsServicesConnector(agentFriendService, agentClientCircuit.SessionID, agentClientCircuit.ServiceSessionID);
  449. friendsConn.NewFriendship(agentID, friendUUI + ";" + secret);
  450. }
  451. }
  452. else // They're both foreigners!
  453. {
  454. HGFriendsServicesConnector friendsConn;
  455. if (agentClientCircuit != null)
  456. {
  457. friendsConn = new HGFriendsServicesConnector(agentFriendService, agentClientCircuit.SessionID, agentClientCircuit.ServiceSessionID);
  458. friendsConn.NewFriendship(agentID, friendUUI + ";" + secret);
  459. }
  460. if (friendClientCircuit != null)
  461. {
  462. friendsConn = new HGFriendsServicesConnector(friendFriendService, friendClientCircuit.SessionID, friendClientCircuit.ServiceSessionID);
  463. friendsConn.NewFriendship(friendID, agentUUI + ";" + secret);
  464. }
  465. }
  466. // my brain hurts now
  467. }
  468. protected override bool DeleteFriendship(UUID agentID, UUID exfriendID)
  469. {
  470. UserAccount agentAccount = UserAccountService.GetUserAccount(m_Scenes[0].RegionInfo.ScopeID, agentID);
  471. UserAccount friendAccount = UserAccountService.GetUserAccount(m_Scenes[0].RegionInfo.ScopeID, exfriendID);
  472. // Are they both local users?
  473. if (agentAccount != null && friendAccount != null)
  474. {
  475. // local grid users
  476. return base.DeleteFriendship(agentID, exfriendID);
  477. }
  478. // ok, at least one of them is foreigner, let's get their data
  479. string agentUUI = string.Empty;
  480. string friendUUI = string.Empty;
  481. if (agentAccount != null) // agent is local, 'friend' is foreigner
  482. {
  483. // We need to look for its information in the friends list itself
  484. FriendInfo[] finfos = GetFriends(agentID);
  485. FriendInfo finfo = GetFriend(finfos, exfriendID);
  486. if (finfo != null)
  487. {
  488. friendUUI = finfo.Friend;
  489. // delete in the local friends service the reference to the foreign friend
  490. FriendsService.Delete(agentID, friendUUI);
  491. // and also the converse
  492. FriendsService.Delete(friendUUI, agentID.ToString());
  493. // notify the exfriend's service
  494. Util.FireAndForget(delegate { Delete(exfriendID, agentID, friendUUI); });
  495. m_log.DebugFormat("[HGFRIENDS MODULE]: {0} terminated {1}", agentID, friendUUI);
  496. return true;
  497. }
  498. }
  499. else if (friendAccount != null) // agent is foreigner, 'friend' is local
  500. {
  501. agentUUI = GetUUI(exfriendID, agentID);
  502. if (agentUUI != string.Empty)
  503. {
  504. // delete in the local friends service the reference to the foreign agent
  505. FriendsService.Delete(exfriendID, agentUUI);
  506. // and also the converse
  507. FriendsService.Delete(agentUUI, exfriendID.ToString());
  508. // notify the agent's service?
  509. Util.FireAndForget(delegate { Delete(agentID, exfriendID, agentUUI); });
  510. m_log.DebugFormat("[HGFRIENDS MODULE]: {0} terminated {1}", agentUUI, exfriendID);
  511. return true;
  512. }
  513. }
  514. //else They're both foreigners! Can't handle this
  515. return false;
  516. }
  517. private string GetUUI(UUID localUser, UUID foreignUser)
  518. {
  519. // Let's see if the user is here by any chance
  520. FriendInfo[] finfos = GetFriends(localUser);
  521. if (finfos != EMPTY_FRIENDS) // friend is here, cool
  522. {
  523. FriendInfo finfo = GetFriend(finfos, foreignUser);
  524. if (finfo != null)
  525. {
  526. return finfo.Friend;
  527. }
  528. }
  529. else // user is not currently on this sim, need to get from the service
  530. {
  531. finfos = FriendsService.GetFriends(localUser);
  532. foreach (FriendInfo finfo in finfos)
  533. {
  534. if (finfo.Friend.StartsWith(foreignUser.ToString())) // found it!
  535. {
  536. return finfo.Friend;
  537. }
  538. }
  539. }
  540. return string.Empty;
  541. }
  542. private void Delete(UUID foreignUser, UUID localUser, string uui)
  543. {
  544. UUID id;
  545. string url = string.Empty, secret = string.Empty, tmp = string.Empty;
  546. if (Util.ParseUniversalUserIdentifier(uui, out id, out url, out tmp, out tmp, out secret))
  547. {
  548. m_log.DebugFormat("[HGFRIENDS MODULE]: Deleting friendship from {0}", url);
  549. HGFriendsServicesConnector friendConn = new HGFriendsServicesConnector(url);
  550. friendConn.DeleteFriendship(foreignUser, localUser, secret);
  551. }
  552. }
  553. }
  554. }