diff options
author | Diva Canto | 2011-05-19 16:54:46 -0700 |
---|---|---|
committer | Diva Canto | 2011-05-19 16:54:46 -0700 |
commit | d21e9c755f004d8fe03b11bc57b810dbd401435a (patch) | |
tree | 1efd9e48308192d21ca73d8ff12d6a48c186077c /OpenSim/Region | |
parent | Accidentally committed too early (diff) | |
download | opensim-SC-d21e9c755f004d8fe03b11bc57b810dbd401435a.zip opensim-SC-d21e9c755f004d8fe03b11bc57b810dbd401435a.tar.gz opensim-SC-d21e9c755f004d8fe03b11bc57b810dbd401435a.tar.bz2 opensim-SC-d21e9c755f004d8fe03b11bc57b810dbd401435a.tar.xz |
HG Friends working to some extent: friendships offered and accepted correctly handled. Friends list showing correct foreign names. TODO: GrantRights.
Diffstat (limited to 'OpenSim/Region')
4 files changed, 553 insertions, 39 deletions
diff --git a/OpenSim/Region/CoreModules/Avatar/Friends/FriendsModule.cs b/OpenSim/Region/CoreModules/Avatar/Friends/FriendsModule.cs index 5baf078..21cd924 100644 --- a/OpenSim/Region/CoreModules/Avatar/Friends/FriendsModule.cs +++ b/OpenSim/Region/CoreModules/Avatar/Friends/FriendsModule.cs | |||
@@ -49,6 +49,8 @@ namespace OpenSim.Region.CoreModules.Avatar.Friends | |||
49 | { | 49 | { |
50 | public class FriendsModule : ISharedRegionModule, IFriendsModule | 50 | public class FriendsModule : ISharedRegionModule, IFriendsModule |
51 | { | 51 | { |
52 | protected bool m_Enabled = false; | ||
53 | |||
52 | protected class UserFriendData | 54 | protected class UserFriendData |
53 | { | 55 | { |
54 | public UUID PrincipalID; | 56 | public UUID PrincipalID; |
@@ -130,8 +132,26 @@ namespace OpenSim.Region.CoreModules.Avatar.Friends | |||
130 | } | 132 | } |
131 | } | 133 | } |
132 | 134 | ||
135 | #region ISharedRegionModule | ||
133 | public void Initialise(IConfigSource config) | 136 | public void Initialise(IConfigSource config) |
134 | { | 137 | { |
138 | IConfig moduleConfig = config.Configs["Modules"]; | ||
139 | if (moduleConfig != null) | ||
140 | { | ||
141 | string name = moduleConfig.GetString("FriendsModule", "FriendsModule"); | ||
142 | m_log.DebugFormat("[XXX] {0} compared to {1}", name, Name); | ||
143 | if (name == Name) | ||
144 | { | ||
145 | InitModule(config); | ||
146 | |||
147 | m_Enabled = true; | ||
148 | m_log.InfoFormat("[FRIENDS MODULE]: {0} enabled.", Name); | ||
149 | } | ||
150 | } | ||
151 | } | ||
152 | |||
153 | protected void InitModule(IConfigSource config) | ||
154 | { | ||
135 | IConfig friendsConfig = config.Configs["Friends"]; | 155 | IConfig friendsConfig = config.Configs["Friends"]; |
136 | if (friendsConfig != null) | 156 | if (friendsConfig != null) |
137 | { | 157 | { |
@@ -153,7 +173,6 @@ namespace OpenSim.Region.CoreModules.Avatar.Friends | |||
153 | m_log.Error("[FRIENDS]: No Connector defined in section Friends, or failed to load, cannot continue"); | 173 | m_log.Error("[FRIENDS]: No Connector defined in section Friends, or failed to load, cannot continue"); |
154 | throw new Exception("Connector load error"); | 174 | throw new Exception("Connector load error"); |
155 | } | 175 | } |
156 | |||
157 | } | 176 | } |
158 | 177 | ||
159 | public void PostInitialise() | 178 | public void PostInitialise() |
@@ -166,6 +185,9 @@ namespace OpenSim.Region.CoreModules.Avatar.Friends | |||
166 | 185 | ||
167 | public void AddRegion(Scene scene) | 186 | public void AddRegion(Scene scene) |
168 | { | 187 | { |
188 | if (!m_Enabled) | ||
189 | return; | ||
190 | |||
169 | m_Scenes.Add(scene); | 191 | m_Scenes.Add(scene); |
170 | scene.RegisterModuleInterface<IFriendsModule>(this); | 192 | scene.RegisterModuleInterface<IFriendsModule>(this); |
171 | 193 | ||
@@ -181,10 +203,13 @@ namespace OpenSim.Region.CoreModules.Avatar.Friends | |||
181 | 203 | ||
182 | public void RemoveRegion(Scene scene) | 204 | public void RemoveRegion(Scene scene) |
183 | { | 205 | { |
206 | if (!m_Enabled) | ||
207 | return; | ||
208 | |||
184 | m_Scenes.Remove(scene); | 209 | m_Scenes.Remove(scene); |
185 | } | 210 | } |
186 | 211 | ||
187 | public string Name | 212 | public virtual string Name |
188 | { | 213 | { |
189 | get { return "FriendsModule"; } | 214 | get { return "FriendsModule"; } |
190 | } | 215 | } |
@@ -194,6 +219,8 @@ namespace OpenSim.Region.CoreModules.Avatar.Friends | |||
194 | get { return null; } | 219 | get { return null; } |
195 | } | 220 | } |
196 | 221 | ||
222 | #endregion | ||
223 | |||
197 | public uint GetFriendPerms(UUID principalID, UUID friendID) | 224 | public uint GetFriendPerms(UUID principalID, UUID friendID) |
198 | { | 225 | { |
199 | FriendInfo[] friends = GetFriends(principalID); | 226 | FriendInfo[] friends = GetFriends(principalID); |
@@ -214,30 +241,33 @@ namespace OpenSim.Region.CoreModules.Avatar.Friends | |||
214 | client.OnTerminateFriendship += OnTerminateFriendship; | 241 | client.OnTerminateFriendship += OnTerminateFriendship; |
215 | client.OnGrantUserRights += OnGrantUserRights; | 242 | client.OnGrantUserRights += OnGrantUserRights; |
216 | 243 | ||
217 | // Asynchronously fetch the friends list or increment the refcount for the existing | 244 | Util.FireAndForget(delegate { FetchFriendslist(client.AgentId); }); |
218 | // friends list | 245 | } |
219 | Util.FireAndForget( | 246 | |
220 | delegate(object o) | 247 | /// Fetch the friends list or increment the refcount for the existing |
248 | /// friends list | ||
249 | /// Returns true if the list was fetched, false if it wasn't | ||
250 | protected virtual bool FetchFriendslist(UUID agentID) | ||
251 | { | ||
252 | lock (m_Friends) | ||
253 | { | ||
254 | UserFriendData friendsData; | ||
255 | if (m_Friends.TryGetValue(agentID, out friendsData)) | ||
221 | { | 256 | { |
222 | lock (m_Friends) | 257 | friendsData.Refcount++; |
223 | { | 258 | return false; |
224 | UserFriendData friendsData; | 259 | } |
225 | if (m_Friends.TryGetValue(client.AgentId, out friendsData)) | 260 | else |
226 | { | 261 | { |
227 | friendsData.Refcount++; | 262 | friendsData = new UserFriendData(); |
228 | } | 263 | friendsData.PrincipalID = agentID; |
229 | else | 264 | friendsData.Friends = FriendsService.GetFriends(agentID); |
230 | { | 265 | friendsData.Refcount = 1; |
231 | friendsData = new UserFriendData(); | ||
232 | friendsData.PrincipalID = client.AgentId; | ||
233 | friendsData.Friends = FriendsService.GetFriends(client.AgentId); | ||
234 | friendsData.Refcount = 1; | ||
235 | 266 | ||
236 | m_Friends[client.AgentId] = friendsData; | 267 | m_Friends[agentID] = friendsData; |
237 | } | 268 | return true; |
238 | } | ||
239 | } | 269 | } |
240 | ); | 270 | } |
241 | } | 271 | } |
242 | 272 | ||
243 | private void OnClientClosed(UUID agentID, Scene scene) | 273 | private void OnClientClosed(UUID agentID, Scene scene) |
@@ -313,10 +343,12 @@ namespace OpenSim.Region.CoreModules.Avatar.Friends | |||
313 | foreach (string fid in outstanding) | 343 | foreach (string fid in outstanding) |
314 | { | 344 | { |
315 | UUID fromAgentID; | 345 | UUID fromAgentID; |
316 | if (!UUID.TryParse(fid, out fromAgentID)) | 346 | string firstname = "Unknown", lastname = "User"; |
347 | if (!GetAgentInfo(client.Scene.RegionInfo.ScopeID, fid, out fromAgentID, out firstname, out lastname)) | ||
348 | { | ||
349 | m_log.DebugFormat("[FRIENDS MODULE]: skipping malformed friend {0}", fid); | ||
317 | continue; | 350 | continue; |
318 | 351 | } | |
319 | UserAccount account = m_Scenes[0].UserAccountService.GetUserAccount(client.Scene.RegionInfo.ScopeID, fromAgentID); | ||
320 | 352 | ||
321 | PresenceInfo presence = null; | 353 | PresenceInfo presence = null; |
322 | PresenceInfo[] presences = PresenceService.GetAgents(new string[] { fid }); | 354 | PresenceInfo[] presences = PresenceService.GetAgents(new string[] { fid }); |
@@ -326,15 +358,37 @@ namespace OpenSim.Region.CoreModules.Avatar.Friends | |||
326 | im.offline = 0; | 358 | im.offline = 0; |
327 | 359 | ||
328 | im.fromAgentID = fromAgentID.Guid; | 360 | im.fromAgentID = fromAgentID.Guid; |
329 | im.fromAgentName = account.FirstName + " " + account.LastName; | 361 | im.fromAgentName = firstname + " " + lastname; |
330 | im.offline = (byte)((presence == null) ? 1 : 0); | 362 | im.offline = (byte)((presence == null) ? 1 : 0); |
331 | im.imSessionID = im.fromAgentID; | 363 | im.imSessionID = im.fromAgentID; |
364 | im.message = FriendshipMessage(fid); | ||
332 | 365 | ||
333 | // Finally | 366 | // Finally |
334 | LocalFriendshipOffered(agentID, im); | 367 | LocalFriendshipOffered(agentID, im); |
335 | } | 368 | } |
336 | } | 369 | } |
337 | 370 | ||
371 | protected virtual string FriendshipMessage(string friendID) | ||
372 | { | ||
373 | return "Will you be my friend?"; | ||
374 | } | ||
375 | |||
376 | protected virtual bool GetAgentInfo(UUID scopeID, string fid, out UUID agentID, out string first, out string last) | ||
377 | { | ||
378 | first = "Unknown"; last = "User"; | ||
379 | if (!UUID.TryParse(fid, out agentID)) | ||
380 | return false; | ||
381 | |||
382 | UserAccount account = m_Scenes[0].UserAccountService.GetUserAccount(scopeID, agentID); | ||
383 | if (account != null) | ||
384 | { | ||
385 | first = account.FirstName; | ||
386 | last = account.LastName; | ||
387 | } | ||
388 | |||
389 | return true; | ||
390 | } | ||
391 | |||
338 | List<UUID> GetOnlineFriends(UUID userID) | 392 | List<UUID> GetOnlineFriends(UUID userID) |
339 | { | 393 | { |
340 | List<string> friendList = new List<string>(); | 394 | List<string> friendList = new List<string>(); |
@@ -475,23 +529,26 @@ namespace OpenSim.Region.CoreModules.Avatar.Friends | |||
475 | 529 | ||
476 | // This user wants to be friends with the other user. | 530 | // This user wants to be friends with the other user. |
477 | // Let's add the relation backwards, in case the other is not online | 531 | // Let's add the relation backwards, in case the other is not online |
478 | FriendsService.StoreFriend(friendID, principalID.ToString(), 0); | 532 | StoreBackwards(friendID, principalID); |
479 | 533 | ||
480 | // Now let's ask the other user to be friends with this user | 534 | // Now let's ask the other user to be friends with this user |
481 | ForwardFriendshipOffer(principalID, friendID, im); | 535 | ForwardFriendshipOffer(principalID, friendID, im); |
482 | } | 536 | } |
483 | } | 537 | } |
484 | 538 | ||
539 | protected virtual void StoreBackwards(UUID friendID, UUID agentID) | ||
540 | { | ||
541 | FriendsService.StoreFriend(friendID.ToString(), agentID.ToString(), 0); | ||
542 | } | ||
543 | |||
485 | private void ForwardFriendshipOffer(UUID agentID, UUID friendID, GridInstantMessage im) | 544 | private void ForwardFriendshipOffer(UUID agentID, UUID friendID, GridInstantMessage im) |
486 | { | 545 | { |
487 | // !!!!!!!! This is a hack so that we don't have to keep state (transactionID/imSessionID) | 546 | // !!!!!!!! This is a hack so that we don't have to keep state (transactionID/imSessionID) |
488 | // We stick this agent's ID as imSession, so that it's directly available on the receiving end | 547 | // We stick this agent's ID as imSession, so that it's directly available on the receiving end |
489 | im.imSessionID = im.fromAgentID; | 548 | im.imSessionID = im.fromAgentID; |
549 | im.fromAgentName = GetFriendshipRequesterName(agentID); | ||
490 | 550 | ||
491 | // Try the local sim | 551 | // Try the local sim |
492 | UserAccount account = UserAccountService.GetUserAccount(UUID.Zero, agentID); | ||
493 | im.fromAgentName = (account == null) ? "Unknown" : account.FirstName + " " + account.LastName; | ||
494 | |||
495 | if (LocalFriendshipOffered(friendID, im)) | 552 | if (LocalFriendshipOffered(friendID, im)) |
496 | return; | 553 | return; |
497 | 554 | ||
@@ -509,12 +566,17 @@ namespace OpenSim.Region.CoreModules.Avatar.Friends | |||
509 | // If the prospective friend is not online, he'll get the message upon login. | 566 | // If the prospective friend is not online, he'll get the message upon login. |
510 | } | 567 | } |
511 | 568 | ||
569 | protected virtual string GetFriendshipRequesterName(UUID agentID) | ||
570 | { | ||
571 | UserAccount account = UserAccountService.GetUserAccount(UUID.Zero, agentID); | ||
572 | return (account == null) ? "Unknown" : account.FirstName + " " + account.LastName; | ||
573 | } | ||
574 | |||
512 | private void OnApproveFriendRequest(IClientAPI client, UUID agentID, UUID friendID, List<UUID> callingCardFolders) | 575 | private void OnApproveFriendRequest(IClientAPI client, UUID agentID, UUID friendID, List<UUID> callingCardFolders) |
513 | { | 576 | { |
514 | m_log.DebugFormat("[FRIENDS]: {0} accepted friendship from {1}", agentID, friendID); | 577 | m_log.DebugFormat("[FRIENDS]: {0} accepted friendship from {1}", agentID, friendID); |
515 | 578 | ||
516 | FriendsService.StoreFriend(agentID, friendID.ToString(), 1); | 579 | StoreFriendships(agentID, friendID); |
517 | FriendsService.StoreFriend(friendID, agentID.ToString(), 1); | ||
518 | 580 | ||
519 | // Update the local cache | 581 | // Update the local cache |
520 | UpdateFriendsCache(agentID); | 582 | UpdateFriendsCache(agentID); |
@@ -544,6 +606,12 @@ namespace OpenSim.Region.CoreModules.Avatar.Friends | |||
544 | } | 606 | } |
545 | } | 607 | } |
546 | 608 | ||
609 | protected virtual void StoreFriendships(UUID agentID, UUID friendID) | ||
610 | { | ||
611 | FriendsService.StoreFriend(agentID.ToString(), friendID.ToString(), 1); | ||
612 | FriendsService.StoreFriend(friendID.ToString(), agentID.ToString(), 1); | ||
613 | } | ||
614 | |||
547 | private void OnDenyFriendRequest(IClientAPI client, UUID agentID, UUID friendID, List<UUID> callingCardFolders) | 615 | private void OnDenyFriendRequest(IClientAPI client, UUID agentID, UUID friendID, List<UUID> callingCardFolders) |
548 | { | 616 | { |
549 | m_log.DebugFormat("[FRIENDS]: {0} denied friendship to {1}", agentID, friendID); | 617 | m_log.DebugFormat("[FRIENDS]: {0} denied friendship to {1}", agentID, friendID); |
@@ -576,8 +644,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Friends | |||
576 | 644 | ||
577 | private void OnTerminateFriendship(IClientAPI client, UUID agentID, UUID exfriendID) | 645 | private void OnTerminateFriendship(IClientAPI client, UUID agentID, UUID exfriendID) |
578 | { | 646 | { |
579 | FriendsService.Delete(agentID, exfriendID.ToString()); | 647 | DeleteFriendship(agentID, exfriendID); |
580 | FriendsService.Delete(exfriendID, agentID.ToString()); | ||
581 | 648 | ||
582 | // Update local cache | 649 | // Update local cache |
583 | UpdateFriendsCache(agentID); | 650 | UpdateFriendsCache(agentID); |
@@ -604,6 +671,12 @@ namespace OpenSim.Region.CoreModules.Avatar.Friends | |||
604 | } | 671 | } |
605 | } | 672 | } |
606 | 673 | ||
674 | protected virtual void DeleteFriendship(UUID agentID, UUID exfriendID) | ||
675 | { | ||
676 | FriendsService.Delete(agentID, exfriendID.ToString()); | ||
677 | FriendsService.Delete(exfriendID, agentID.ToString()); | ||
678 | } | ||
679 | |||
607 | private void OnGrantUserRights(IClientAPI remoteClient, UUID requester, UUID target, int rights) | 680 | private void OnGrantUserRights(IClientAPI remoteClient, UUID requester, UUID target, int rights) |
608 | { | 681 | { |
609 | FriendInfo[] friends = GetFriends(remoteClient.AgentId); | 682 | FriendInfo[] friends = GetFriends(remoteClient.AgentId); |
@@ -622,7 +695,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Friends | |||
622 | if (friend != null) // Found it | 695 | if (friend != null) // Found it |
623 | { | 696 | { |
624 | // Store it on the DB | 697 | // Store it on the DB |
625 | FriendsService.StoreFriend(requester, target.ToString(), rights); | 698 | FriendsService.StoreFriend(requester.ToString(), target.ToString(), rights); |
626 | 699 | ||
627 | // Store it in the local cache | 700 | // Store it in the local cache |
628 | int myFlags = friend.MyFlags; | 701 | int myFlags = friend.MyFlags; |
@@ -780,7 +853,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Friends | |||
780 | 853 | ||
781 | #endregion | 854 | #endregion |
782 | 855 | ||
783 | private FriendInfo[] GetFriends(UUID agentID) | 856 | protected FriendInfo[] GetFriends(UUID agentID) |
784 | { | 857 | { |
785 | UserFriendData friendsData; | 858 | UserFriendData friendsData; |
786 | 859 | ||
diff --git a/OpenSim/Region/CoreModules/Avatar/Friends/HGFriendsModule.cs b/OpenSim/Region/CoreModules/Avatar/Friends/HGFriendsModule.cs new file mode 100644 index 0000000..645ecdc --- /dev/null +++ b/OpenSim/Region/CoreModules/Avatar/Friends/HGFriendsModule.cs | |||
@@ -0,0 +1,438 @@ | |||
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 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 | |||
46 | namespace OpenSim.Region.CoreModules.Avatar.Friends | ||
47 | { | ||
48 | [Extension(Path = "/OpenSim/RegionModules", NodeName = "RegionModule")] | ||
49 | public class HGFriendsModule : FriendsModule, ISharedRegionModule, IFriendsModule | ||
50 | { | ||
51 | private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); | ||
52 | |||
53 | #region ISharedRegionModule | ||
54 | public override string Name | ||
55 | { | ||
56 | get { return "HGFriendsModule"; } | ||
57 | } | ||
58 | |||
59 | #endregion | ||
60 | |||
61 | //public void SendFriendsOnlineIfNeeded(IClientAPI client) | ||
62 | //{ | ||
63 | // UUID agentID = client.AgentId; | ||
64 | |||
65 | // // Check if the online friends list is needed | ||
66 | // lock (m_NeedsListOfFriends) | ||
67 | // { | ||
68 | // if (!m_NeedsListOfFriends.Remove(agentID)) | ||
69 | // return; | ||
70 | // } | ||
71 | |||
72 | // // Send the friends online | ||
73 | // List<UUID> online = GetOnlineFriends(agentID); | ||
74 | // if (online.Count > 0) | ||
75 | // { | ||
76 | // m_log.DebugFormat("[FRIENDS MODULE]: User {0} in region {1} has {2} friends online", client.AgentId, client.Scene.RegionInfo.RegionName, online.Count); | ||
77 | // client.SendAgentOnline(online.ToArray()); | ||
78 | // } | ||
79 | |||
80 | // // Send outstanding friendship offers | ||
81 | // List<string> outstanding = new List<string>(); | ||
82 | // FriendInfo[] friends = GetFriends(agentID); | ||
83 | // foreach (FriendInfo fi in friends) | ||
84 | // { | ||
85 | // if (fi.TheirFlags == -1) | ||
86 | // outstanding.Add(fi.Friend); | ||
87 | // } | ||
88 | |||
89 | // GridInstantMessage im = new GridInstantMessage(client.Scene, UUID.Zero, String.Empty, agentID, (byte)InstantMessageDialog.FriendshipOffered, | ||
90 | // "Will you be my friend?", true, Vector3.Zero); | ||
91 | |||
92 | // foreach (string fid in outstanding) | ||
93 | // { | ||
94 | // UUID fromAgentID; | ||
95 | // if (!UUID.TryParse(fid, out fromAgentID)) | ||
96 | // continue; | ||
97 | |||
98 | // UserAccount account = m_Scenes[0].UserAccountService.GetUserAccount(client.Scene.RegionInfo.ScopeID, fromAgentID); | ||
99 | |||
100 | // PresenceInfo presence = null; | ||
101 | // PresenceInfo[] presences = PresenceService.GetAgents(new string[] { fid }); | ||
102 | // if (presences != null && presences.Length > 0) | ||
103 | // presence = presences[0]; | ||
104 | // if (presence != null) | ||
105 | // im.offline = 0; | ||
106 | |||
107 | // im.fromAgentID = fromAgentID.Guid; | ||
108 | // im.fromAgentName = account.FirstName + " " + account.LastName; | ||
109 | // im.offline = (byte)((presence == null) ? 1 : 0); | ||
110 | // im.imSessionID = im.fromAgentID; | ||
111 | |||
112 | // // Finally | ||
113 | // LocalFriendshipOffered(agentID, im); | ||
114 | // } | ||
115 | //} | ||
116 | |||
117 | //List<UUID> GetOnlineFriends(UUID userID) | ||
118 | //{ | ||
119 | // List<string> friendList = new List<string>(); | ||
120 | // List<UUID> online = new List<UUID>(); | ||
121 | |||
122 | // FriendInfo[] friends = GetFriends(userID); | ||
123 | // foreach (FriendInfo fi in friends) | ||
124 | // { | ||
125 | // if (((fi.TheirFlags & 1) != 0) && (fi.TheirFlags != -1)) | ||
126 | // friendList.Add(fi.Friend); | ||
127 | // } | ||
128 | |||
129 | // if (friendList.Count > 0) | ||
130 | // { | ||
131 | // PresenceInfo[] presence = PresenceService.GetAgents(friendList.ToArray()); | ||
132 | // foreach (PresenceInfo pi in presence) | ||
133 | // { | ||
134 | // UUID presenceID; | ||
135 | // if (UUID.TryParse(pi.UserID, out presenceID)) | ||
136 | // online.Add(presenceID); | ||
137 | // } | ||
138 | // } | ||
139 | |||
140 | // return online; | ||
141 | //} | ||
142 | |||
143 | //private void StatusNotify(FriendInfo friend, UUID userID, bool online) | ||
144 | //{ | ||
145 | // UUID friendID; | ||
146 | // if (UUID.TryParse(friend.Friend, out friendID)) | ||
147 | // { | ||
148 | // // Try local | ||
149 | // if (LocalStatusNotification(userID, friendID, online)) | ||
150 | // return; | ||
151 | |||
152 | // // The friend is not here [as root]. Let's forward. | ||
153 | // PresenceInfo[] friendSessions = PresenceService.GetAgents(new string[] { friendID.ToString() }); | ||
154 | // if (friendSessions != null && friendSessions.Length > 0) | ||
155 | // { | ||
156 | // PresenceInfo friendSession = null; | ||
157 | // foreach (PresenceInfo pinfo in friendSessions) | ||
158 | // if (pinfo.RegionID != UUID.Zero) // let's guard against sessions-gone-bad | ||
159 | // { | ||
160 | // friendSession = pinfo; | ||
161 | // break; | ||
162 | // } | ||
163 | |||
164 | // if (friendSession != null) | ||
165 | // { | ||
166 | // GridRegion region = GridService.GetRegionByUUID(m_Scenes[0].RegionInfo.ScopeID, friendSession.RegionID); | ||
167 | // //m_log.DebugFormat("[FRIENDS]: Remote Notify to region {0}", region.RegionName); | ||
168 | // m_FriendsSimConnector.StatusNotify(region, userID, friendID, online); | ||
169 | // } | ||
170 | // } | ||
171 | |||
172 | // // Friend is not online. Ignore. | ||
173 | // } | ||
174 | // else | ||
175 | // { | ||
176 | // m_log.WarnFormat("[FRIENDS]: Error parsing friend ID {0}", friend.Friend); | ||
177 | // } | ||
178 | //} | ||
179 | |||
180 | protected override bool FetchFriendslist(UUID agentID) | ||
181 | { | ||
182 | if (base.FetchFriendslist(agentID)) | ||
183 | { | ||
184 | // We need to preload the user management cache with the names | ||
185 | // of foreign friends, just like we do with SOPs' creators | ||
186 | foreach (FriendInfo finfo in m_Friends[agentID].Friends) | ||
187 | { | ||
188 | if (finfo.TheirFlags != -1) | ||
189 | { | ||
190 | UUID id; | ||
191 | if (!UUID.TryParse(finfo.Friend, out id)) | ||
192 | { | ||
193 | string url = string.Empty, first = string.Empty, last = string.Empty; | ||
194 | if (Util.ParseUniversalUserIdentifier(finfo.Friend, out id, out url, out first, out last)) | ||
195 | { | ||
196 | IUserManagement uMan = m_Scenes[0].RequestModuleInterface<IUserManagement>(); | ||
197 | uMan.AddUser(id, url + ";" + first + " " + last); | ||
198 | } | ||
199 | } | ||
200 | } | ||
201 | } | ||
202 | return true; | ||
203 | } | ||
204 | return false; | ||
205 | } | ||
206 | |||
207 | protected override bool GetAgentInfo(UUID scopeID, string fid, out UUID agentID, out string first, out string last) | ||
208 | { | ||
209 | first = "Unknown"; last = "User"; | ||
210 | if (base.GetAgentInfo(scopeID, fid, out agentID, out first, out last)) | ||
211 | return true; | ||
212 | |||
213 | // fid is not a UUID... | ||
214 | string url = string.Empty; | ||
215 | if (Util.ParseUniversalUserIdentifier(fid, out agentID, out url, out first, out last)) | ||
216 | { | ||
217 | IUserManagement userMan = m_Scenes[0].RequestModuleInterface<IUserManagement>(); | ||
218 | userMan.AddUser(agentID, url + ";" + first + " " + last); | ||
219 | |||
220 | try // our best | ||
221 | { | ||
222 | string[] parts = userMan.GetUserName(agentID).Split(); | ||
223 | first = parts[0]; | ||
224 | last = parts[1]; | ||
225 | } | ||
226 | catch { } | ||
227 | return true; | ||
228 | } | ||
229 | return false; | ||
230 | } | ||
231 | |||
232 | protected override string GetFriendshipRequesterName(UUID agentID) | ||
233 | { | ||
234 | // For the time being we assume that HG friendship requests can only happen | ||
235 | // when avies are on the same region. | ||
236 | IClientAPI client = LocateClientObject(agentID); | ||
237 | if (client != null) | ||
238 | return client.FirstName + " " + client.LastName; | ||
239 | else | ||
240 | return base.GetFriendshipRequesterName(agentID); | ||
241 | } | ||
242 | |||
243 | protected override string FriendshipMessage(string friendID) | ||
244 | { | ||
245 | UUID id; | ||
246 | if (UUID.TryParse(friendID, out id)) | ||
247 | return base.FriendshipMessage(friendID); | ||
248 | |||
249 | return "Please confirm this friendship you made while you were away."; | ||
250 | } | ||
251 | |||
252 | protected override void StoreBackwards(UUID friendID, UUID agentID) | ||
253 | { | ||
254 | UserAccount account1 = UserAccountService.GetUserAccount(m_Scenes[0].RegionInfo.ScopeID, agentID); | ||
255 | UserAccount account2 = UserAccountService.GetUserAccount(m_Scenes[0].RegionInfo.ScopeID, friendID); | ||
256 | // Are they both local users? | ||
257 | if (account1 != null && account2 != null) | ||
258 | { | ||
259 | // local grid users | ||
260 | m_log.DebugFormat("[HGFRIENDS MODULE]: Users are both local"); | ||
261 | base.StoreBackwards(friendID, agentID); | ||
262 | return; | ||
263 | } | ||
264 | |||
265 | // no provision for this temporary friendship state | ||
266 | //FriendsService.StoreFriend(friendID.ToString(), agentID.ToString(), 0); | ||
267 | } | ||
268 | |||
269 | protected override void StoreFriendships(UUID agentID, UUID friendID) | ||
270 | { | ||
271 | UserAccount agentAccount = UserAccountService.GetUserAccount(m_Scenes[0].RegionInfo.ScopeID, agentID); | ||
272 | UserAccount friendAccount = UserAccountService.GetUserAccount(m_Scenes[0].RegionInfo.ScopeID, friendID); | ||
273 | // Are they both local users? | ||
274 | if (agentAccount != null && friendAccount != null) | ||
275 | { | ||
276 | // local grid users | ||
277 | m_log.DebugFormat("[HGFRIENDS MODULE]: Users are both local"); | ||
278 | base.StoreFriendships(agentID, friendID); | ||
279 | return; | ||
280 | } | ||
281 | |||
282 | |||
283 | // ok, at least one of them is foreigner, let's get their data | ||
284 | IClientAPI agentClient = LocateClientObject(agentID); | ||
285 | IClientAPI friendClient = LocateClientObject(friendID); | ||
286 | AgentCircuitData agentClientCircuit = null; | ||
287 | AgentCircuitData friendClientCircuit = null; | ||
288 | string agentUUI = string.Empty; | ||
289 | string friendUUI = string.Empty; | ||
290 | string agentFriendService = string.Empty; | ||
291 | string friendFriendService = string.Empty; | ||
292 | |||
293 | if (agentClient != null) | ||
294 | { | ||
295 | agentClientCircuit = ((Scene)(agentClient.Scene)).AuthenticateHandler.GetAgentCircuitData(agentClient.CircuitCode); | ||
296 | agentUUI = Util.ProduceUserUniversalIdentifier(agentClientCircuit); | ||
297 | agentFriendService = agentClientCircuit.ServiceURLs["FriendsServerURI"].ToString(); | ||
298 | } | ||
299 | if (friendClient != null) | ||
300 | { | ||
301 | friendClientCircuit = ((Scene)(friendClient.Scene)).AuthenticateHandler.GetAgentCircuitData(friendClient.CircuitCode); | ||
302 | friendUUI = Util.ProduceUserUniversalIdentifier(friendClientCircuit); | ||
303 | friendFriendService = friendClientCircuit.ServiceURLs["FriendsServerURI"].ToString(); | ||
304 | } | ||
305 | |||
306 | m_log.DebugFormat("[XXX] HG Friendship! thisUUI={0}; friendUUI={1}; foreignThisFriendService={2}; foreignFriendFriendService={3}", | ||
307 | agentUUI, friendUUI, agentFriendService, friendFriendService); | ||
308 | |||
309 | if (agentAccount != null) // agent is local, 'friend' is foreigner | ||
310 | { | ||
311 | // This may happen when the agent returned home, in which case the friend is not there | ||
312 | // We need to llok for its information in the friends list itself | ||
313 | if (friendUUI == string.Empty) | ||
314 | { | ||
315 | FriendInfo[] finfos = GetFriends(agentID); | ||
316 | foreach (FriendInfo finfo in finfos) | ||
317 | { | ||
318 | if (finfo.TheirFlags == -1) | ||
319 | { | ||
320 | if (finfo.Friend.StartsWith(friendID.ToString())) | ||
321 | friendUUI = finfo.Friend; | ||
322 | } | ||
323 | } | ||
324 | } | ||
325 | |||
326 | // store in the local friends service a reference to the foreign friend | ||
327 | FriendsService.StoreFriend(agentID.ToString(), friendUUI, 1); | ||
328 | // and also the converse | ||
329 | FriendsService.StoreFriend(friendUUI, agentID.ToString(), 1); | ||
330 | |||
331 | if (friendClientCircuit != null) | ||
332 | { | ||
333 | // store in the foreign friends service a reference to the local agent | ||
334 | HGFriendsServicesConnector friendsConn = new HGFriendsServicesConnector(friendFriendService, friendClientCircuit.SessionID, friendClientCircuit.ServiceSessionID); | ||
335 | friendsConn.NewFriendship(friendID, agentUUI); | ||
336 | } | ||
337 | } | ||
338 | else if (friendAccount != null) // 'friend' is local, agent is foreigner | ||
339 | { | ||
340 | // store in the local friends service a reference to the foreign agent | ||
341 | FriendsService.StoreFriend(friendID.ToString(), agentUUI, 1); | ||
342 | // and also the converse | ||
343 | FriendsService.StoreFriend(agentUUI, friendID.ToString(), 1); | ||
344 | |||
345 | if (agentClientCircuit != null) | ||
346 | { | ||
347 | // store in the foreign friends service a reference to the local agent | ||
348 | HGFriendsServicesConnector friendsConn = new HGFriendsServicesConnector(agentFriendService, agentClientCircuit.SessionID, agentClientCircuit.ServiceSessionID); | ||
349 | friendsConn.NewFriendship(agentID, friendUUI); | ||
350 | } | ||
351 | } | ||
352 | else // They're both foreigners! | ||
353 | { | ||
354 | HGFriendsServicesConnector friendsConn; | ||
355 | if (agentClientCircuit != null) | ||
356 | { | ||
357 | friendsConn = new HGFriendsServicesConnector(agentFriendService, agentClientCircuit.SessionID, agentClientCircuit.ServiceSessionID); | ||
358 | friendsConn.NewFriendship(agentID, friendUUI); | ||
359 | } | ||
360 | if (friendClientCircuit != null) | ||
361 | { | ||
362 | friendsConn = new HGFriendsServicesConnector(friendFriendService, friendClientCircuit.SessionID, friendClientCircuit.ServiceSessionID); | ||
363 | friendsConn.NewFriendship(friendID, agentUUI); | ||
364 | } | ||
365 | } | ||
366 | // my brain hurts now | ||
367 | } | ||
368 | |||
369 | protected override void DeleteFriendship(UUID agentID, UUID exfriendID) | ||
370 | { | ||
371 | base.DeleteFriendship(agentID, exfriendID); | ||
372 | // Maybe some of the base deletes will fail. | ||
373 | // Let's delete the local friendship with foreign friend | ||
374 | FriendInfo[] friends = GetFriends(agentID); | ||
375 | foreach (FriendInfo finfo in friends) | ||
376 | { | ||
377 | if (finfo.Friend != exfriendID.ToString() && finfo.Friend.EndsWith(exfriendID.ToString())) | ||
378 | { | ||
379 | FriendsService.Delete(agentID, exfriendID.ToString()); | ||
380 | // TODO: delete the friendship on the other side | ||
381 | // Should use the homeurl given in finfo.Friend | ||
382 | } | ||
383 | } | ||
384 | } | ||
385 | |||
386 | //private void OnGrantUserRights(IClientAPI remoteClient, UUID requester, UUID target, int rights) | ||
387 | //{ | ||
388 | // FriendInfo[] friends = GetFriends(remoteClient.AgentId); | ||
389 | // if (friends.Length == 0) | ||
390 | // return; | ||
391 | |||
392 | // m_log.DebugFormat("[FRIENDS MODULE]: User {0} changing rights to {1} for friend {2}", requester, rights, target); | ||
393 | // // Let's find the friend in this user's friend list | ||
394 | // FriendInfo friend = null; | ||
395 | // foreach (FriendInfo fi in friends) | ||
396 | // { | ||
397 | // if (fi.Friend == target.ToString()) | ||
398 | // friend = fi; | ||
399 | // } | ||
400 | |||
401 | // if (friend != null) // Found it | ||
402 | // { | ||
403 | // // Store it on the DB | ||
404 | // FriendsService.StoreFriend(requester, target.ToString(), rights); | ||
405 | |||
406 | // // Store it in the local cache | ||
407 | // int myFlags = friend.MyFlags; | ||
408 | // friend.MyFlags = rights; | ||
409 | |||
410 | // // Always send this back to the original client | ||
411 | // remoteClient.SendChangeUserRights(requester, target, rights); | ||
412 | |||
413 | // // | ||
414 | // // Notify the friend | ||
415 | // // | ||
416 | |||
417 | // // Try local | ||
418 | // if (LocalGrantRights(requester, target, myFlags, rights)) | ||
419 | // return; | ||
420 | |||
421 | // PresenceInfo[] friendSessions = PresenceService.GetAgents(new string[] { target.ToString() }); | ||
422 | // if (friendSessions != null && friendSessions.Length > 0) | ||
423 | // { | ||
424 | // PresenceInfo friendSession = friendSessions[0]; | ||
425 | // if (friendSession != null) | ||
426 | // { | ||
427 | // GridRegion region = GridService.GetRegionByUUID(m_Scenes[0].RegionInfo.ScopeID, friendSession.RegionID); | ||
428 | // // TODO: You might want to send the delta to save the lookup | ||
429 | // // on the other end!! | ||
430 | // m_FriendsSimConnector.GrantRights(region, requester, target, myFlags, rights); | ||
431 | // } | ||
432 | // } | ||
433 | // } | ||
434 | //} | ||
435 | |||
436 | |||
437 | } | ||
438 | } | ||
diff --git a/OpenSim/Region/CoreModules/Framework/UserManagement/UserManagementModule.cs b/OpenSim/Region/CoreModules/Framework/UserManagement/UserManagementModule.cs index 4cc6905..795de09 100644 --- a/OpenSim/Region/CoreModules/Framework/UserManagement/UserManagementModule.cs +++ b/OpenSim/Region/CoreModules/Framework/UserManagement/UserManagementModule.cs | |||
@@ -141,6 +141,7 @@ namespace OpenSim.Region.CoreModules.Framework.UserManagement | |||
141 | 141 | ||
142 | void HandleUUIDNameRequest(UUID uuid, IClientAPI remote_client) | 142 | void HandleUUIDNameRequest(UUID uuid, IClientAPI remote_client) |
143 | { | 143 | { |
144 | m_log.DebugFormat("[XXX] HandleUUIDNameRequest {0}", uuid); | ||
144 | if (m_Scenes[0].LibraryService != null && (m_Scenes[0].LibraryService.LibraryRootFolder.Owner == uuid)) | 145 | if (m_Scenes[0].LibraryService != null && (m_Scenes[0].LibraryService.LibraryRootFolder.Owner == uuid)) |
145 | { | 146 | { |
146 | remote_client.SendNameReply(uuid, "Mr", "OpenSim"); | 147 | remote_client.SendNameReply(uuid, "Mr", "OpenSim"); |
@@ -210,6 +211,7 @@ namespace OpenSim.Region.CoreModules.Framework.UserManagement | |||
210 | 211 | ||
211 | public string GetUserName(UUID uuid) | 212 | public string GetUserName(UUID uuid) |
212 | { | 213 | { |
214 | m_log.DebugFormat("[XXX] GetUserName {0}", uuid); | ||
213 | string[] names = GetUserNames(uuid); | 215 | string[] names = GetUserNames(uuid); |
214 | if (names.Length == 2) | 216 | if (names.Length == 2) |
215 | { | 217 | { |
diff --git a/OpenSim/Region/CoreModules/ServiceConnectorsIn/Hypergrid/HypergridServiceInConnectorModule.cs b/OpenSim/Region/CoreModules/ServiceConnectorsIn/Hypergrid/HypergridServiceInConnectorModule.cs index d2343c9..f5b6817 100644 --- a/OpenSim/Region/CoreModules/ServiceConnectorsIn/Hypergrid/HypergridServiceInConnectorModule.cs +++ b/OpenSim/Region/CoreModules/ServiceConnectorsIn/Hypergrid/HypergridServiceInConnectorModule.cs | |||
@@ -115,6 +115,7 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsIn.Hypergrid | |||
115 | 115 | ||
116 | new UserAgentServerConnector(m_Config, MainServer.Instance); | 116 | new UserAgentServerConnector(m_Config, MainServer.Instance); |
117 | new HeloServiceInConnector(m_Config, MainServer.Instance, "HeloService"); | 117 | new HeloServiceInConnector(m_Config, MainServer.Instance, "HeloService"); |
118 | new HGFriendsServerConnector(m_Config, MainServer.Instance, "HGFriendsService"); | ||
118 | } | 119 | } |
119 | scene.RegisterModuleInterface<IGatekeeperService>(m_HypergridHandler.GateKeeper); | 120 | scene.RegisterModuleInterface<IGatekeeperService>(m_HypergridHandler.GateKeeper); |
120 | } | 121 | } |