From c1320112a9365a95fd2f08af6a97dde8199adf17 Mon Sep 17 00:00:00 2001 From: Justin Clarke Casey Date: Tue, 23 Dec 2008 17:16:47 +0000 Subject: [PATCH] * Add a method to allow friendship offers to a logged in client from an offline user directly from the server --- OpenSim/Framework/UserProfileData.cs | 8 +++ .../Environment/Interfaces/IFriendsModule.cs | 49 +++++++++++++++++++ .../Modules/Avatar/Friends/FriendsModule.cs | 27 ++++++++-- .../InstantMessage/MessageTransferModule.cs | 2 +- OpenSim/Region/Environment/Scenes/Scene.cs | 1 - .../Shared/Api/Implementation/LSL_Api.cs | 1 - 6 files changed, 81 insertions(+), 7 deletions(-) create mode 100644 OpenSim/Region/Environment/Interfaces/IFriendsModule.cs diff --git a/OpenSim/Framework/UserProfileData.cs b/OpenSim/Framework/UserProfileData.cs index b6f309d5a0..51678e402b 100644 --- a/OpenSim/Framework/UserProfileData.cs +++ b/OpenSim/Framework/UserProfileData.cs @@ -200,6 +200,14 @@ namespace OpenSim.Framework get { return _surname; } set { _surname = value; } } + + /// + /// The concatentation of the various name components. + /// + public string Name + { + get { return String.Format("{0} {1}", _firstname, _surname); } + } public string Email { diff --git a/OpenSim/Region/Environment/Interfaces/IFriendsModule.cs b/OpenSim/Region/Environment/Interfaces/IFriendsModule.cs new file mode 100644 index 0000000000..5d3376c125 --- /dev/null +++ b/OpenSim/Region/Environment/Interfaces/IFriendsModule.cs @@ -0,0 +1,49 @@ +/* + * Copyright (c) Contributors, http://opensimulator.org/ + * See CONTRIBUTORS.TXT for a full list of copyright holders. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of the OpenSim Project nor the + * names of its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +using OpenMetaverse; +using OpenSim.Framework; + +namespace OpenSim.Region.Environment.Interfaces +{ + public interface IFriendsModule + { + /// + /// Offer a friendship to a user from the server end rather than by direct initiation from a client. + /// + /// + /// A user with this id must existing in the user data store, but need not be logged on. + /// + /// + /// An actually logged in client to which the offer is being made. + /// FIXME: This is somewhat too tightly coupled - it should arguably be possible to offer friendships even if the + /// receiving user is not currently online. + /// + /// + void OfferFriendship(UUID fromUserId, IClientAPI toUserClient, string offerMessage); + } +} diff --git a/OpenSim/Region/Environment/Modules/Avatar/Friends/FriendsModule.cs b/OpenSim/Region/Environment/Modules/Avatar/Friends/FriendsModule.cs index 134650866a..a1f0bf512d 100644 --- a/OpenSim/Region/Environment/Modules/Avatar/Friends/FriendsModule.cs +++ b/OpenSim/Region/Environment/Modules/Avatar/Friends/FriendsModule.cs @@ -80,7 +80,7 @@ namespace OpenSim.Region.Environment.Modules.Avatar.Friends - Terminate Friendship messages (single) */ - public class FriendsModule : IRegionModule + public class FriendsModule : IRegionModule, IFriendsModule { private class Transaction { @@ -126,6 +126,8 @@ namespace OpenSim.Region.Environment.Modules.Avatar.Friends m_scenes[scene.RegionInfo.RegionHandle] = scene; } + scene.RegisterModuleInterface(this); + scene.EventManager.OnNewClient += OnNewClient; scene.EventManager.OnIncomingInstantMessage += OnGridInstantMessage; scene.EventManager.OnAvatarEnteringNewParcel += AvatarEnteringParcel; @@ -375,6 +377,24 @@ namespace OpenSim.Region.Environment.Modules.Avatar.Friends } return returnAgent; } + + public void OfferFriendship(UUID fromUserId, IClientAPI toUserClient, string offerMessage) + { + CachedUserInfo userInfo = m_initialScene.CommsManager.UserProfileCacheService.GetUserDetails(fromUserId); + + if (userInfo != null) + { + GridInstantMessage msg = new GridInstantMessage( + toUserClient.Scene, fromUserId, userInfo.UserProfile.Name, toUserClient.AgentId, + (byte)InstantMessageDialog.FriendshipOffered, offerMessage, false, Vector3.Zero); + + FriendshipOffered(msg); + } + else + { + m_log.ErrorFormat("[FRIENDS]: No user found for id {0} in OfferFriendship()", fromUserId); + } + } #region FriendRequestHandling @@ -385,7 +405,7 @@ namespace OpenSim.Region.Environment.Modules.Avatar.Friends if (im.dialog == (byte)InstantMessageDialog.FriendshipOffered) // 38 { - FriendshipOffered(client, im); + FriendshipOffered(im); } else if (im.dialog == (byte)InstantMessageDialog.FriendshipAccepted) // 39 { @@ -403,7 +423,7 @@ namespace OpenSim.Region.Environment.Modules.Avatar.Friends /// May not currently be used - see OnApproveFriendRequest() instead /// /// - private void FriendshipOffered(IClientAPI client, GridInstantMessage im) + private void FriendshipOffered(GridInstantMessage im) { // this is triggered by the initiating agent: // A local agent offers friendship to some possibly remote friend. @@ -422,7 +442,6 @@ namespace OpenSim.Region.Environment.Modules.Avatar.Friends // be sneeky and use the initiator-UUID as transactionID. This means we can be stateless. // we have to look up the agent name on friendship-approval, though. im.imSessionID = im.fromAgentID; - im.fromAgentName = client.Name; if (m_TransferModule != null) { diff --git a/OpenSim/Region/Environment/Modules/Avatar/InstantMessage/MessageTransferModule.cs b/OpenSim/Region/Environment/Modules/Avatar/InstantMessage/MessageTransferModule.cs index 3af65a669f..838d42c640 100644 --- a/OpenSim/Region/Environment/Modules/Avatar/InstantMessage/MessageTransferModule.cs +++ b/OpenSim/Region/Environment/Modules/Avatar/InstantMessage/MessageTransferModule.cs @@ -99,7 +99,7 @@ namespace OpenSim.Region.Environment.Modules.Avatar.InstantMessage { UUID toAgentID = new UUID(im.toAgentID); - m_log.DebugFormat("[INSTANT MESSAGE]: Attempting delivery of IM fromn {0} to {1}", im.fromAgentName, toAgentID.ToString()); + m_log.DebugFormat("[INSTANT MESSAGE]: Attempting delivery of IM from {0} to {1}", im.fromAgentName, toAgentID.ToString()); // Try root avatar only first foreach (Scene scene in m_Scenes) diff --git a/OpenSim/Region/Environment/Scenes/Scene.cs b/OpenSim/Region/Environment/Scenes/Scene.cs index 06354cfa3b..d4d5b90ce9 100644 --- a/OpenSim/Region/Environment/Scenes/Scene.cs +++ b/OpenSim/Region/Environment/Scenes/Scene.cs @@ -2270,7 +2270,6 @@ namespace OpenSim.Region.Environment.Scenes client.OnUpdatePrimGroupScale += m_sceneGraph.UpdatePrimGroupScale; client.OnUpdateExtraParams += m_sceneGraph.UpdateExtraParam; client.OnUpdatePrimShape += m_sceneGraph.UpdatePrimShape; - //client.OnRequestMapBlocks += RequestMapBlocks; // handled in a module now. client.OnUpdatePrimTexture += m_sceneGraph.UpdatePrimTexture; client.OnTeleportLocationRequest += RequestTeleportLocation; client.OnTeleportLandmarkRequest += RequestTeleportLandmark; diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs index 5b2da4f48b..89911ec823 100644 --- a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs +++ b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs @@ -2564,7 +2564,6 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api if ((m_host.TaskInventory[InventorySelf()].PermsMask & ScriptBaseClass.PERMISSION_TAKE_CONTROLS) != 0) { presence.RegisterControlEventsToScript(controls, accept, pass_on, m_localID, m_itemID); - } } }