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