From 5b43f9cac47267a5400001445b05f137ae452ee7 Mon Sep 17 00:00:00 2001 From: Diva Canto Date: Thu, 6 Jan 2011 12:47:13 -0800 Subject: [PATCH 01/20] HG bug fix. Must wait for client's UDP contact before getting scene presence. --- OpenSim/Region/Framework/Scenes/Scene.cs | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/OpenSim/Region/Framework/Scenes/Scene.cs b/OpenSim/Region/Framework/Scenes/Scene.cs index e27b2ba7ab..12fd813e0c 100644 --- a/OpenSim/Region/Framework/Scenes/Scene.cs +++ b/OpenSim/Region/Framework/Scenes/Scene.cs @@ -2592,12 +2592,19 @@ namespace OpenSim.Region.Framework.Scenes // and the scene presence and the client, if they exist try { - ScenePresence sp = GetScenePresence(agentID); - PresenceService.LogoutAgent(sp.ControllingClient.SessionId); - + // We need to wait for the client to make UDP contact first. + // It's the UDP contact that creates the scene presence + ScenePresence sp = WaitGetScenePresence(agentID); if (sp != null) - sp.ControllingClient.Close(); + { + PresenceService.LogoutAgent(sp.ControllingClient.SessionId); + sp.ControllingClient.Close(); + } + else + { + m_log.WarnFormat("[SCENE]: Could not find scene presence for {0}", agentID); + } // BANG! SLASH! m_authenticateHandler.RemoveCircuit(agentID); From 21dedb573be61a52cbbcc519f999f6046e20e070 Mon Sep 17 00:00:00 2001 From: Diva Canto Date: Thu, 6 Jan 2011 12:48:28 -0800 Subject: [PATCH 02/20] HG map tile fetch: handle cached images appropriately. --- .../Hypergrid/GatekeeperServiceConnector.cs | 16 ++++++++++++---- OpenSim/Services/GridService/HypergridLinker.cs | 2 +- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/OpenSim/Services/Connectors/Hypergrid/GatekeeperServiceConnector.cs b/OpenSim/Services/Connectors/Hypergrid/GatekeeperServiceConnector.cs index 1aa3282dac..8ab323ad41 100644 --- a/OpenSim/Services/Connectors/Hypergrid/GatekeeperServiceConnector.cs +++ b/OpenSim/Services/Connectors/Hypergrid/GatekeeperServiceConnector.cs @@ -158,10 +158,17 @@ namespace OpenSim.Services.Connectors.Hypergrid try { WebClient c = new WebClient(); - //m_log.Debug("JPEG: " + imageURL); string name = regionID.ToString(); filename = Path.Combine(storagePath, name + ".jpg"); - c.DownloadFile(imageURL, filename); + m_log.DebugFormat("[GATEKEEPER SERVICE CONNECTOR]: Map image at {0}, cached at {1}", imageURL, filename); + if (!File.Exists(filename)) + { + m_log.DebugFormat("[GATEKEEPER SERVICE CONNECTOR]: downloading..."); + c.DownloadFile(imageURL, filename); + } + else + m_log.DebugFormat("[GATEKEEPER SERVICE CONNECTOR]: using cached image"); + bitmap = new Bitmap(filename); //m_log.Debug("Size: " + m.PhysicalDimension.Height + "-" + m.PhysicalDimension.Width); byte[] imageData = OpenJPEG.EncodeFromImage(bitmap, true); @@ -172,10 +179,11 @@ namespace OpenSim.Services.Connectors.Hypergrid ass.Data = imageData; - m_AssetService.Store(ass); + mapTile = ass.FullID; // finally - mapTile = ass.FullID; + m_AssetService.Store(ass); + } catch // LEGIT: Catching problems caused by OpenJPEG p/invoke { diff --git a/OpenSim/Services/GridService/HypergridLinker.cs b/OpenSim/Services/GridService/HypergridLinker.cs index c02c81306f..16fcc65492 100644 --- a/OpenSim/Services/GridService/HypergridLinker.cs +++ b/OpenSim/Services/GridService/HypergridLinker.cs @@ -324,7 +324,7 @@ namespace OpenSim.Services.GridService regInfo.TerrainImage = m_GatekeeperConnector.GetMapImage(regionID, imageURL, m_MapTileDirectory); AddHyperlinkRegion(regInfo, handle); - m_log.Info("[HYPERGRID LINKER]: Successfully linked to region_uuid " + regInfo.RegionID); + m_log.InfoFormat("[HYPERGRID LINKER]: Successfully linked to region_uuid {0} with image {1}", regInfo.RegionID, regInfo.TerrainImage); return true; } From 81587466e72cfb989c0cb3fa74ae5ff6e7f861bb Mon Sep 17 00:00:00 2001 From: Diva Canto Date: Thu, 6 Jan 2011 12:53:54 -0800 Subject: [PATCH 03/20] Map search: changed the flag sent to the client. It was 2 (???), now it's 0. This makes HG map tiles work on map search -- a longstanding annoyance. My map search tests were all ok, but since I don't understand these flag values, this may break something related to map search. --- .../Region/CoreModules/World/WorldMap/MapSearchModule.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/OpenSim/Region/CoreModules/World/WorldMap/MapSearchModule.cs b/OpenSim/Region/CoreModules/World/WorldMap/MapSearchModule.cs index bdd1a0b7c5..cc28a5b2ff 100644 --- a/OpenSim/Region/CoreModules/World/WorldMap/MapSearchModule.cs +++ b/OpenSim/Region/CoreModules/World/WorldMap/MapSearchModule.cs @@ -102,7 +102,7 @@ namespace OpenSim.Region.CoreModules.World.WorldMap GridRegion info = m_scene.GridService.GetRegionByName(m_scene.RegionInfo.ScopeID, mapName); if (info != null) regionInfos.Add(info); } - + m_log.DebugFormat("[MAPSEARCHMODULE]: search returned {0} regions", regionInfos.Count); List blocks = new List(); MapBlockData data; @@ -128,14 +128,14 @@ namespace OpenSim.Region.CoreModules.World.WorldMap data.Agents = 0; data.Access = 255; data.MapImageId = UUID.Zero; - data.Name = mapName; + data.Name = ""; // mapName; data.RegionFlags = 0; data.WaterHeight = 0; // not used data.X = 0; data.Y = 0; blocks.Add(data); - remoteClient.SendMapBlock(blocks, 2); + remoteClient.SendMapBlock(blocks, 0); } // private Scene GetClientScene(IClientAPI client) From fda56618e154c2fcbf76d57abfc66eb94156221e Mon Sep 17 00:00:00 2001 From: Diva Canto Date: Thu, 6 Jan 2011 16:17:43 -0800 Subject: [PATCH 04/20] Deal with possibly un-initialized scripts in object transfers. Mantis #5310 --- .../Region/ScriptEngine/Shared/Instance/ScriptInstance.cs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/OpenSim/Region/ScriptEngine/Shared/Instance/ScriptInstance.cs b/OpenSim/Region/ScriptEngine/Shared/Instance/ScriptInstance.cs index 8e712b60fe..783791f512 100644 --- a/OpenSim/Region/ScriptEngine/Shared/Instance/ScriptInstance.cs +++ b/OpenSim/Region/ScriptEngine/Shared/Instance/ScriptInstance.cs @@ -864,7 +864,10 @@ namespace OpenSim.Region.ScriptEngine.Shared.Instance public Dictionary GetVars() { - return m_Script.GetVars(); + if (m_Script != null) + return m_Script.GetVars(); + else + return new Dictionary(); } public void SetVars(Dictionary vars) From 32a3f330eddfe2975e59ae7289b6a0033fb858e3 Mon Sep 17 00:00:00 2001 From: Diva Canto Date: Thu, 6 Jan 2011 17:42:16 -0800 Subject: [PATCH 05/20] Canonicalize URL endings for the UserAgentServiceConnector. --- .../Connectors/Hypergrid/UserAgentServiceConnector.cs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/OpenSim/Services/Connectors/Hypergrid/UserAgentServiceConnector.cs b/OpenSim/Services/Connectors/Hypergrid/UserAgentServiceConnector.cs index 7ddcfa61ae..c40a3474a3 100644 --- a/OpenSim/Services/Connectors/Hypergrid/UserAgentServiceConnector.cs +++ b/OpenSim/Services/Connectors/Hypergrid/UserAgentServiceConnector.cs @@ -60,7 +60,9 @@ namespace OpenSim.Services.Connectors.Hypergrid { Uri m_Uri = new Uri(m_ServerURL); IPAddress ip = Util.GetHostFromDNS(m_Uri.Host); - m_ServerURL = m_ServerURL.Replace(m_Uri.Host, ip.ToString()); ; + m_ServerURL = m_ServerURL.Replace(m_Uri.Host, ip.ToString()); + if (!m_ServerURL.EndsWith("/")) + m_ServerURL += "/"; } catch (Exception e) { @@ -87,6 +89,8 @@ namespace OpenSim.Services.Connectors.Hypergrid throw new Exception("UserAgent connector init error"); } m_ServerURL = serviceURI; + if (!m_ServerURL.EndsWith("/")) + m_ServerURL += "/"; m_log.DebugFormat("[USER AGENT CONNECTOR]: UserAgentServiceConnector started for {0}", m_ServerURL); } From 52f88f5739980bb53d126949725bf38daf5e0800 Mon Sep 17 00:00:00 2001 From: Diva Canto Date: Fri, 7 Jan 2011 10:04:39 -0800 Subject: [PATCH 06/20] Spawn a threadlet upon receiving requests to close agents. The operation may take too long, and we don't need to keep the caller waiting. --- .../Simulation/LocalSimulationConnector.cs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/OpenSim/Region/CoreModules/ServiceConnectorsOut/Simulation/LocalSimulationConnector.cs b/OpenSim/Region/CoreModules/ServiceConnectorsOut/Simulation/LocalSimulationConnector.cs index 37b403e8cc..2dd0099f83 100644 --- a/OpenSim/Region/CoreModules/ServiceConnectorsOut/Simulation/LocalSimulationConnector.cs +++ b/OpenSim/Region/CoreModules/ServiceConnectorsOut/Simulation/LocalSimulationConnector.cs @@ -300,7 +300,10 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Simulation if (s.RegionInfo.RegionID == destination.RegionID) { //m_log.Debug("[LOCAL COMMS]: Found region to SendCloseAgent"); - return s.IncomingCloseAgent(id); + // Let's spawn a threadlet right here, because this may take + // a while + Util.FireAndForget(delegate { s.IncomingCloseAgent(id); }); + return true; } } //m_log.Debug("[LOCAL COMMS]: region not found in SendCloseAgent"); From c18bcf3d8db61fd704b229da77fb3ecc190fa742 Mon Sep 17 00:00:00 2001 From: Diva Canto Date: Fri, 7 Jan 2011 10:25:49 -0800 Subject: [PATCH 07/20] A bit more frugal on the caller side of closing agents, now that the receiving end is async. No need for so much concurrency. --- .../Scenes/SceneCommunicationService.cs | 36 ++++++++++--------- 1 file changed, 20 insertions(+), 16 deletions(-) diff --git a/OpenSim/Region/Framework/Scenes/SceneCommunicationService.cs b/OpenSim/Region/Framework/Scenes/SceneCommunicationService.cs index 69ebe9efde..f8ff308893 100644 --- a/OpenSim/Region/Framework/Scenes/SceneCommunicationService.cs +++ b/OpenSim/Region/Framework/Scenes/SceneCommunicationService.cs @@ -258,13 +258,17 @@ namespace OpenSim.Region.Framework.Scenes } - public delegate void SendCloseChildAgentDelegate(UUID agentID, ulong regionHandle); + //public delegate void SendCloseChildAgentDelegate(UUID agentID, ulong regionHandle); + //private void SendCloseChildAgentCompleted(IAsyncResult iar) + //{ + // SendCloseChildAgentDelegate icon = (SendCloseChildAgentDelegate)iar.AsyncState; + // icon.EndInvoke(iar); + //} /// - /// This Closes child agents on neighboring regions - /// Calls an asynchronous method to do so.. so it doesn't lag the sim. + /// Closes a child agent on a given region /// - protected void SendCloseChildAgentAsync(UUID agentID, ulong regionHandle) + protected void SendCloseChildAgent(UUID agentID, ulong regionHandle) { m_log.Debug("[INTERGRID]: Sending close agent to " + regionHandle); @@ -277,21 +281,21 @@ namespace OpenSim.Region.Framework.Scenes m_scene.SimulationService.CloseAgent(destination, agentID); } - private void SendCloseChildAgentCompleted(IAsyncResult iar) - { - SendCloseChildAgentDelegate icon = (SendCloseChildAgentDelegate)iar.AsyncState; - icon.EndInvoke(iar); - } - + /// + /// Closes a child agents in a collection of regions. Does so asynchronously + /// so that the caller doesn't wait. + /// + /// + /// public void SendCloseChildAgentConnections(UUID agentID, List regionslst) { - foreach (ulong handle in regionslst) + Util.FireAndForget(delegate { - SendCloseChildAgentDelegate d = SendCloseChildAgentAsync; - d.BeginInvoke(agentID, handle, - SendCloseChildAgentCompleted, - d); - } + foreach (ulong handle in regionslst) + { + SendCloseChildAgent(agentID, handle); + } + }); } public List RequestNamedRegions(string name, int maxNumber) From 8c0e156b4d534cbc9ad21805529804610b7c78eb Mon Sep 17 00:00:00 2001 From: Diva Canto Date: Fri, 7 Jan 2011 11:38:54 -0800 Subject: [PATCH 08/20] Make HG map search consistent with new syntax for link-region, i.e. http://foo.org. Old syntax (foo.org) is still supported, but has surprising results when ppl search again, because internally the HG link names start with http. --- .../World/WorldMap/MapSearchModule.cs | 2 +- .../Services/GridService/HypergridLinker.cs | 80 ++++++++++--------- 2 files changed, 43 insertions(+), 39 deletions(-) diff --git a/OpenSim/Region/CoreModules/World/WorldMap/MapSearchModule.cs b/OpenSim/Region/CoreModules/World/WorldMap/MapSearchModule.cs index cc28a5b2ff..a9e46d04c2 100644 --- a/OpenSim/Region/CoreModules/World/WorldMap/MapSearchModule.cs +++ b/OpenSim/Region/CoreModules/World/WorldMap/MapSearchModule.cs @@ -102,7 +102,7 @@ namespace OpenSim.Region.CoreModules.World.WorldMap GridRegion info = m_scene.GridService.GetRegionByName(m_scene.RegionInfo.ScopeID, mapName); if (info != null) regionInfos.Add(info); } - m_log.DebugFormat("[MAPSEARCHMODULE]: search returned {0} regions", regionInfos.Count); + m_log.DebugFormat("[MAPSEARCHMODULE]: search {0} returned {1} regions", mapName, regionInfos.Count); List blocks = new List(); MapBlockData data; diff --git a/OpenSim/Services/GridService/HypergridLinker.cs b/OpenSim/Services/GridService/HypergridLinker.cs index 16fcc65492..588c1dd0ed 100644 --- a/OpenSim/Services/GridService/HypergridLinker.cs +++ b/OpenSim/Services/GridService/HypergridLinker.cs @@ -162,6 +162,7 @@ namespace OpenSim.Services.GridService #region Link Region + // from map search public GridRegion LinkRegion(UUID scopeID, string regionDescriptor) { string reason = string.Empty; @@ -171,7 +172,7 @@ namespace OpenSim.Services.GridService private static Random random = new Random(); - // From the command line link-region + // From the command line link-region (obsolete) and the map public GridRegion TryLinkRegionToCoords(UUID scopeID, string mapName, int xloc, int yloc, out string reason) { return TryLinkRegionToCoords(scopeID, mapName, xloc, yloc, UUID.Zero, out reason); @@ -180,45 +181,48 @@ namespace OpenSim.Services.GridService public GridRegion TryLinkRegionToCoords(UUID scopeID, string mapName, int xloc, int yloc, UUID ownerID, out string reason) { reason = string.Empty; - string host = "127.0.0.1"; - string portstr; - string regionName = ""; - uint port = 0; - string[] parts = mapName.Split(new char[] { ':' }); - if (parts.Length >= 1) + GridRegion regInfo = null; + + if (!mapName.StartsWith("http")) { - host = parts[0]; + string host = "127.0.0.1"; + string portstr; + string regionName = ""; + uint port = 0; + string[] parts = mapName.Split(new char[] { ':' }); + if (parts.Length >= 1) + { + host = parts[0]; + } + if (parts.Length >= 2) + { + portstr = parts[1]; + //m_log.Debug("-- port = " + portstr); + if (!UInt32.TryParse(portstr, out port)) + regionName = parts[1]; + } + // always take the last one + if (parts.Length >= 3) + { + regionName = parts[2]; + } + + + bool success = TryCreateLink(scopeID, xloc, yloc, regionName, port, host, ownerID, out regInfo, out reason); + if (success) + { + regInfo.RegionName = mapName; + return regInfo; + } } - if (parts.Length >= 2) + else { - portstr = parts[1]; - //m_log.Debug("-- port = " + portstr); - if (!UInt32.TryParse(portstr, out port)) + string[] parts = mapName.Split(new char[] {' '}); + string regionName = String.Empty; + if (parts.Length > 1) regionName = parts[1]; - } - // always take the last one - if (parts.Length >= 3) - { - regionName = parts[2]; - } - - //// Sanity check. - //try - //{ - // Util.GetHostFromDNS(host); - //} - //catch - //{ - // reason = "Malformed hostname"; - // return null; - //} - - GridRegion regInfo; - bool success = TryCreateLink(scopeID, xloc, yloc, regionName, port, host, ownerID, out regInfo, out reason); - if (success) - { - regInfo.RegionName = mapName; - return regInfo; + if (TryCreateLink(scopeID, xloc, yloc, regionName, 0, null, parts[0], ownerID, out regInfo, out reason)) + return regInfo; } return null; @@ -231,7 +235,7 @@ namespace OpenSim.Services.GridService public bool TryCreateLink(UUID scopeID, int xloc, int yloc, string remoteRegionName, uint externalPort, string externalHostName, string serverURI, UUID ownerID, out GridRegion regInfo, out string reason) { - m_log.DebugFormat("[HYPERGRID LINKER]: Link to {0}:{1}, in {2}-{3}", + m_log.DebugFormat("[HYPERGRID LINKER]: Link to {0} {1}, in {2}-{3}", ((serverURI == null) ? (externalHostName + ":" + externalPort) : serverURI), remoteRegionName, xloc / Constants.RegionSize, yloc / Constants.RegionSize); @@ -324,7 +328,7 @@ namespace OpenSim.Services.GridService regInfo.TerrainImage = m_GatekeeperConnector.GetMapImage(regionID, imageURL, m_MapTileDirectory); AddHyperlinkRegion(regInfo, handle); - m_log.InfoFormat("[HYPERGRID LINKER]: Successfully linked to region_uuid {0} with image {1}", regInfo.RegionID, regInfo.TerrainImage); + m_log.InfoFormat("[HYPERGRID LINKER]: Successfully linked to region {0} with image {1}", regInfo.RegionName, regInfo.TerrainImage); return true; } From 02e661f8dd8e714bd357ce4091a79cf282228b26 Mon Sep 17 00:00:00 2001 From: Diva Canto Date: Fri, 7 Jan 2011 11:39:22 -0800 Subject: [PATCH 09/20] Minor additional debug message. --- .../Framework/EntityTransfer/EntityTransferModule.cs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/OpenSim/Region/CoreModules/Framework/EntityTransfer/EntityTransferModule.cs b/OpenSim/Region/CoreModules/Framework/EntityTransfer/EntityTransferModule.cs index e5cefe4e92..8bf2bf86dd 100644 --- a/OpenSim/Region/CoreModules/Framework/EntityTransfer/EntityTransferModule.cs +++ b/OpenSim/Region/CoreModules/Framework/EntityTransfer/EntityTransferModule.cs @@ -1203,6 +1203,8 @@ namespace OpenSim.Region.CoreModules.Framework.EntityTransfer m_log.Debug("[ENTITY TRANSFER MODULE]: Completed inform client about neighbour " + endPoint.ToString()); } + if (!regionAccepted) + m_log.DebugFormat("[ENTITY TRANSFER MODULE]: Region {0} did not accept agent: {1}", reg.RegionName, reason); } /// From a1c5de0f94ecdf614dba3aaae7aaa60ceefa09c9 Mon Sep 17 00:00:00 2001 From: Diva Canto Date: Fri, 7 Jan 2011 12:32:47 -0800 Subject: [PATCH 10/20] Try to fix a IAR problem reported by nebadon, where save iar seems stuck forever. --- OpenSim/Region/Framework/Scenes/UuidGatherer.cs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/OpenSim/Region/Framework/Scenes/UuidGatherer.cs b/OpenSim/Region/Framework/Scenes/UuidGatherer.cs index 3978a7d3ae..83906d745f 100644 --- a/OpenSim/Region/Framework/Scenes/UuidGatherer.cs +++ b/OpenSim/Region/Framework/Scenes/UuidGatherer.cs @@ -86,6 +86,10 @@ namespace OpenSim.Region.Framework.Scenes /// The assets gathered public void GatherAssetUuids(UUID assetUuid, AssetType assetType, IDictionary assetUuids) { + // avoid infinite loops + if (assetUuids.ContainsKey(assetUuid)) + return; + try { assetUuids[assetUuid] = assetType; From df7fb207a87b1b07a00600d5b66e717ac2332b4f Mon Sep 17 00:00:00 2001 From: Mic Bowman Date: Sat, 8 Jan 2011 13:33:07 -0800 Subject: [PATCH 11/20] Moved the map tile processing used by the Simian Grid Frontend into a separate region module. Configuration settings added to the defaults ini file. Others may find this useful for pushing map tiles to a separate server. --- .../SimianGrid/SimianGridMaptileModule.cs | 261 ++++++++++++++++++ .../SimianGrid/SimianGridServiceConnector.cs | 86 ------ bin/OpenSimDefaults.ini | 8 + 3 files changed, 269 insertions(+), 86 deletions(-) create mode 100644 OpenSim/Services/Connectors/SimianGrid/SimianGridMaptileModule.cs diff --git a/OpenSim/Services/Connectors/SimianGrid/SimianGridMaptileModule.cs b/OpenSim/Services/Connectors/SimianGrid/SimianGridMaptileModule.cs new file mode 100644 index 0000000000..dd8fe2b800 --- /dev/null +++ b/OpenSim/Services/Connectors/SimianGrid/SimianGridMaptileModule.cs @@ -0,0 +1,261 @@ +/* + * 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 OpenSimulator 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 System; +using System.Collections.Generic; +using System.Reflection; +using System.Net; +using System.IO; +using System.Timers; +using System.Drawing; +using System.Drawing.Imaging; + +using log4net; +using Mono.Addins; +using Nini.Config; +using OpenSim.Framework; +using OpenSim.Region.Framework.Interfaces; +using OpenSim.Region.Framework.Scenes; +using OpenMetaverse; +using OpenMetaverse.StructuredData; + +namespace OpenSim.Region.OptionalModules.Simian +{ + /// + /// + /// + /// + + [Extension(Path = "/OpenSim/RegionModules", NodeName = "RegionModule", Id = "SimianGridMaptile")] + public class SimianGridMaptile : ISharedRegionModule + { + private static readonly ILog m_log = + LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); + + private bool m_enabled = false; + private string m_serverUrl = String.Empty; + private Dictionary m_scenes = new Dictionary(); + + private int m_refreshtime = 0; + private int m_lastrefresh = 0; + private System.Timers.Timer m_refreshTimer = new System.Timers.Timer(); + + #region ISharedRegionModule + + public Type ReplaceableInterface { get { return null; } } + public string Name { get { return "SimianGridMaptile"; } } + public void RegionLoaded(Scene scene) { } + public void Close() { } + + /// + /// + /// + public void Initialise(IConfigSource source) + { + IConfig config = source.Configs["SimianGridMaptiles"]; + if (config == null) + return; + + if (! config.GetBoolean("Enabled", false)) + return; + + m_serverUrl = config.GetString("MaptileURL"); + if (String.IsNullOrEmpty(m_serverUrl)) + return; + + m_refreshtime = Convert.ToInt32(config.GetString("RefreshTime")); + if (m_refreshtime <= 0) + return; + + m_log.InfoFormat("[SIMIAN MAPTILE] enabled with refresh timeout {0} and URL {1}", + m_refreshtime,m_serverUrl); + + m_enabled = true; + } + + /// + /// + /// + public void PostInitialise() + { + if (m_enabled) + { + m_refreshTimer.Enabled = true; + m_refreshTimer.AutoReset = true; + m_refreshTimer.Interval = 5 * 60 * 1000; // every 5 minutes + m_refreshTimer.Elapsed += new ElapsedEventHandler(HandleMaptileRefresh); + } + } + + + /// + /// + /// + public void AddRegion(Scene scene) + { + if (! m_enabled) + return; + + // Every shared region module has to maintain an indepedent list of + // currently running regions + lock (m_scenes) + m_scenes[scene.RegionInfo.RegionID] = scene; + } + + /// + /// + /// + public void RemoveRegion(Scene scene) + { + if (! m_enabled) + return; + + lock (m_scenes) + m_scenes.Remove(scene.RegionInfo.RegionID); + } + + #endregion ISharedRegionModule + + /// + /// + /// + private void HandleMaptileRefresh(object sender, EventArgs ea) + { + // this approach is a bit convoluted becase we want to wait for the + // first upload to happen on startup but after all the objects are + // loaded and initialized + if (m_lastrefresh > 0 && Util.EnvironmentTickCountSubtract(m_lastrefresh) < m_refreshtime) + return; + + m_log.DebugFormat("[SIMIAN MAPTILE] map refresh fired"); + lock (m_scenes) + { + foreach (IScene scene in m_scenes.Values) + { + try + { + UploadMapTile(scene); + } + catch (Exception ex) + { + m_log.WarnFormat("[SIMIAN MAPTILE] something bad happened {0}",ex.Message); + } + } + } + + m_lastrefresh = Util.EnvironmentTickCount(); + } + + /// + /// + /// + private void UploadMapTile(IScene scene) + { + m_log.DebugFormat("[SIMIAN MAPTILE]: upload maptile for {0}",scene.RegionInfo.RegionName); + + // Create a PNG map tile and upload it to the AddMapTile API + byte[] pngData = Utils.EmptyBytes; + IMapImageGenerator tileGenerator = scene.RequestModuleInterface(); + if (tileGenerator == null) + { + m_log.Warn("[SIMIAN MAPTILE]: Cannot upload PNG map tile without an ImageGenerator"); + return; + } + + using (Image mapTile = tileGenerator.CreateMapTile()) + { + using (MemoryStream stream = new MemoryStream()) + { + mapTile.Save(stream, ImageFormat.Png); + pngData = stream.ToArray(); + } + } + + List postParameters = new List() + { + new MultipartForm.Parameter("X", scene.RegionInfo.RegionLocX.ToString()), + new MultipartForm.Parameter("Y", scene.RegionInfo.RegionLocY.ToString()), + new MultipartForm.File("Tile", "tile.png", "image/png", pngData) + }; + + string errorMessage = null; + int tickstart = Util.EnvironmentTickCount(); + + // Make the remote storage request + try + { + HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(m_serverUrl); + request.Timeout = 20000; + request.ReadWriteTimeout = 5000; + + using (HttpWebResponse response = MultipartForm.Post(request, postParameters)) + { + using (Stream responseStream = response.GetResponseStream()) + { + string responseStr = responseStream.GetStreamString(); + OSD responseOSD = OSDParser.Deserialize(responseStr); + if (responseOSD.Type == OSDType.Map) + { + OSDMap responseMap = (OSDMap)responseOSD; + if (responseMap["Success"].AsBoolean()) + return; + + errorMessage = "Upload failed: " + responseMap["Message"].AsString(); + } + else + { + errorMessage = "Response format was invalid:\n" + responseStr; + } + } + } + } + catch (WebException we) + { + errorMessage = we.Message; + if (we.Status == WebExceptionStatus.ProtocolError) + { + HttpWebResponse webResponse = (HttpWebResponse)we.Response; + errorMessage = String.Format("[{0}] {1}", + webResponse.StatusCode,webResponse.StatusDescription); + } + } + catch (Exception ex) + { + errorMessage = ex.Message; + } + finally + { + // This just dumps a warning for any operation that takes more than 100 ms + int tickdiff = Util.EnvironmentTickCountSubtract(tickstart); + m_log.DebugFormat("[SIMIAN MAPTILE]: map tile uploaded in {0}ms",tickdiff); + } + + m_log.WarnFormat("[SIMIAN MAPTILE]: Failed to store {0} byte tile for {1}: {2}", + pngData.Length, scene.RegionInfo.RegionName, errorMessage); + } + } +} \ No newline at end of file diff --git a/OpenSim/Services/Connectors/SimianGrid/SimianGridServiceConnector.cs b/OpenSim/Services/Connectors/SimianGrid/SimianGridServiceConnector.cs index 9c72a614fb..18a31670bc 100644 --- a/OpenSim/Services/Connectors/SimianGrid/SimianGridServiceConnector.cs +++ b/OpenSim/Services/Connectors/SimianGrid/SimianGridServiceConnector.cs @@ -28,8 +28,6 @@ using System; using System.Collections.Generic; using System.Collections.Specialized; -using System.Drawing; -using System.Drawing.Imaging; using System.IO; using System.Net; using System.Reflection; @@ -102,13 +100,6 @@ namespace OpenSim.Services.Connectors.SimianGrid public string RegisterRegion(UUID scopeID, GridRegion regionInfo) { - // Generate and upload our map tile in PNG format to the SimianGrid AddMapTile service -// Scene scene; -// if (m_scenes.TryGetValue(regionInfo.RegionID, out scene)) -// UploadMapTile(scene); -// else -// m_log.Warn("Registering region " + regionInfo.RegionName + " (" + regionInfo.RegionID + ") that we are not tracking"); - Vector3d minPosition = new Vector3d(regionInfo.RegionLocX, regionInfo.RegionLocY, 0.0); Vector3d maxPosition = minPosition + new Vector3d(Constants.RegionSize, Constants.RegionSize, 4096.0); @@ -380,83 +371,6 @@ namespace OpenSim.Services.Connectors.SimianGrid #endregion IGridService - private void UploadMapTile(IScene scene) - { - string errorMessage = null; - - // Create a PNG map tile and upload it to the AddMapTile API - byte[] pngData = Utils.EmptyBytes; - IMapImageGenerator tileGenerator = scene.RequestModuleInterface(); - if (tileGenerator == null) - { - m_log.Warn("[SIMIAN GRID CONNECTOR]: Cannot upload PNG map tile without an IMapImageGenerator"); - return; - } - - using (Image mapTile = tileGenerator.CreateMapTile()) - { - using (MemoryStream stream = new MemoryStream()) - { - mapTile.Save(stream, ImageFormat.Png); - pngData = stream.ToArray(); - } - } - - List postParameters = new List() - { - new MultipartForm.Parameter("X", scene.RegionInfo.RegionLocX.ToString()), - new MultipartForm.Parameter("Y", scene.RegionInfo.RegionLocY.ToString()), - new MultipartForm.File("Tile", "tile.png", "image/png", pngData) - }; - - // Make the remote storage request - try - { - HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(m_ServerURI); - - HttpWebResponse response = MultipartForm.Post(request, postParameters); - using (Stream responseStream = response.GetResponseStream()) - { - string responseStr = null; - - try - { - responseStr = responseStream.GetStreamString(); - OSD responseOSD = OSDParser.Deserialize(responseStr); - if (responseOSD.Type == OSDType.Map) - { - OSDMap responseMap = (OSDMap)responseOSD; - if (responseMap["Success"].AsBoolean()) - m_log.Info("[SIMIAN GRID CONNECTOR]: Uploaded " + pngData.Length + " byte PNG map tile to AddMapTile"); - else - errorMessage = "Upload failed: " + responseMap["Message"].AsString(); - } - else - { - errorMessage = "Response format was invalid:\n" + responseStr; - } - } - catch (Exception ex) - { - if (!String.IsNullOrEmpty(responseStr)) - errorMessage = "Failed to parse the response:\n" + responseStr; - else - errorMessage = "Failed to retrieve the response: " + ex.Message; - } - } - } - catch (WebException ex) - { - errorMessage = ex.Message; - } - - if (!String.IsNullOrEmpty(errorMessage)) - { - m_log.WarnFormat("[SIMIAN GRID CONNECTOR]: Failed to store {0} byte PNG map tile for {1}: {2}", - pngData.Length, scene.RegionInfo.RegionName, errorMessage.Replace('\n', ' ')); - } - } - private GridRegion GetNearestRegion(Vector3d position, bool onlyEnabled) { NameValueCollection requestArgs = new NameValueCollection diff --git a/bin/OpenSimDefaults.ini b/bin/OpenSimDefaults.ini index 8437ece651..90284530f4 100644 --- a/bin/OpenSimDefaults.ini +++ b/bin/OpenSimDefaults.ini @@ -1240,6 +1240,14 @@ ; Enable media on a prim facilities Enabled = true; +;; +;; If you are using a simian grid frontend you can enable +;; this module to upload tile images for the mapping fn +;; +[SimianGridMaptiles] + Enabled = False + MaptileURL = "http://www.mygrid.com/Grid/" + RefreshTime = 3600 ;; ;; These are defaults that are overwritten below in [Architecture]. From eab0951a591bc2576d6b361a6fa4c75f683bfa54 Mon Sep 17 00:00:00 2001 From: Diva Canto Date: Sat, 8 Jan 2011 15:49:51 -0800 Subject: [PATCH 12/20] Fixes the issue of hung archives. Problem was with SceneObjectSerializer. Also fixes a buglet in scene load xml command, where it was given the wrong argument index for filename. --- OpenSim/Region/Application/OpenSim.cs | 2 +- .../Scenes/Serialization/SceneObjectSerializer.cs | 12 ++++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/OpenSim/Region/Application/OpenSim.cs b/OpenSim/Region/Application/OpenSim.cs index e3b857351c..51eb396aa1 100644 --- a/OpenSim/Region/Application/OpenSim.cs +++ b/OpenSim/Region/Application/OpenSim.cs @@ -1146,7 +1146,7 @@ namespace OpenSim MainConsole.Instance.Output(String.Format("loadOffsets = <{0},{1},{2}>",loadOffset.X,loadOffset.Y,loadOffset.Z)); } } - m_sceneManager.LoadCurrentSceneFromXml(cmdparams[0], generateNewIDS, loadOffset); + m_sceneManager.LoadCurrentSceneFromXml(cmdparams[2], generateNewIDS, loadOffset); } else { diff --git a/OpenSim/Region/Framework/Scenes/Serialization/SceneObjectSerializer.cs b/OpenSim/Region/Framework/Scenes/Serialization/SceneObjectSerializer.cs index 605521a0fa..57ae4fd24f 100644 --- a/OpenSim/Region/Framework/Scenes/Serialization/SceneObjectSerializer.cs +++ b/OpenSim/Region/Framework/Scenes/Serialization/SceneObjectSerializer.cs @@ -1441,6 +1441,12 @@ namespace OpenSim.Region.Framework.Scenes.Serialization { TaskInventoryDictionary tinv = new TaskInventoryDictionary(); + if (reader.IsEmptyElement) + { + reader.Read(); + return tinv; + } + reader.ReadStartElement(name, String.Empty); while (reader.Name == "TaskInventoryItem") @@ -1474,6 +1480,12 @@ namespace OpenSim.Region.Framework.Scenes.Serialization { PrimitiveBaseShape shape = new PrimitiveBaseShape(); + if (reader.IsEmptyElement) + { + reader.Read(); + return shape; + } + reader.ReadStartElement(name, String.Empty); // Shape string nodeName = string.Empty; From 35a2961ccd1407153f9040e03f4a49b0e615e29f Mon Sep 17 00:00:00 2001 From: Diva Canto Date: Sat, 8 Jan 2011 16:17:00 -0800 Subject: [PATCH 13/20] Added a -v|verbose option to save iar. --- .../Inventory/Archiver/InventoryArchiveWriteRequest.cs | 6 ++++++ .../Avatar/Inventory/Archiver/InventoryArchiverModule.cs | 4 +++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/OpenSim/Region/CoreModules/Avatar/Inventory/Archiver/InventoryArchiveWriteRequest.cs b/OpenSim/Region/CoreModules/Avatar/Inventory/Archiver/InventoryArchiveWriteRequest.cs index 5e5f6c0590..dc4900f5a7 100644 --- a/OpenSim/Region/CoreModules/Avatar/Inventory/Archiver/InventoryArchiveWriteRequest.cs +++ b/OpenSim/Region/CoreModules/Avatar/Inventory/Archiver/InventoryArchiveWriteRequest.cs @@ -139,6 +139,9 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver protected void SaveInvItem(InventoryItemBase inventoryItem, string path, Dictionary options, IUserAccountService userAccountService) { + if (options.ContainsKey("verbose")) + m_log.InfoFormat("[INVENTORY ARCHIVER]: Saving item {0} with asset {1}", inventoryItem.ID, inventoryItem.AssetID); + string filename = path + CreateArchiveItemName(inventoryItem); // Record the creator of this item for user record purposes (which might go away soon) @@ -162,6 +165,9 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver InventoryFolderBase inventoryFolder, string path, bool saveThisFolderItself, Dictionary options, IUserAccountService userAccountService) { + if (options.ContainsKey("verbose")) + m_log.InfoFormat("[INVENTORY ARCHIVER]: Saving folder {0}", inventoryFolder.Name); + if (saveThisFolderItself) { path += CreateArchiveFolderName(inventoryFolder); diff --git a/OpenSim/Region/CoreModules/Avatar/Inventory/Archiver/InventoryArchiverModule.cs b/OpenSim/Region/CoreModules/Avatar/Inventory/Archiver/InventoryArchiverModule.cs index b1c2a3c683..1a96098f18 100644 --- a/OpenSim/Region/CoreModules/Avatar/Inventory/Archiver/InventoryArchiverModule.cs +++ b/OpenSim/Region/CoreModules/Avatar/Inventory/Archiver/InventoryArchiverModule.cs @@ -122,12 +122,13 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver scene.AddCommand( this, "save iar", - "save iar [--p|-profile=] []", + "save iar [--p|-profile=] [] [--v|-verbose]", "Save user inventory archive (IAR).", " is the user's first name." + Environment.NewLine + " is the user's last name." + Environment.NewLine + " is the path inside the user's inventory for the folder/item to be saved." + Environment.NewLine + "-p|--profile= adds the url of the profile service to the saved user information." + Environment.NewLine + + "-v|--verbose extra debug messages." + Environment.NewLine + " is the filesystem path at which to save the IAR." + string.Format(" If this is not given then the filename {0} in the current directory is used", DEFAULT_INV_BACKUP_FILENAME), HandleSaveInvConsoleCommand); @@ -394,6 +395,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver OptionSet ops = new OptionSet(); //ops.Add("v|version=", delegate(string v) { options["version"] = v; }); ops.Add("p|profile=", delegate(string v) { options["profile"] = v; }); + ops.Add("v|verbose", delegate(string v) { options["verbose"] = v; }); List mainParams = ops.Parse(cmdparams); From 0fabe0e5a5ee37cad77aeebf84660f9daef95d2e Mon Sep 17 00:00:00 2001 From: Diva Canto Date: Sat, 8 Jan 2011 16:33:33 -0800 Subject: [PATCH 14/20] Added more debug messages under the -verbose option. --- .../Region/CoreModules/World/Archiver/AssetsRequest.cs | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/OpenSim/Region/CoreModules/World/Archiver/AssetsRequest.cs b/OpenSim/Region/CoreModules/World/Archiver/AssetsRequest.cs index 5da165666d..b88869882f 100644 --- a/OpenSim/Region/CoreModules/World/Archiver/AssetsRequest.cs +++ b/OpenSim/Region/CoreModules/World/Archiver/AssetsRequest.cs @@ -249,14 +249,18 @@ namespace OpenSim.Region.CoreModules.World.Archiver if (asset != null) { -// m_log.DebugFormat("[ARCHIVER]: Writing asset {0}", id); + if (m_options.ContainsKey("verbose")) + m_log.InfoFormat("[ARCHIVER]: Writing asset {0}", id); + m_foundAssetUuids.Add(asset.FullID); m_assetsArchiver.WriteAsset(PostProcess(asset)); } else { -// m_log.DebugFormat("[ARCHIVER]: Recording asset {0} as not found", id); + if (m_options.ContainsKey("verbose")) + m_log.InfoFormat("[ARCHIVER]: Recording asset {0} as not found", id); + m_notFoundAssetUuids.Add(new UUID(id)); } From e80bcc0049c9e60e052969aaf8582fa2b867f879 Mon Sep 17 00:00:00 2001 From: Diva Canto Date: Sun, 9 Jan 2011 16:52:41 -0800 Subject: [PATCH 15/20] Improved debug messages to track what is going on with the XFF header --- .../Server/Handlers/Hypergrid/HomeAgentHandlers.cs | 2 ++ OpenSim/Server/Handlers/Simulation/AgentHandlers.cs | 2 ++ .../Services/HypergridService/UserAgentService.cs | 12 +++++++----- 3 files changed, 11 insertions(+), 5 deletions(-) diff --git a/OpenSim/Server/Handlers/Hypergrid/HomeAgentHandlers.cs b/OpenSim/Server/Handlers/Hypergrid/HomeAgentHandlers.cs index a5ec4f2b08..0066bd4d62 100644 --- a/OpenSim/Server/Handlers/Hypergrid/HomeAgentHandlers.cs +++ b/OpenSim/Server/Handlers/Hypergrid/HomeAgentHandlers.cs @@ -217,6 +217,8 @@ namespace OpenSim.Server.Handlers.Hypergrid Hashtable headers = (Hashtable)request["headers"]; if (headers.ContainsKey("X-Forwarded-For") && headers["X-Forwarded-For"] != null) { + m_log.DebugFormat("[HOME AGENT HANDLER]: XFF is {0}", headers["X-Forwarded-For"]); + IPEndPoint ep = Util.GetClientIPFromXFF((string)headers["X-Forwarded-For"]); if (ep != null) return ep.Address.ToString(); diff --git a/OpenSim/Server/Handlers/Simulation/AgentHandlers.cs b/OpenSim/Server/Handlers/Simulation/AgentHandlers.cs index 24ae81ff0f..9c41bcbd9c 100644 --- a/OpenSim/Server/Handlers/Simulation/AgentHandlers.cs +++ b/OpenSim/Server/Handlers/Simulation/AgentHandlers.cs @@ -202,6 +202,8 @@ namespace OpenSim.Server.Handlers.Simulation Hashtable headers = (Hashtable)request["headers"]; if (headers.ContainsKey("X-Forwarded-For") && headers["X-Forwarded-For"] != null) { + m_log.DebugFormat("[AGENT HANDLER]: XFF is {0}", headers["X-Forwarded-For"]); + IPEndPoint ep = Util.GetClientIPFromXFF((string)headers["X-Forwarded-For"]); if (ep != null) return ep.Address.ToString(); diff --git a/OpenSim/Services/HypergridService/UserAgentService.cs b/OpenSim/Services/HypergridService/UserAgentService.cs index 12dda48164..3ead180a0b 100644 --- a/OpenSim/Services/HypergridService/UserAgentService.cs +++ b/OpenSim/Services/HypergridService/UserAgentService.cs @@ -155,7 +155,7 @@ namespace OpenSim.Services.HypergridService string myExternalIP = string.Empty; string gridName = gatekeeper.ServerURI; - m_log.DebugFormat("[USER AGENT SERVICE]: m_grid - {0}, gn - {1}", m_GridName, gridName); + m_log.DebugFormat("[USER AGENT SERVICE]: this grid: {0}, desired grid: {1}", m_GridName, gridName); if (m_GridName == gridName) success = m_GatekeeperService.LoginAgent(agentCircuit, finalDestination, out reason); @@ -266,11 +266,13 @@ namespace OpenSim.Services.HypergridService if (m_TravelingAgents.ContainsKey(sessionID)) { - m_log.DebugFormat("[USER AGENT SERVICE]: Comparing with login IP {0} and MyIP {1}", - m_TravelingAgents[sessionID].ClientIPAddress, m_TravelingAgents[sessionID].MyIpAddress); - - return m_TravelingAgents[sessionID].ClientIPAddress == reportedIP || + bool result = m_TravelingAgents[sessionID].ClientIPAddress == reportedIP || m_TravelingAgents[sessionID].MyIpAddress == reportedIP; // NATed + + m_log.DebugFormat("[USER AGENT SERVICE]: Comparing {0} with login IP {1} and MyIP {1}; result is {3}", + reportedIP, m_TravelingAgents[sessionID].ClientIPAddress, m_TravelingAgents[sessionID].MyIpAddress, result); + + return result; } return false; From dd154f74036f6f78c936f557e89da1293a4ce342 Mon Sep 17 00:00:00 2001 From: Melanie Date: Thu, 6 Jan 2011 19:12:25 +0100 Subject: [PATCH 16/20] Fix god mode perms adjustment --- OpenSim/Region/Framework/Scenes/SceneObjectPartInventory.cs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/OpenSim/Region/Framework/Scenes/SceneObjectPartInventory.cs b/OpenSim/Region/Framework/Scenes/SceneObjectPartInventory.cs index 39ebaefcab..90f1d6efe1 100644 --- a/OpenSim/Region/Framework/Scenes/SceneObjectPartInventory.cs +++ b/OpenSim/Region/Framework/Scenes/SceneObjectPartInventory.cs @@ -1010,6 +1010,8 @@ namespace OpenSim.Region.Framework.Scenes item.BasePermissions = perms; } } + m_inventorySerial++; + HasInventoryChanged = true; } public bool ContainsScripts() From 7cfe17b5b39bb6e99abe24ae27c60b51165abe21 Mon Sep 17 00:00:00 2001 From: Melanie Date: Wed, 12 Jan 2011 21:25:38 +0000 Subject: [PATCH 17/20] Partial permissions fix for boxed items. --- OpenSim/Region/Framework/Scenes/Scene.Inventory.cs | 10 ++++++++++ .../Framework/Scenes/SceneObjectPartInventory.cs | 7 +++++++ 2 files changed, 17 insertions(+) diff --git a/OpenSim/Region/Framework/Scenes/Scene.Inventory.cs b/OpenSim/Region/Framework/Scenes/Scene.Inventory.cs index dc2ce4874d..bc6b165668 100644 --- a/OpenSim/Region/Framework/Scenes/Scene.Inventory.cs +++ b/OpenSim/Region/Framework/Scenes/Scene.Inventory.cs @@ -2131,5 +2131,15 @@ namespace OpenSim.Region.Framework.Scenes m_sceneGraph.LinkObjects(root, children); } + + private string PermissionString(uint permissions) + { + PermissionMask perms = (PermissionMask)permissions & + (PermissionMask.Move | + PermissionMask.Copy | + PermissionMask.Transfer | + PermissionMask.Modify); + return perms.ToString(); + } } } diff --git a/OpenSim/Region/Framework/Scenes/SceneObjectPartInventory.cs b/OpenSim/Region/Framework/Scenes/SceneObjectPartInventory.cs index 90f1d6efe1..900130a85d 100644 --- a/OpenSim/Region/Framework/Scenes/SceneObjectPartInventory.cs +++ b/OpenSim/Region/Framework/Scenes/SceneObjectPartInventory.cs @@ -946,6 +946,13 @@ namespace OpenSim.Region.Framework.Scenes { foreach (TaskInventoryItem item in m_items.Values) { + if ((item.CurrentPermissions & item.NextPermissions & (uint)PermissionMask.Copy) == 0) + mask &= ~((uint)PermissionMask.Copy >> 13); + if ((item.CurrentPermissions & item.NextPermissions & (uint)PermissionMask.Transfer) == 0) + mask &= ~((uint)PermissionMask.Transfer >> 13); + if ((item.CurrentPermissions & item.NextPermissions & (uint)PermissionMask.Modify) == 0) + mask &= ~((uint)PermissionMask.Modify >> 13); + if (item.InvType != (int)InventoryType.Object) { if ((item.CurrentPermissions & item.NextPermissions & (uint)PermissionMask.Copy) == 0) From f75a3ee7628f4f0f75cad825d8ffc8195258583f Mon Sep 17 00:00:00 2001 From: Melanie Date: Tue, 11 Jan 2011 14:59:55 +0100 Subject: [PATCH 18/20] Use ToString() rather than a cast (more robust) --- OpenSim/Region/ScriptEngine/Shared/LSL_Types.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/OpenSim/Region/ScriptEngine/Shared/LSL_Types.cs b/OpenSim/Region/ScriptEngine/Shared/LSL_Types.cs index 91e03acccd..298d664a64 100644 --- a/OpenSim/Region/ScriptEngine/Shared/LSL_Types.cs +++ b/OpenSim/Region/ScriptEngine/Shared/LSL_Types.cs @@ -558,7 +558,7 @@ namespace OpenSim.Region.ScriptEngine.Shared else if (m_data[itemIndex] is Int32) return new LSLInteger((int)m_data[itemIndex]); else if (m_data[itemIndex] is LSL_Types.LSLString) - return new LSLInteger((string)m_data[itemIndex]); + return new LSLInteger(m_data[itemIndex].ToString()); else throw new InvalidCastException(); } From 914e4b319ee0adba72bfbfebd878827bfdfde843 Mon Sep 17 00:00:00 2001 From: Melanie Date: Wed, 12 Jan 2011 21:39:13 +0000 Subject: [PATCH 19/20] Fix direct item give permissions --- .../InventoryAccess/InventoryAccessModule.cs | 26 ++++++----- .../World/Objects/BuySell/BuySellModule.cs | 2 +- .../Framework/Scenes/Scene.Inventory.cs | 44 ++++++++++++++++--- .../Scenes/SceneObjectGroup.Inventory.cs | 2 +- .../Scenes/SceneObjectPartInventory.cs | 22 +++++++--- 5 files changed, 73 insertions(+), 23 deletions(-) diff --git a/OpenSim/Region/CoreModules/Framework/InventoryAccess/InventoryAccessModule.cs b/OpenSim/Region/CoreModules/Framework/InventoryAccess/InventoryAccessModule.cs index 1ebccd1af1..f2cc16c693 100644 --- a/OpenSim/Region/CoreModules/Framework/InventoryAccess/InventoryAccessModule.cs +++ b/OpenSim/Region/CoreModules/Framework/InventoryAccess/InventoryAccessModule.cs @@ -434,10 +434,7 @@ namespace OpenSim.Region.CoreModules.Framework.InventoryAccess item.EveryOnePermissions = objectGroup.RootPart.EveryoneMask & objectGroup.RootPart.NextOwnerMask; item.GroupPermissions = objectGroup.RootPart.GroupMask & objectGroup.RootPart.NextOwnerMask; - // Magic number badness. Maybe this deserves an enum. - // bit 4 (16) is the "Slam" bit, it means treat as passed - // and apply next owner perms on rez - item.CurrentPermissions |= 16; // Slam! + item.Flags |= (uint)InventoryItemFlags.ObjectSlamPerm; } else { @@ -641,7 +638,9 @@ namespace OpenSim.Region.CoreModules.Framework.InventoryAccess rootPart.Description = item.Description; group.SetGroup(remoteClient.ActiveGroupId, remoteClient); - if ((rootPart.OwnerID != item.Owner) || (item.CurrentPermissions & 16) != 0) + if ((rootPart.OwnerID != item.Owner) || + (item.CurrentPermissions & 16) != 0 || // Magic number + (item.Flags & (uint)InventoryItemFlags.ObjectSlamPerm) != 0) { //Need to kill the for sale here rootPart.ObjectSaleType = 0; @@ -651,9 +650,12 @@ namespace OpenSim.Region.CoreModules.Framework.InventoryAccess { foreach (SceneObjectPart part in group.Parts) { - part.EveryoneMask = item.EveryOnePermissions; - part.NextOwnerMask = item.NextPermissions; - part.GroupMask = 0; // DO NOT propagate here + if ((item.Flags & (uint)InventoryItemFlags.ObjectOverwriteEveryone) != 0) + part.EveryoneMask = item.EveryOnePermissions; + if ((item.Flags & (uint)InventoryItemFlags.ObjectOverwriteNextOwner) != 0) + part.NextOwnerMask = item.NextPermissions; + if ((item.Flags & (uint)InventoryItemFlags.ObjectOverwriteGroup) != 0) + part.GroupMask = item.GroupPermissions; } group.ApplyNextOwnerPermissions(); @@ -669,8 +671,12 @@ namespace OpenSim.Region.CoreModules.Framework.InventoryAccess part.Inventory.ChangeInventoryOwner(item.Owner); part.GroupMask = 0; // DO NOT propagate here } - part.EveryoneMask = item.EveryOnePermissions; - part.NextOwnerMask = item.NextPermissions; + if ((item.Flags & (uint)InventoryItemFlags.ObjectOverwriteEveryone) != 0) + part.EveryoneMask = item.EveryOnePermissions; + if ((item.Flags & (uint)InventoryItemFlags.ObjectOverwriteNextOwner) != 0) + part.NextOwnerMask = item.NextPermissions; + if ((item.Flags & (uint)InventoryItemFlags.ObjectOverwriteGroup) != 0) + part.GroupMask = item.GroupPermissions; } rootPart.TrimPermissions(); diff --git a/OpenSim/Region/CoreModules/World/Objects/BuySell/BuySellModule.cs b/OpenSim/Region/CoreModules/World/Objects/BuySell/BuySellModule.cs index 568ba198bd..be399ff65b 100644 --- a/OpenSim/Region/CoreModules/World/Objects/BuySell/BuySellModule.cs +++ b/OpenSim/Region/CoreModules/World/Objects/BuySell/BuySellModule.cs @@ -215,7 +215,7 @@ namespace OpenSim.Region.CoreModules.World.Objects.BuySell part.NextOwnerMask; item.GroupPermissions = part.GroupMask & part.NextOwnerMask; - item.CurrentPermissions |= 16; // Slam! + item.Flags |= (uint)InventoryItemFlags.ObjectSlamPerm; item.CreationDate = Util.UnixTimeSinceEpoch(); if (m_scene.AddInventoryItem(item)) diff --git a/OpenSim/Region/Framework/Scenes/Scene.Inventory.cs b/OpenSim/Region/Framework/Scenes/Scene.Inventory.cs index bc6b165668..19fa6c5499 100644 --- a/OpenSim/Region/Framework/Scenes/Scene.Inventory.cs +++ b/OpenSim/Region/Framework/Scenes/Scene.Inventory.cs @@ -326,10 +326,17 @@ namespace OpenSim.Region.Framework.Scenes { if (UUID.Zero == transactionID) { + item.Flags = itemUpd.Flags; item.Name = itemUpd.Name; item.Description = itemUpd.Description; + if (item.NextPermissions != (itemUpd.NextPermissions & item.BasePermissions)) + item.Flags |= (uint)InventoryItemFlags.ObjectOverwriteNextOwner; item.NextPermissions = itemUpd.NextPermissions & item.BasePermissions; + if (item.EveryOnePermissions != (itemUpd.EveryOnePermissions & item.BasePermissions)) + item.Flags |= (uint)InventoryItemFlags.ObjectOverwriteEveryone; item.EveryOnePermissions = itemUpd.EveryOnePermissions & item.BasePermissions; + if (item.GroupPermissions != (itemUpd.GroupPermissions & item.BasePermissions)) + item.Flags |= (uint)InventoryItemFlags.ObjectOverwriteGroup; item.GroupPermissions = itemUpd.GroupPermissions & item.BasePermissions; item.GroupID = itemUpd.GroupID; item.GroupOwned = itemUpd.GroupOwned; @@ -344,9 +351,12 @@ namespace OpenSim.Region.Framework.Scenes // TODO: Check if folder changed and move item //item.NextPermissions = itemUpd.Folder; item.InvType = itemUpd.InvType; + + if (item.SalePrice != itemUpd.SalePrice || + item.SaleType != itemUpd.SaleType) + item.Flags |= (uint)InventoryItemFlags.ObjectSlamSale; item.SalePrice = itemUpd.SalePrice; item.SaleType = itemUpd.SaleType; - item.Flags = itemUpd.Flags; InventoryService.UpdateItem(item); } @@ -527,7 +537,8 @@ namespace OpenSim.Region.Framework.Scenes // Assign to the actual item. Make sure the slam bit is // set, if it wasn't set before. itemCopy.BasePermissions = basePerms; - itemCopy.CurrentPermissions = ownerPerms | 16; // Slam + itemCopy.CurrentPermissions = ownerPerms; + itemCopy.Flags |= (uint)InventoryItemFlags.ObjectSlamPerm; itemCopy.NextPermissions = item.NextPermissions; @@ -1043,7 +1054,7 @@ namespace OpenSim.Region.Framework.Scenes else agentItem.CurrentPermissions = agentItem.BasePermissions & taskItem.CurrentPermissions; - agentItem.CurrentPermissions |= 16; // Slam + agentItem.Flags |= (uint)InventoryItemFlags.ObjectSlamPerm; agentItem.NextPermissions = taskItem.NextPermissions; agentItem.EveryOnePermissions = taskItem.EveryonePermissions & (taskItem.NextPermissions | (uint)PermissionMask.Move); agentItem.GroupPermissions = taskItem.GroupPermissions & taskItem.NextPermissions; @@ -1254,7 +1265,7 @@ namespace OpenSim.Region.Framework.Scenes (srcTaskItem.NextPermissions | (uint)PermissionMask.Move); destTaskItem.BasePermissions = srcTaskItem.BasePermissions & (srcTaskItem.NextPermissions | (uint)PermissionMask.Move); - destTaskItem.CurrentPermissions |= 16; // Slam! + destTaskItem.Flags |= (uint)InventoryItemFlags.ObjectSlamPerm; } } @@ -1435,6 +1446,8 @@ namespace OpenSim.Region.Framework.Scenes // Base ALWAYS has move currentItem.BasePermissions |= (uint)PermissionMask.Move; + itemInfo.Flags = currentItem.Flags; + // Check if we're allowed to mess with permissions if (!Permissions.IsGod(remoteClient.AgentId)) // Not a god { @@ -1452,6 +1465,14 @@ namespace OpenSim.Region.Framework.Scenes // Owner can't change base, and can change other // only up to base itemInfo.BasePermissions = currentItem.BasePermissions; + if (itemInfo.EveryonePermissions != currentItem.EveryonePermissions) + itemInfo.Flags |= (uint)InventoryItemFlags.ObjectOverwriteEveryone; + if (itemInfo.GroupPermissions != currentItem.GroupPermissions) + itemInfo.Flags |= (uint)InventoryItemFlags.ObjectOverwriteGroup; + if (itemInfo.CurrentPermissions != currentItem.CurrentPermissions) + itemInfo.Flags |= (uint)InventoryItemFlags.ObjectOverwriteOwner; + if (itemInfo.NextPermissions != currentItem.NextPermissions) + itemInfo.Flags |= (uint)InventoryItemFlags.ObjectOverwriteNextOwner; itemInfo.EveryonePermissions &= currentItem.BasePermissions; itemInfo.GroupPermissions &= currentItem.BasePermissions; itemInfo.CurrentPermissions &= currentItem.BasePermissions; @@ -1459,6 +1480,19 @@ namespace OpenSim.Region.Framework.Scenes } } + else + { + if (itemInfo.BasePermissions != currentItem.BasePermissions) + itemInfo.Flags |= (uint)InventoryItemFlags.ObjectOverwriteBase; + if (itemInfo.EveryonePermissions != currentItem.EveryonePermissions) + itemInfo.Flags |= (uint)InventoryItemFlags.ObjectOverwriteEveryone; + if (itemInfo.GroupPermissions != currentItem.GroupPermissions) + itemInfo.Flags |= (uint)InventoryItemFlags.ObjectOverwriteGroup; + if (itemInfo.CurrentPermissions != currentItem.CurrentPermissions) + itemInfo.Flags |= (uint)InventoryItemFlags.ObjectOverwriteOwner; + if (itemInfo.NextPermissions != currentItem.NextPermissions) + itemInfo.Flags |= (uint)InventoryItemFlags.ObjectOverwriteNextOwner; + } // Next ALWAYS has move itemInfo.NextPermissions |= (uint)PermissionMask.Move; @@ -1667,7 +1701,7 @@ namespace OpenSim.Region.Framework.Scenes srcTaskItem.NextPermissions; destTaskItem.BasePermissions = srcTaskItem.BasePermissions & srcTaskItem.NextPermissions; - destTaskItem.CurrentPermissions |= 16; // Slam! + destTaskItem.Flags |= (uint)InventoryItemFlags.ObjectSlamPerm; } } diff --git a/OpenSim/Region/Framework/Scenes/SceneObjectGroup.Inventory.cs b/OpenSim/Region/Framework/Scenes/SceneObjectGroup.Inventory.cs index 982e280244..e8095c0831 100644 --- a/OpenSim/Region/Framework/Scenes/SceneObjectGroup.Inventory.cs +++ b/OpenSim/Region/Framework/Scenes/SceneObjectGroup.Inventory.cs @@ -122,7 +122,7 @@ namespace OpenSim.Region.Framework.Scenes taskItem.NextPermissions = item.NextPermissions; // We're adding this to a prim we don't own. Force // owner change - taskItem.CurrentPermissions |= 16; // Slam + taskItem.Flags |= (uint)InventoryItemFlags.ObjectSlamPerm; } else { diff --git a/OpenSim/Region/Framework/Scenes/SceneObjectPartInventory.cs b/OpenSim/Region/Framework/Scenes/SceneObjectPartInventory.cs index 900130a85d..91bb3a52dd 100644 --- a/OpenSim/Region/Framework/Scenes/SceneObjectPartInventory.cs +++ b/OpenSim/Region/Framework/Scenes/SceneObjectPartInventory.cs @@ -629,14 +629,19 @@ namespace OpenSim.Region.Framework.Scenes group.SetGroup(m_part.GroupID, null); - if ((rootPart.OwnerID != item.OwnerID) || (item.CurrentPermissions & 16) != 0) + // TODO: Remove magic number badness + if ((rootPart.OwnerID != item.OwnerID) || (item.CurrentPermissions & 16) != 0 || (item.Flags & (uint)InventoryItemFlags.ObjectSlamPerm) != 0) // Magic number { if (m_part.ParentGroup.Scene.Permissions.PropagatePermissions()) { foreach (SceneObjectPart part in partList) { - part.EveryoneMask = item.EveryonePermissions; - part.NextOwnerMask = item.NextPermissions; + if ((item.Flags & (uint)InventoryItemFlags.ObjectOverwriteEveryone) != 0) + part.EveryoneMask = item.EveryonePermissions; + if ((item.Flags & (uint)InventoryItemFlags.ObjectOverwriteNextOwner) != 0) + part.NextOwnerMask = item.NextPermissions; + if ((item.Flags & (uint)InventoryItemFlags.ObjectOverwriteGroup) != 0) + part.GroupMask = item.GroupPermissions; } group.ApplyNextOwnerPermissions(); @@ -645,15 +650,20 @@ namespace OpenSim.Region.Framework.Scenes foreach (SceneObjectPart part in partList) { - if ((part.OwnerID != item.OwnerID) || (item.CurrentPermissions & 16) != 0) + // TODO: Remove magic number badness + if ((part.OwnerID != item.OwnerID) || (item.CurrentPermissions & 16) != 0 || (item.Flags & (uint)InventoryItemFlags.ObjectSlamPerm) != 0) // Magic number { part.LastOwnerID = part.OwnerID; part.OwnerID = item.OwnerID; part.Inventory.ChangeInventoryOwner(item.OwnerID); } - part.EveryoneMask = item.EveryonePermissions; - part.NextOwnerMask = item.NextPermissions; + if ((item.Flags & (uint)InventoryItemFlags.ObjectOverwriteEveryone) != 0) + part.EveryoneMask = item.EveryonePermissions; + if ((item.Flags & (uint)InventoryItemFlags.ObjectOverwriteNextOwner) != 0) + part.NextOwnerMask = item.NextPermissions; + if ((item.Flags & (uint)InventoryItemFlags.ObjectOverwriteGroup) != 0) + part.GroupMask = item.GroupPermissions; } rootPart.TrimPermissions(); From 705f4e1e4be44e6b96d028b3445681145a0c4d8f Mon Sep 17 00:00:00 2001 From: Melanie Date: Wed, 12 Jan 2011 21:46:49 +0000 Subject: [PATCH 20/20] Dont' trust the viewer! Fix a permission slam error caused by trusting the viewer too much. --- .../Framework/InventoryAccess/InventoryAccessModule.cs | 6 ++++++ OpenSim/Region/Framework/Scenes/Scene.Inventory.cs | 1 - 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/OpenSim/Region/CoreModules/Framework/InventoryAccess/InventoryAccessModule.cs b/OpenSim/Region/CoreModules/Framework/InventoryAccess/InventoryAccessModule.cs index f2cc16c693..7bb8789f16 100644 --- a/OpenSim/Region/CoreModules/Framework/InventoryAccess/InventoryAccessModule.cs +++ b/OpenSim/Region/CoreModules/Framework/InventoryAccess/InventoryAccessModule.cs @@ -637,6 +637,12 @@ namespace OpenSim.Region.CoreModules.Framework.InventoryAccess rootPart.Name = item.Name; rootPart.Description = item.Description; + if ((item.Flags & (uint)InventoryItemFlags.ObjectSlamSale) != 0) + { + rootPart.ObjectSaleType = item.SaleType; + rootPart.SalePrice = item.SalePrice; + } + group.SetGroup(remoteClient.ActiveGroupId, remoteClient); if ((rootPart.OwnerID != item.Owner) || (item.CurrentPermissions & 16) != 0 || // Magic number diff --git a/OpenSim/Region/Framework/Scenes/Scene.Inventory.cs b/OpenSim/Region/Framework/Scenes/Scene.Inventory.cs index 19fa6c5499..e2d96d9a37 100644 --- a/OpenSim/Region/Framework/Scenes/Scene.Inventory.cs +++ b/OpenSim/Region/Framework/Scenes/Scene.Inventory.cs @@ -326,7 +326,6 @@ namespace OpenSim.Region.Framework.Scenes { if (UUID.Zero == transactionID) { - item.Flags = itemUpd.Flags; item.Name = itemUpd.Name; item.Description = itemUpd.Description; if (item.NextPermissions != (itemUpd.NextPermissions & item.BasePermissions))