From dc88dc2c3dde7c90e2e2fc094d91bb0915ff1c2f Mon Sep 17 00:00:00 2001 From: Diva Canto Date: Fri, 26 Feb 2010 17:33:08 -0800 Subject: More flesh to FriendsModule. Still incomplete. --- .../CoreModules/Avatar/Friends/FriendsModule.cs | 67 ++++++++++++++++++++++ 1 file changed, 67 insertions(+) (limited to 'OpenSim/Region/CoreModules/Avatar') diff --git a/OpenSim/Region/CoreModules/Avatar/Friends/FriendsModule.cs b/OpenSim/Region/CoreModules/Avatar/Friends/FriendsModule.cs index f2ab174..7094213 100644 --- a/OpenSim/Region/CoreModules/Avatar/Friends/FriendsModule.cs +++ b/OpenSim/Region/CoreModules/Avatar/Friends/FriendsModule.cs @@ -45,6 +45,7 @@ using OpenSim.Framework.Servers.HttpServer; using log4net; using FriendInfo = OpenSim.Services.Interfaces.FriendInfo; using PresenceInfo = OpenSim.Services.Interfaces.PresenceInfo; +using GridRegion = OpenSim.Services.Interfaces.GridRegion; namespace OpenSim.Region.CoreModules.Avatar.Friends { @@ -94,6 +95,28 @@ namespace OpenSim.Region.CoreModules.Avatar.Friends } } + protected IFriendsService FriendsService + { + get + { + if (m_FriendsService == null) + { + if (m_Scenes.Count > 0) + m_FriendsService = m_Scenes[0].RequestModuleInterface(); + } + + return m_FriendsService; + } + } + + protected IGridService GridService + { + get + { + return m_Scenes[0].GridService; + } + } + public FriendsModule() : base("POST", "/friends") { @@ -431,22 +454,66 @@ namespace OpenSim.Region.CoreModules.Avatar.Friends private void OnInstantMessage(IClientAPI client, GridInstantMessage im) { + if (im.dialog == (byte)OpenMetaverse.InstantMessageDialog.FriendshipOffered) + { + // we got a friendship offer + UUID principalID = new UUID(im.fromAgentID); + UUID friendID = new UUID(im.toAgentID); + + // this user wants to be friends with the other user + FriendsService.StoreFriend(principalID, friendID.ToString(), 1); + + // Now let's ask the other user to be friends with this user + ForwardFriendshipOffer(principalID, friendID, im); + } + } + + private void ForwardFriendshipOffer(UUID agentID, UUID friendID, GridInstantMessage im) + { + IClientAPI friendClient = LocateClientObject(friendID); + if (friendClient != null) + { + // the prospective friend in this sim as root agent + friendClient.SendInstantMessage(im); + // we're done + return; + } + + // The prospective friend is not here [as root]. Let's forward. + PresenceInfo[] friendSessions = PresenceService.GetAgents(new string[] { friendID.ToString() }); + PresenceInfo friendSession = PresenceInfo.GetOnlinePresence(friendSessions); + if (friendSession != null) + { + GridRegion region = GridService.GetRegionByUUID(m_Scenes[0].RegionInfo.ScopeID, friendSession.RegionID); + // ... + // m_FriendsSimConnector.FriendshipOffered(region, agentID, friemdID, im.message); + } } private void OnApproveFriendRequest(IClientAPI client, UUID agentID, UUID friendID, List callingCardFolders) { + FriendsService.StoreFriend(agentID, friendID.ToString(), 1); + + // TODO: Notify the new friend } private void OnDenyFriendRequest(IClientAPI client, UUID agentID, UUID friendID, List callingCardFolders) { + // TODO: Notify the friend-wanna-be } private void OnTerminateFriendship(IClientAPI client, UUID agentID, UUID exfriendID) { + FriendsService.Delete(agentID, exfriendID.ToString()); + + // TODO: Notify the exfriend } private void OnGrantUserRights(IClientAPI remoteClient, UUID requester, UUID target, int rights) { + FriendsService.StoreFriend(requester, target.ToString(), rights); + + // TODO: Notify the friend } } } -- cgit v1.1