From c7f2debd38e35b0f049df9cc33ff8fb4eede40db Mon Sep 17 00:00:00 2001 From: Melanie Date: Wed, 15 Aug 2012 18:21:28 +0200 Subject: Fix and finish the extra parameters storage system for MySQL --- OpenSim/Data/MySQL/MySQLSimulationData.cs | 58 ++++++++++++++++++++++++++++++- 1 file changed, 57 insertions(+), 1 deletion(-) diff --git a/OpenSim/Data/MySQL/MySQLSimulationData.cs b/OpenSim/Data/MySQL/MySQLSimulationData.cs index be985ab..3fc04ee 100644 --- a/OpenSim/Data/MySQL/MySQLSimulationData.cs +++ b/OpenSim/Data/MySQL/MySQLSimulationData.cs @@ -1969,15 +1969,71 @@ namespace OpenSim.Data.MySQL public void SaveExtra(UUID regionID, string name, string val) { + lock (m_dbLock) + { + using (MySqlConnection dbcon = new MySqlConnection(m_connectionString)) + { + dbcon.Open(); + + using (MySqlCommand cmd = dbcon.CreateCommand()) + { + cmd.CommandText = "replace into regionextra values (?RegionID, ?Name, ?value)"; + cmd.Parameters.AddWithValue("?RegionID", regionID.ToString()); + cmd.Parameters.AddWithValue("?Name", name); + cmd.Parameters.AddWithValue("?value", val); + + cmd.ExecuteNonQuery(); + } + } + } } public void RemoveExtra(UUID regionID, string name) { + lock (m_dbLock) + { + using (MySqlConnection dbcon = new MySqlConnection(m_connectionString)) + { + dbcon.Open(); + + using (MySqlCommand cmd = dbcon.CreateCommand()) + { + cmd.CommandText = "delete from regionextra where RegionID=?RegionID and Name=?Name"; + cmd.Parameters.AddWithValue("?RegionID", regionID.ToString()); + cmd.Parameters.AddWithValue("?Name", name); + + cmd.ExecuteNonQuery(); + } + } + } } public Dictionary GetExtra(UUID regionID) { - return null; + Dictionary ret = new Dictionary(); + + lock (m_dbLock) + { + using (MySqlConnection dbcon = new MySqlConnection(m_connectionString)) + { + dbcon.Open(); + + using (MySqlCommand cmd = dbcon.CreateCommand()) + { + cmd.CommandText = "select * from regionextra where RegionID=?RegionID"; + cmd.Parameters.AddWithValue("?RegionID", regionID.ToString()); + using (IDataReader r = cmd.ExecuteReader()) + { + while (r.Read()) + { + ret[r["Name"].ToString()] = r["value"].ToString(); + } + } + } + } + } + + return ret; } } } -- cgit v1.1 From c27ff70d5c9c7f91ff63b197359de84f7508ec60 Mon Sep 17 00:00:00 2001 From: Melanie Date: Wed, 15 Aug 2012 18:22:16 +0200 Subject: Add support for the extra params to scene and the event manager --- OpenSim/Region/Framework/Scenes/EventManager.cs | 23 +++++++++++++++ OpenSim/Region/Framework/Scenes/Scene.cs | 39 +++++++++++++++++++++++++ 2 files changed, 62 insertions(+) diff --git a/OpenSim/Region/Framework/Scenes/EventManager.cs b/OpenSim/Region/Framework/Scenes/EventManager.cs index 6dea2f0..4d65be9 100644 --- a/OpenSim/Region/Framework/Scenes/EventManager.cs +++ b/OpenSim/Region/Framework/Scenes/EventManager.cs @@ -213,6 +213,9 @@ namespace OpenSim.Region.Framework.Scenes /// public event NewScript OnNewScript; + public delegate void ExtraSettingChangedDelegate(Scene scene, string name, string value); + public event ExtraSettingChangedDelegate OnExtraSettingChanged; + public virtual void TriggerNewScript(UUID clientID, SceneObjectPart part, UUID itemID) { NewScript handlerNewScript = OnNewScript; @@ -2591,5 +2594,25 @@ namespace OpenSim.Region.Framework.Scenes } } + public void TriggerExtraSettingChanged(Scene scene, string name, string val) + { + ExtraSettingChangedDelegate handler = OnExtraSettingChanged; + + if (handler != null) + { + foreach (ExtraSettingChangedDelegate d in handler.GetInvocationList()) + { + try + { + d(scene, name, val); + } + catch (Exception e) + { + m_log.ErrorFormat("[EVENT MANAGER]: Delegate for ExtraSettingChanged failed - continuing {0} - {1}", + e.Message, e.StackTrace); + } + } + } + } } } diff --git a/OpenSim/Region/Framework/Scenes/Scene.cs b/OpenSim/Region/Framework/Scenes/Scene.cs index 59f49ea..0e5ddfd 100644 --- a/OpenSim/Region/Framework/Scenes/Scene.cs +++ b/OpenSim/Region/Framework/Scenes/Scene.cs @@ -5447,5 +5447,44 @@ namespace OpenSim.Region.Framework.Scenes callback(asset); } + + public string GetExtraSetting(string name) + { + string val; + + if (!m_extraSettings.TryGetValue(name, out val)) + return String.Empty; + + return val; + } + + public void StoreExtraSetting(string name, string val) + { + string oldVal; + + if (m_extraSettings.TryGetValue(name, out oldVal)) + { + if (oldVal == val) + return; + } + + m_extraSettings[name] = val; + + m_SimulationDataService.SaveExtra(RegionInfo.RegionID, name, val); + + m_eventManager.TriggerExtraSettingChanged(this, name, val); + } + + public void RemoveExtraSetting(string name) + { + if (!m_extraSettings.ContainsKey(name)) + return; + + m_extraSettings.Remove(name); + + m_SimulationDataService.RemoveExtra(RegionInfo.RegionID, name); + + m_eventManager.TriggerExtraSettingChanged(this, name, String.Empty); + } } } -- cgit v1.1 From ebbf349c6a883ea641ee02b0517313f6391f60ef Mon Sep 17 00:00:00 2001 From: Melanie Date: Wed, 15 Aug 2012 18:22:52 +0200 Subject: Let the temp attachment module add a command to allow attaching without permissions and add support for this (incomplete!) to LSL --- .../Avatar/Attachments/TempAttachmentsModule.cs | 41 ++++++++++++- .../Shared/Api/Implementation/LSL_Api.cs | 70 ++++++++++++---------- 2 files changed, 77 insertions(+), 34 deletions(-) diff --git a/OpenSim/Region/OptionalModules/Avatar/Attachments/TempAttachmentsModule.cs b/OpenSim/Region/OptionalModules/Avatar/Attachments/TempAttachmentsModule.cs index 27ba5c9..cb89cd1 100644 --- a/OpenSim/Region/OptionalModules/Avatar/Attachments/TempAttachmentsModule.cs +++ b/OpenSim/Region/OptionalModules/Avatar/Attachments/TempAttachmentsModule.cs @@ -43,15 +43,13 @@ using OpenSim.Region.Framework.Scenes; namespace OpenSim.Region.OptionalModules.Avatar.Attachments { - /// - /// A module that just holds commands for inspecting avatar appearance. - /// [Extension(Path = "/OpenSim/RegionModules", NodeName = "RegionModule", Id = "TempAttachmentsModule")] public class TempAttachmentsModule : INonSharedRegionModule { private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); private Scene m_scene; + private IRegionConsole m_console; public void Initialise(IConfigSource configSource) { @@ -74,6 +72,12 @@ namespace OpenSim.Region.OptionalModules.Avatar.Attachments { comms.RegisterScriptInvocation( this, "llAttachToAvatarTemp"); m_log.DebugFormat("[TEMP ATTACHS]: Registered script functions"); + m_console = scene.RequestModuleInterface(); + + if (m_console != null) + { + m_console.AddCommand("TempATtachModule", false, "set auto_grant_attach_perms", "set auto_grant_attach_perms true|false", "Allow objects owned by the region owner os estate managers to obtain attach permissions without asking the user", SetAutoGrantAttachPerms); + } } else { @@ -95,6 +99,37 @@ namespace OpenSim.Region.OptionalModules.Avatar.Attachments get { return "TempAttachmentsModule"; } } + private void SendConsoleOutput(UUID agentID, string text) + { + if (m_console == null) + return; + + m_console.SendConsoleOutput(agentID, text); + } + + private void SetAutoGrantAttachPerms(string module, string[] parms) + { + UUID agentID = new UUID(parms[parms.Length - 1]); + Array.Resize(ref parms, parms.Length - 1); + + if (parms.Length != 3) + { + SendConsoleOutput(agentID, "Command parameter error"); + return; + } + + string val = parms[2]; + if (val != "true" && val != "false") + { + SendConsoleOutput(agentID, "Command parameter error"); + return; + } + + m_scene.StoreExtraSetting("auto_grant_attach_perms", val); + + SendConsoleOutput(agentID, String.Format("auto_grant_attach_perms set to {0}", val)); + } + private void llAttachToAvatarTemp(UUID host, UUID script, int attachmentPoint) { SceneObjectPart hostPart = m_scene.GetSceneObjectPart(host); diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs index 1287709..8b53edc 100644 --- a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs +++ b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs @@ -3424,53 +3424,61 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api m_host.AddScriptLPS(1); + int implicitPerms = 0; + if (m_host.ParentGroup.IsAttachment && (UUID)agent == m_host.ParentGroup.AttachedAvatar) { // When attached, certain permissions are implicit if requested from owner - int implicitPerms = ScriptBaseClass.PERMISSION_TAKE_CONTROLS | + implicitPerms = ScriptBaseClass.PERMISSION_TAKE_CONTROLS | ScriptBaseClass.PERMISSION_TRIGGER_ANIMATION | ScriptBaseClass.PERMISSION_CONTROL_CAMERA | ScriptBaseClass.PERMISSION_ATTACH; - - if ((perm & (~implicitPerms)) == 0) // Requested only implicit perms + } + else + { + bool sitting = false; + if (m_host.SitTargetAvatar == agentID) { - lock (m_host.TaskInventory) + sitting = true; + } + else + { + foreach (SceneObjectPart p in m_host.ParentGroup.Parts) { - m_host.TaskInventory[m_item.ItemID].PermsGranter = agentID; - m_host.TaskInventory[m_item.ItemID].PermsMask = perm; + if (p.SitTargetAvatar == agentID) + sitting = true; } + } - m_ScriptEngine.PostScriptEvent(m_item.ItemID, new EventParams( - "run_time_permissions", new Object[] { - new LSL_Integer(perm) }, - new DetectParams[0])); - - return; + if (sitting) + { + // When agent is sitting, certain permissions are implicit if requested from sitting agent + implicitPerms = ScriptBaseClass.PERMISSION_TRIGGER_ANIMATION | + ScriptBaseClass.PERMISSION_CONTROL_CAMERA | + ScriptBaseClass.PERMISSION_TRACK_CAMERA | + ScriptBaseClass.PERMISSION_TAKE_CONTROLS; + } + else + { + if (World.GetExtraSetting("auto_grant_attach_perms") == "true") + implicitPerms = ScriptBaseClass.PERMISSION_ATTACH; } } - else if (m_host.SitTargetAvatar == agentID) // Sitting avatar - { - // When agent is sitting, certain permissions are implicit if requested from sitting agent - int implicitPerms = ScriptBaseClass.PERMISSION_TRIGGER_ANIMATION | - ScriptBaseClass.PERMISSION_CONTROL_CAMERA | - ScriptBaseClass.PERMISSION_TRACK_CAMERA | - ScriptBaseClass.PERMISSION_TAKE_CONTROLS; - if ((perm & (~implicitPerms)) == 0) // Requested only implicit perms + if ((perm & (~implicitPerms)) == 0) // Requested only implicit perms + { + lock (m_host.TaskInventory) { - lock (m_host.TaskInventory) - { - m_host.TaskInventory[m_item.ItemID].PermsGranter = agentID; - m_host.TaskInventory[m_item.ItemID].PermsMask = perm; - } + m_host.TaskInventory[m_item.ItemID].PermsGranter = agentID; + m_host.TaskInventory[m_item.ItemID].PermsMask = perm; + } - m_ScriptEngine.PostScriptEvent(m_item.ItemID, new EventParams( - "run_time_permissions", new Object[] { - new LSL_Integer(perm) }, - new DetectParams[0])); + m_ScriptEngine.PostScriptEvent(m_item.ItemID, new EventParams( + "run_time_permissions", new Object[] { + new LSL_Integer(perm) }, + new DetectParams[0])); - return; - } + return; } ScenePresence presence = World.GetScenePresence(agentID); -- cgit v1.1