diff --git a/OpenSim/Region/CoreModules/Avatar/Friends/FriendsModule.cs b/OpenSim/Region/CoreModules/Avatar/Friends/FriendsModule.cs index f64c161271..fc6325dc3d 100644 --- a/OpenSim/Region/CoreModules/Avatar/Friends/FriendsModule.cs +++ b/OpenSim/Region/CoreModules/Avatar/Friends/FriendsModule.cs @@ -162,7 +162,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Friends } } - protected void InitModule(IConfigSource config) + protected virtual void InitModule(IConfigSource config) { IConfig friendsConfig = config.Configs["Friends"]; if (friendsConfig != null) @@ -546,7 +546,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Friends } } - private void OnInstantMessage(IClientAPI client, GridInstantMessage im) + protected virtual void OnInstantMessage(IClientAPI client, GridInstantMessage im) { if ((InstantMessageDialog)im.dialog == InstantMessageDialog.FriendshipOffered) { diff --git a/OpenSim/Region/CoreModules/Avatar/Friends/HGFriendsModule.cs b/OpenSim/Region/CoreModules/Avatar/Friends/HGFriendsModule.cs index 9a6d277252..3728b85a16 100644 --- a/OpenSim/Region/CoreModules/Avatar/Friends/HGFriendsModule.cs +++ b/OpenSim/Region/CoreModules/Avatar/Friends/HGFriendsModule.cs @@ -50,6 +50,8 @@ namespace OpenSim.Region.CoreModules.Avatar.Friends { private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); + private int m_levelHGFriends = 0; + IUserManagement m_uMan; public IUserManagement UserManagementModule { @@ -87,6 +89,21 @@ namespace OpenSim.Region.CoreModules.Avatar.Friends m_StatusNotifier = new HGStatusNotifier(this); } + protected override void InitModule(IConfigSource config) + { + base.InitModule(config); + + // Additionally to the base method + IConfig friendsConfig = config.Configs["HGFriendsModule"]; + if (friendsConfig != null) + { + m_levelHGFriends = friendsConfig.GetInt("LevelHGFriends", 0); + + // TODO: read in all config variables pertaining to + // HG friendship permissions + } + } + #endregion #region IFriendsSimConnector @@ -105,6 +122,35 @@ namespace OpenSim.Region.CoreModules.Avatar.Friends #endregion + protected override void OnInstantMessage(IClientAPI client, GridInstantMessage im) + { + if ((InstantMessageDialog)im.dialog == InstantMessageDialog.FriendshipOffered) + { + // we got a friendship offer + UUID principalID = new UUID(im.fromAgentID); + UUID friendID = new UUID(im.toAgentID); + + // Check if friendID is foreigner and if principalID has the permission + // to request friendships with foreigners. If not, return immediately. + if (!UserManagementModule.IsLocalGridUser(friendID)) + { + ScenePresence avatar = null; + ((Scene)client.Scene).TryGetScenePresence(principalID, out avatar); + + if (avatar == null) + return; + + if (avatar.UserLevel < m_levelHGFriends) + { + client.SendAgentAlertMessage("Unable to send friendship invitation to foreigner. Insufficient permissions.", false); + return; + } + } + } + + base.OnInstantMessage(client, im); + } + protected override void OnApproveFriendRequest(IClientAPI client, UUID friendID, List callingCardFolders) { // Update the local cache. Yes, we need to do it right here diff --git a/bin/config-include/GridCommon.ini.example b/bin/config-include/GridCommon.ini.example index fa6f5258c5..8d7f6fc427 100644 --- a/bin/config-include/GridCommon.ini.example +++ b/bin/config-include/GridCommon.ini.example @@ -137,6 +137,10 @@ ;; uncomment the next line. You may want to do this on sims that have licensed content. ; OutboundPermission = False +[HGFriendsModule] + ; User level required to be able to send friendship invitations to foreign users + ;LevelHGFriends = 0; + [UserAgentService] ; ; === HG ONLY === diff --git a/bin/config-include/StandaloneCommon.ini.example b/bin/config-include/StandaloneCommon.ini.example index 8fe64df93e..e4bc548967 100644 --- a/bin/config-include/StandaloneCommon.ini.example +++ b/bin/config-include/StandaloneCommon.ini.example @@ -61,6 +61,10 @@ ;; uncomment the next line. You may want to do this on sims that have licensed content. ; OutboundPermission = False +[HGFriendsModule] + ; User level required to be able to send friendship invitations to foreign users + ;LevelHGFriends = 0; + [GridService] ;; For in-memory region storage (default) StorageProvider = "OpenSim.Data.Null.dll:NullRegionData"