From 98f90f4eed231724f1105f19d9bc29cb23b3e5bf Mon Sep 17 00:00:00 2001 From: TomTheDragon Date: Sun, 5 Nov 2017 17:33:13 -0500 Subject: [PATCH 1/9] Changing map tile colors This change also allows setting the water color, as well as the 4 colors for textured map tiles. Signed-off-by: UbitUmarov --- .../World/LegacyMap/ShadedMapTileRenderer.cs | 12 +++--- .../LegacyMap/TexturedMapTileRenderer.cs | 43 +++++++++++-------- bin/OpenSim.ini.example | 15 +++++++ 3 files changed, 47 insertions(+), 23 deletions(-) diff --git a/OpenSim/Region/CoreModules/World/LegacyMap/ShadedMapTileRenderer.cs b/OpenSim/Region/CoreModules/World/LegacyMap/ShadedMapTileRenderer.cs index 708286c906..0b37179710 100644 --- a/OpenSim/Region/CoreModules/World/LegacyMap/ShadedMapTileRenderer.cs +++ b/OpenSim/Region/CoreModules/World/LegacyMap/ShadedMapTileRenderer.cs @@ -38,18 +38,20 @@ namespace OpenSim.Region.CoreModules.World.LegacyMap { public class ShadedMapTileRenderer : IMapTileTerrainRenderer { - private static readonly Color WATER_COLOR = Color.FromArgb(29, 71, 95); - private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); private static readonly string LogHeader = "[SHADED MAPTILE RENDERER]"; private Scene m_scene; - //private IConfigSource m_config; // not used currently + private IConfigSource m_config; + private Color m_color_water; public void Initialise(Scene scene, IConfigSource config) { m_scene = scene; - // m_config = config; // not used currently + m_config = config; + + string[] configSections = new string[] { "Map", "Startup" }; + m_color_water = System.Drawing.ColorTranslator.FromHtml(Util.GetConfigVarFromSections(m_config, "MapColorWater", configSections, "#1D475F")); } public void TerrainToBitmap(Bitmap mapbmp) @@ -231,7 +233,7 @@ namespace OpenSim.Region.CoreModules.World.LegacyMap try { - mapbmp.SetPixel(x, yr, WATER_COLOR); + mapbmp.SetPixel(x, yr, m_color_water); } catch (ArgumentException) { diff --git a/OpenSim/Region/CoreModules/World/LegacyMap/TexturedMapTileRenderer.cs b/OpenSim/Region/CoreModules/World/LegacyMap/TexturedMapTileRenderer.cs index 4b3ee182eb..c71f5c0d89 100644 --- a/OpenSim/Region/CoreModules/World/LegacyMap/TexturedMapTileRenderer.cs +++ b/OpenSim/Region/CoreModules/World/LegacyMap/TexturedMapTileRenderer.cs @@ -130,21 +130,19 @@ namespace OpenSim.Region.CoreModules.World.LegacyMap // some hardcoded terrain UUIDs that work with SL 1.20 (the four default textures and "Blank"). // The color-values were choosen because they "look right" (at least to me) ;-) private static readonly UUID defaultTerrainTexture1 = new UUID("0bc58228-74a0-7e83-89bc-5c23464bcec5"); - private static readonly Color defaultColor1 = Color.FromArgb(165, 137, 118); private static readonly UUID defaultTerrainTexture2 = new UUID("63338ede-0037-c4fd-855b-015d77112fc8"); - private static readonly Color defaultColor2 = Color.FromArgb(69, 89, 49); private static readonly UUID defaultTerrainTexture3 = new UUID("303cd381-8560-7579-23f1-f0a880799740"); - private static readonly Color defaultColor3 = Color.FromArgb(162, 154, 141); private static readonly UUID defaultTerrainTexture4 = new UUID("53a2f406-4895-1d13-d541-d2e3b86bc19c"); - private static readonly Color defaultColor4 = Color.FromArgb(200, 200, 200); - - private static readonly Color WATER_COLOR = Color.FromArgb(29, 71, 95); #endregion - private Scene m_scene; - // private IConfigSource m_config; // not used currently + private IConfigSource m_config; + private Color m_color_water; + private Color m_color_1; + private Color m_color_2; + private Color m_color_3; + private Color m_color_4; // mapping from texture UUIDs to averaged color. This will contain 5-9 values, in general; new values are only // added when the terrain textures are changed in the estate dialog and a new map is generated (and will stay in @@ -156,12 +154,21 @@ namespace OpenSim.Region.CoreModules.World.LegacyMap public void Initialise(Scene scene, IConfigSource source) { m_scene = scene; - // m_config = source; // not used currently + m_config = source; + + string[] configSections = new string[] { "Map", "Startup" }; + + m_color_water = System.Drawing.ColorTranslator.FromHtml(Util.GetConfigVarFromSections(m_config, "MapColorWater", configSections, "#1D475F")); + m_color_1 = System.Drawing.ColorTranslator.FromHtml(Util.GetConfigVarFromSections(m_config, "MapColor1", configSections, "#A58976")); + m_color_2 = System.Drawing.ColorTranslator.FromHtml(Util.GetConfigVarFromSections(m_config, "MapColor2", configSections, "#455931")); + m_color_3 = System.Drawing.ColorTranslator.FromHtml(Util.GetConfigVarFromSections(m_config, "MapColor3", configSections, "#A29A8D")); + m_color_4 = System.Drawing.ColorTranslator.FromHtml(Util.GetConfigVarFromSections(m_config, "MapColor4", configSections, "#C8C8C8")); + m_mapping = new Dictionary(); - m_mapping.Add(defaultTerrainTexture1, defaultColor1); - m_mapping.Add(defaultTerrainTexture2, defaultColor2); - m_mapping.Add(defaultTerrainTexture3, defaultColor3); - m_mapping.Add(defaultTerrainTexture4, defaultColor4); + m_mapping.Add(defaultTerrainTexture1, m_color_1); + m_mapping.Add(defaultTerrainTexture2, m_color_2); + m_mapping.Add(defaultTerrainTexture3, m_color_3); + m_mapping.Add(defaultTerrainTexture4, m_color_4); m_mapping.Add(Util.BLANK_TEXTURE_UUID, Color.White); } @@ -298,10 +305,10 @@ namespace OpenSim.Region.CoreModules.World.LegacyMap RegionSettings settings = m_scene.RegionInfo.RegionSettings; // the four terrain colors as HSVs for interpolation - HSV hsv1 = new HSV(computeAverageColor(settings.TerrainTexture1, defaultColor1)); - HSV hsv2 = new HSV(computeAverageColor(settings.TerrainTexture2, defaultColor2)); - HSV hsv3 = new HSV(computeAverageColor(settings.TerrainTexture3, defaultColor3)); - HSV hsv4 = new HSV(computeAverageColor(settings.TerrainTexture4, defaultColor4)); + HSV hsv1 = new HSV(computeAverageColor(settings.TerrainTexture1, m_color_1)); + HSV hsv2 = new HSV(computeAverageColor(settings.TerrainTexture2, m_color_2)); + HSV hsv3 = new HSV(computeAverageColor(settings.TerrainTexture3, m_color_3)); + HSV hsv4 = new HSV(computeAverageColor(settings.TerrainTexture4, m_color_4)); float levelNElow = (float)settings.Elevation1NE; float levelNEhigh = (float)settings.Elevation2NE; @@ -417,7 +424,7 @@ namespace OpenSim.Region.CoreModules.World.LegacyMap heightvalue = 100f - (heightvalue * 100f) / 19f; // 0 - 19 => 100 - 0 - mapbmp.SetPixel(x, yr, WATER_COLOR); + mapbmp.SetPixel(x, yr, m_color_water); } } } diff --git a/bin/OpenSim.ini.example b/bin/OpenSim.ini.example index ceded47736..14a41b03e5 100644 --- a/bin/OpenSim.ini.example +++ b/bin/OpenSim.ini.example @@ -370,6 +370,21 @@ ;; Attempt to render meshes and sculpties on the map. ; RenderMeshes = false + ;# {MapColorWater} {} {Water color for textured and shaded maps} {"#1D475F"} + ; MapColorWater = "#3399FF" + + ;# {MapColor1} {} {Terrain color 1 for textured maps} {"#A58976"} + ; MapColor1 = "#A58976" + + ;# {MapColor2} {} {Terrain color 2 for textured maps} {"#455931"} + ; MapColor2 = "#455931" + + ;# {MapColor3} {} {Terrain color 3 for textured maps} {"#A29A8D"} + ; MapColor3 = "#A29A8D" + + ;# {MapColor4} {} {Terrain color 4 for textured maps} {"#C8C8C8"} + ; MapColor4 = "#C8C8C8" + [Permissions] ;# {permissionmodules} {} {Permission modules to use (may specify multiple modules, separated by comma} {} DefaultPermissionsModule From 873d42005fed47ba6e7c9bc2184e33f496ff9ce7 Mon Sep 17 00:00:00 2001 From: UbitUmarov Date: Tue, 14 Nov 2017 03:49:32 +0000 Subject: [PATCH 2/9] add AGENT_LIST_EXCLUDENPC bit mask option to llGetAgentList scope to exclude NPCs --- .../ScriptEngine/Shared/Api/Implementation/LSL_Api.cs | 10 ++++++++++ .../ScriptEngine/Shared/Api/Runtime/LSL_Constants.cs | 1 + 2 files changed, 11 insertions(+) diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs index fa32986a47..d36d9a048b 100644 --- a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs +++ b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs @@ -6639,11 +6639,18 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api /// AGENT_LIST_PARCEL - all in the same parcel as the scripted object /// AGENT_LIST_PARCEL_OWNER - all in any parcel owned by the owner of the /// current parcel. + /// AGENT_LIST_EXCLUDENPC ignore NPCs (bit mask) /// public LSL_List llGetAgentList(LSL_Integer scope, LSL_List options) { m_host.AddScriptLPS(1); + // do our bit masks part + bool noNPC = (scope & ScriptBaseClass.AGENT_LIST_EXCLUDENPC) !=0; + + // remove bit masks part + scope &= ~ ScriptBaseClass.AGENT_LIST_EXCLUDENPC; + // the constants are 1, 2 and 4 so bits are being set, but you // get an error "INVALID_SCOPE" if it is anything but 1, 2 and 4 bool regionWide = scope == ScriptBaseClass.AGENT_LIST_REGION; @@ -6684,6 +6691,9 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api World.ForEachRootScenePresence( delegate (ScenePresence ssp) { + if(noNPC && ssp.IsNPC) + return; + // Gods are not listed in SL if (!ssp.IsDeleted && !ssp.IsViewerUIGod && !ssp.IsChildAgent) { diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/LSL_Constants.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/LSL_Constants.cs index e4c1ca0a8f..2f249a70f6 100644 --- a/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/LSL_Constants.cs +++ b/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/LSL_Constants.cs @@ -660,6 +660,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.ScriptBase public const int AGENT_LIST_PARCEL = 1; public const int AGENT_LIST_PARCEL_OWNER = 2; public const int AGENT_LIST_REGION = 4; + public const int AGENT_LIST_EXCLUDENPC = 0x4000000; // our flag, not SL and it is a bit mask // Can not be public const? public static readonly vector ZERO_VECTOR = new vector(0.0, 0.0, 0.0); From d35ab8c86ceb721302bfde309815107911fb1c02 Mon Sep 17 00:00:00 2001 From: Melanie Thielker Date: Tue, 14 Nov 2017 12:12:07 +0000 Subject: [PATCH 3/9] Donating the Avination Mute Module This lived out-of-tree and therefore wasn't part of the big code drop. It's classic Avination, tied to MySQL and a direct database connection and I don't have the bandwidth to fix it to core methods. However, it has all the strange mute logic that OpenSim was missing and maybe someone can step up to make it work in an open grid context. --- OpenSim/Data/MySQL/Resources/XMute.migrations | 16 + .../Avatar/InstantMessage/XMuteModule.cs | 357 ++++++++++++++++++ prebuild.xml | 3 + 3 files changed, 376 insertions(+) create mode 100644 OpenSim/Data/MySQL/Resources/XMute.migrations create mode 100644 OpenSim/Region/CoreModules/Avatar/InstantMessage/XMuteModule.cs diff --git a/OpenSim/Data/MySQL/Resources/XMute.migrations b/OpenSim/Data/MySQL/Resources/XMute.migrations new file mode 100644 index 0000000000..4ac7f82448 --- /dev/null +++ b/OpenSim/Data/MySQL/Resources/XMute.migrations @@ -0,0 +1,16 @@ +:VERSION 1 + +BEGIN; + +CREATE TABLE `XMute` ( + `AgentID` char(36) NOT NULL, + `MuteID` char(36) NOT NULL DEFAULT '00000000-0000-0000-0000-000000000000', + `MuteName` varchar(64) NOT NULL DEFAULT '', + `MuteType` int(11) NOT NULL DEFAULT '1', + `MuteFlags` int(11) NOT NULL DEFAULT '0', + `Stamp` int(11) NOT NULL, + UNIQUE KEY `AgentID_2` (`AgentID`,`MuteID`,`MuteName`), + KEY `AgentID` (`AgentID`) +); + +COMMIT; diff --git a/OpenSim/Region/CoreModules/Avatar/InstantMessage/XMuteModule.cs b/OpenSim/Region/CoreModules/Avatar/InstantMessage/XMuteModule.cs new file mode 100644 index 0000000000..fb5239fb32 --- /dev/null +++ b/OpenSim/Region/CoreModules/Avatar/InstantMessage/XMuteModule.cs @@ -0,0 +1,357 @@ +/* + * 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 log4net; +using Nini.Config; +using OpenMetaverse; +using OpenSim.Framework; +using OpenSim.Framework.Servers; +using OpenSim.Framework.Client; +using OpenSim.Region.Framework.Interfaces; +using OpenSim.Region.Framework.Scenes; +using Mono.Addins; +using OpenSim.Data; +using OpenSim.Data.MySQL; +using MySql.Data.MySqlClient; +using System.Security.Cryptography; + +namespace OpenSim.Region.CoreModules.Avatar.InstantMessage +{ + public class MuteData + { + public UUID AgentID; + public UUID MuteID; + public string MuteName; + public int MuteType; + public int MuteFlags; + public int Stamp; + } + + [Extension(Path = "/OpenSim/RegionModules", NodeName = "RegionModule", Id = "XMute")] + public class XMuteModule : ISharedRegionModule + { + private static readonly ILog m_log = LogManager.GetLogger( + MethodBase.GetCurrentMethod().DeclaringType); + + protected bool m_Enabled = true; + protected List m_SceneList = new List(); + protected MuteTableHandler m_MuteTable; + protected string m_DatabaseConnect; + + public void Initialise(IConfigSource config) + { + IConfig cnf = config.Configs["Messaging"]; + if (cnf == null) + { + m_Enabled = false; + return; + } + + if (cnf.GetString("MuteListModule", "None") != + "XMute") + { + m_Enabled = false; + return; + } + + m_DatabaseConnect = cnf.GetString("MuteDatabaseConnect", String.Empty); + if (m_DatabaseConnect == String.Empty) + { + m_log.Debug("[XMute]: MuteDatabaseConnect missing or empty"); + m_Enabled = false; + return; + } + + m_MuteTable = new MuteTableHandler( + m_DatabaseConnect, "XMute", String.Empty); + } + + public void AddRegion(Scene scene) + { + if (!m_Enabled) + return; + + lock (m_SceneList) + { + m_SceneList.Add(scene); + + scene.EventManager.OnNewClient += OnNewClient; + } + } + + public void RegionLoaded(Scene scene) + { + } + + public void RemoveRegion(Scene scene) + { + if (!m_Enabled) + return; + + lock (m_SceneList) + { + m_SceneList.Remove(scene); + } + } + + public void PostInitialise() + { + if (!m_Enabled) + return; + + m_log.Debug("[XMute]: Mute list enabled"); + } + + public string Name + { + get { return "XMuteModule"; } + } + + public Type ReplaceableInterface + { + get { return null; } + } + + public void Close() + { + } + + private void OnNewClient(IClientAPI client) + { + client.OnMuteListRequest += OnMuteListRequest; + client.OnUpdateMuteListEntry += OnUpdateMuteListEntry; + client.OnRemoveMuteListEntry += OnRemoveMuteListEntry; + } + + private void OnMuteListRequest(IClientAPI client, uint crc) + { + string filename = "mutes"+client.AgentId.ToString(); + + IXfer xfer = client.Scene.RequestModuleInterface(); + if (xfer != null) + { + MuteData[] data = m_MuteTable.Get("AgentID", client.AgentId.ToString()); + if (data == null || data.Length == 0) + { + xfer.AddNewFile(filename, new Byte[0]); + } + else + { + List mutes = new List(); + + foreach (MuteData d in data) + mutes.Add(String.Format("{0} {1} {2}|{3}", + d.MuteType, + d.MuteID.ToString(), + d.MuteName, + d.MuteFlags)); + + Byte[] filedata = Util.UTF8.GetBytes(String.Join("\n", + mutes.ToArray()) + "\n"); + + uint dataCrc = Crc32.Compute(filedata); + + if (dataCrc == crc) + { + client.SendUseCachedMuteList(); + return; + } + + xfer.AddNewFile(filename, filedata); + } + + client.SendMuteListUpdate(filename); + } + } + + private void OnUpdateMuteListEntry(IClientAPI client, UUID muteID, string muteName, int muteType, uint muteFlags) + { + MuteData mute = new MuteData(); + + mute.AgentID = client.AgentId; + mute.MuteID = muteID; + mute.MuteName = muteName; + mute.MuteType = muteType; + mute.MuteFlags = (int)muteFlags; + mute.Stamp = Util.UnixTimeSinceEpoch(); + + m_MuteTable.Store(mute); + } + + private void OnRemoveMuteListEntry(IClientAPI client, UUID muteID, string muteName) + { + m_MuteTable.Delete(new string[] { "AgentID", + "MuteID", + "MuteName" }, + new string[] { client.AgentId.ToString(), + muteID.ToString(), + muteName }); + } + } + + public class MuteTableHandler : MySQLGenericTableHandler + { + public MuteTableHandler(string conn, string realm, string m) : base(conn, realm, m) + { + } + + public bool Delete(string[] fields, string[] val) + { + if (fields.Length != val.Length) + return false; + + using (MySqlCommand cmd = new MySqlCommand()) + { + string text = String.Format("delete from {0} where ", m_Realm); + + List terms = new List(); + + for (int i = 0 ; i < fields.Length ; i++) + { + terms.Add(String.Format("{0} = ?{0}", fields[i])); + cmd.Parameters.AddWithValue("?" + fields[i], val[i]); + } + + text += string.Join(" and ", terms.ToArray()); + + cmd.CommandText = text; + + if (ExecuteNonQuery(cmd) > 0) + return true; + return false; + } + } + } + + public class Crc32 : HashAlgorithm + { + public const UInt32 DefaultPolynomial = 0xedb88320; + public const UInt32 DefaultSeed = 0xffffffff; + + private UInt32 hash; + private UInt32 seed; + private UInt32[] table; + private static UInt32[] defaultTable; + + public Crc32() + { + table = InitializeTable(DefaultPolynomial); + seed = DefaultSeed; + Initialize(); + } + + public Crc32(UInt32 polynomial, UInt32 seed) + { + table = InitializeTable(polynomial); + this.seed = seed; + Initialize(); + } + + public override void Initialize() + { + hash = seed; + } + + protected override void HashCore(byte[] buffer, int start, int length) + { + hash = CalculateHash(table, hash, buffer, start, length); + } + + protected override byte[] HashFinal() + { + byte[] hashBuffer = UInt32ToBigEndianBytes(~hash); + this.HashValue = hashBuffer; + return hashBuffer; + } + + public override int HashSize + { + get { return 32; } + } + + public static UInt32 Compute(byte[] buffer) + { + return ~CalculateHash(InitializeTable(DefaultPolynomial), DefaultSeed, buffer, 0, buffer.Length); + } + + public static UInt32 Compute(UInt32 seed, byte[] buffer) + { + return ~CalculateHash(InitializeTable(DefaultPolynomial), seed, buffer, 0, buffer.Length); + } + + public static UInt32 Compute(UInt32 polynomial, UInt32 seed, byte[] buffer) + { + return ~CalculateHash(InitializeTable(polynomial), seed, buffer, 0, buffer.Length); + } + + private static UInt32[] InitializeTable(UInt32 polynomial) + { + if (polynomial == DefaultPolynomial && defaultTable != null) + return defaultTable; + + UInt32[] createTable = new UInt32[256]; + for (int i = 0; i < 256; i++) + { + UInt32 entry = (UInt32)i; + for (int j = 0; j < 8; j++) + if ((entry & 1) == 1) + entry = (entry >> 1) ^ polynomial; + else + entry = entry >> 1; + createTable[i] = entry; + } + + if (polynomial == DefaultPolynomial) + defaultTable = createTable; + + return createTable; + } + + private static UInt32 CalculateHash(UInt32[] table, UInt32 seed, byte[] buffer, int start, int size) + { + UInt32 crc = seed; + for (int i = start; i < size; i++) + unchecked + { + crc = (crc >> 8) ^ table[buffer[i] ^ crc & 0xff]; + } + return crc; + } + + private byte[] UInt32ToBigEndianBytes(UInt32 x) + { + return new byte[] { + (byte)((x >> 24) & 0xff), + (byte)((x >> 16) & 0xff), + (byte)((x >> 8) & 0xff), + (byte)(x & 0xff) }; + } + } +} + diff --git a/prebuild.xml b/prebuild.xml index f31f749fd4..94e3ec9f09 100644 --- a/prebuild.xml +++ b/prebuild.xml @@ -1393,6 +1393,7 @@ + @@ -1402,6 +1403,7 @@ + @@ -1417,6 +1419,7 @@ + From 2f13b68d4f4fd634eaee005bdf4c4a8e21c21c9a Mon Sep 17 00:00:00 2001 From: UbitUmarov Date: Thu, 16 Nov 2017 17:50:06 +0000 Subject: [PATCH 4/9] add missing part of mutes list protocol --- OpenSim/Framework/IClientAPI.cs | 2 +- .../ClientStack/Linden/UDP/LLClientView.cs | 35 +++++++++++++++++-- .../Server/IRCClientView.cs | 5 +++ .../OptionalModules/World/NPC/NPCAvatar.cs | 4 +++ OpenSim/Tests/Common/Mock/TestClient.cs | 4 +++ 5 files changed, 47 insertions(+), 3 deletions(-) diff --git a/OpenSim/Framework/IClientAPI.cs b/OpenSim/Framework/IClientAPI.cs index 5ca8c88ecb..a9044d5aed 100644 --- a/OpenSim/Framework/IClientAPI.cs +++ b/OpenSim/Framework/IClientAPI.cs @@ -1485,7 +1485,7 @@ namespace OpenSim.Framework void SendUserInfoReply(bool imViaEmail, bool visible, string email); void SendUseCachedMuteList(); - + void SendEmpytMuteList(); void SendMuteListUpdate(string filename); void SendGroupActiveProposals(UUID groupID, UUID transactionID, GroupActiveProposals[] Proposals); diff --git a/OpenSim/Region/ClientStack/Linden/UDP/LLClientView.cs b/OpenSim/Region/ClientStack/Linden/UDP/LLClientView.cs index 4a76ffc6c3..2ff6cedc07 100644 --- a/OpenSim/Region/ClientStack/Linden/UDP/LLClientView.cs +++ b/OpenSim/Region/ClientStack/Linden/UDP/LLClientView.cs @@ -2307,11 +2307,23 @@ namespace OpenSim.Region.ClientStack.LindenUDP OutPacket(remove, ThrottleOutPacketType.Asset); } +/* + private uint adjustControls(int input) + { + uint ret = (uint)input; + uint masked = ret & 0x0f; + masked <<= 19; + ret |= masked; + return ret; + } +*/ + public void SendTakeControls(int controls, bool passToAgent, bool TakeControls) { ScriptControlChangePacket scriptcontrol = (ScriptControlChangePacket)PacketPool.Instance.GetPacket(PacketType.ScriptControlChange); ScriptControlChangePacket.DataBlock[] data = new ScriptControlChangePacket.DataBlock[1]; ScriptControlChangePacket.DataBlock ddata = new ScriptControlChangePacket.DataBlock(); +// ddata.Controls = adjustControls(controls); ddata.Controls = (uint)controls; ddata.PassToAgent = passToAgent; ddata.TakeControls = TakeControls; @@ -3762,6 +3774,22 @@ namespace OpenSim.Region.ClientStack.LindenUDP OutPacket(useCachedMuteList, ThrottleOutPacketType.Task); } + public void SendEmpytMuteList() + { + GenericMessagePacket gmp = new GenericMessagePacket(); + + gmp.AgentData.AgentID = AgentId; + gmp.AgentData.SessionID = m_sessionId; + gmp.AgentData.TransactionID = UUID.Zero; + + gmp.MethodData.Method = Util.StringToBytes256("emptymutelist"); + gmp.ParamList = new GenericMessagePacket.ParamListBlock[1]; + gmp.ParamList[0] = new GenericMessagePacket.ParamListBlock(); + gmp.ParamList[0].Parameter = new byte[0]; + + OutPacket(gmp, ThrottleOutPacketType.Task); + } + public void SendMuteListUpdate(string filename) { MuteListUpdatePacket muteListUpdate = (MuteListUpdatePacket)PacketPool.Instance.GetPacket(PacketType.MuteListUpdate); @@ -11008,9 +11036,12 @@ namespace OpenSim.Region.ClientStack.LindenUDP } else { - SendUseCachedMuteList(); + if(muteListRequest.MuteData.MuteCRC == 0) + SendEmpytMuteList(); + else + SendUseCachedMuteList(); } - return true; + return true; } private bool HandleUpdateMuteListEntry(IClientAPI client, Packet Packet) diff --git a/OpenSim/Region/OptionalModules/Agent/InternetRelayClientView/Server/IRCClientView.cs b/OpenSim/Region/OptionalModules/Agent/InternetRelayClientView/Server/IRCClientView.cs index d39c224129..469dd67437 100644 --- a/OpenSim/Region/OptionalModules/Agent/InternetRelayClientView/Server/IRCClientView.cs +++ b/OpenSim/Region/OptionalModules/Agent/InternetRelayClientView/Server/IRCClientView.cs @@ -1702,6 +1702,11 @@ namespace OpenSim.Region.OptionalModules.Agent.InternetRelayClientView.Server } + public void SendEmpytMuteList() + { + + } + public void SendMuteListUpdate(string filename) { diff --git a/OpenSim/Region/OptionalModules/World/NPC/NPCAvatar.cs b/OpenSim/Region/OptionalModules/World/NPC/NPCAvatar.cs index 151a202e49..bb23f2fb1f 100644 --- a/OpenSim/Region/OptionalModules/World/NPC/NPCAvatar.cs +++ b/OpenSim/Region/OptionalModules/World/NPC/NPCAvatar.cs @@ -1314,6 +1314,10 @@ namespace OpenSim.Region.OptionalModules.World.NPC { } + public void SendEmpytMuteList() + { + } + public void SendMuteListUpdate(string filename) { } diff --git a/OpenSim/Tests/Common/Mock/TestClient.cs b/OpenSim/Tests/Common/Mock/TestClient.cs index a8359255ad..449716b60f 100644 --- a/OpenSim/Tests/Common/Mock/TestClient.cs +++ b/OpenSim/Tests/Common/Mock/TestClient.cs @@ -1315,6 +1315,10 @@ namespace OpenSim.Tests.Common { } + public void SendEmpytMuteList() + { + } + public void SendMuteListUpdate(string filename) { } From 366cdac656fc99b9fe83fcc2d9c88cc2ca5959a8 Mon Sep 17 00:00:00 2001 From: UbitUmarov Date: Thu, 16 Nov 2017 18:13:32 +0000 Subject: [PATCH 5/9] try kick jenkins/nant --- prebuild.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/prebuild.xml b/prebuild.xml index 94e3ec9f09..2f741f406c 100644 --- a/prebuild.xml +++ b/prebuild.xml @@ -1402,8 +1402,6 @@ - - @@ -1418,6 +1416,8 @@ + + From 4150a616c5158a003afe800b57d334bd7dd94c2f Mon Sep 17 00:00:00 2001 From: UbitUmarov Date: Thu, 16 Nov 2017 18:45:01 +0000 Subject: [PATCH 6/9] try kick jenkins/nant 2 --- prebuild.xml | 230 ++++++++++++++++++++++++++------------------------- 1 file changed, 116 insertions(+), 114 deletions(-) diff --git a/prebuild.xml b/prebuild.xml index 2f741f406c..44946be43d 100644 --- a/prebuild.xml +++ b/prebuild.xml @@ -1371,6 +1371,122 @@ + + + + + + ../../../bin/ + + + + + ../../../bin/ + + + + ../../../bin/ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + ../../../bin/ + + + + + ../../../bin/ + + + + ../../../bin/ + + + + + + + + + + + + + + + + + + + + + + + + + + + ../../../bin/ + + + + + ../../../bin/ + + + + ../../../bin/ + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -1922,120 +2038,6 @@ - - - - - ../../../bin/ - - - - - ../../../bin/ - - - - ../../../bin/ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - ../../../bin/ - - - - - ../../../bin/ - - - - ../../../bin/ - - - - - - - - - - - - - - - - - - - - - - - - - - - ../../../bin/ - - - - - ../../../bin/ - - - - ../../../bin/ - - - - - - - - - - - - - - - - - - - - - - - - - From 1e3cb827562f580aea60deab640f98078107e8a3 Mon Sep 17 00:00:00 2001 From: UbitUmarov Date: Fri, 17 Nov 2017 01:30:39 +0000 Subject: [PATCH 7/9] move some sharable items out of Xmute to Framework; add another test mutelistmodule, ignore it --- OpenSim/Framework/Crc32.cs | 139 +++++++++++ OpenSim/Framework/MuteData.cs | 41 ++++ .../InstantMessage/MuteListModuleTst.cs | 224 ++++++++++++++++++ .../Avatar/InstantMessage/XMuteModule.cs | 125 +--------- prebuild.xml | 2 + 5 files changed, 411 insertions(+), 120 deletions(-) create mode 100644 OpenSim/Framework/Crc32.cs create mode 100644 OpenSim/Framework/MuteData.cs create mode 100644 OpenSim/Region/CoreModules/Avatar/InstantMessage/MuteListModuleTst.cs diff --git a/OpenSim/Framework/Crc32.cs b/OpenSim/Framework/Crc32.cs new file mode 100644 index 0000000000..7ad156646f --- /dev/null +++ b/OpenSim/Framework/Crc32.cs @@ -0,0 +1,139 @@ +/* + * 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.Security.Cryptography; + +namespace OpenSim.Framework +{ + // this is more generic than openmetaverse CRC32 + + public class Crc32 : HashAlgorithm + { + public const UInt32 DefaultPolynomial = 0xedb88320; + public const UInt32 DefaultSeed = 0xffffffff; + + private UInt32 hash; + private UInt32 seed; + private UInt32[] table; + private static UInt32[] defaultTable; + + public Crc32() + { + table = InitializeTable(DefaultPolynomial); + seed = DefaultSeed; + Initialize(); + } + + public Crc32(UInt32 polynomial, UInt32 seed) + { + table = InitializeTable(polynomial); + this.seed = seed; + Initialize(); + } + + public override void Initialize() + { + hash = seed; + } + + protected override void HashCore(byte[] buffer, int start, int length) + { + hash = CalculateHash(table, hash, buffer, start, length); + } + + protected override byte[] HashFinal() + { + byte[] hashBuffer = UInt32ToBigEndianBytes(~hash); + this.HashValue = hashBuffer; + return hashBuffer; + } + + public override int HashSize + { + get { return 32; } + } + + public static UInt32 Compute(byte[] buffer) + { + return ~CalculateHash(InitializeTable(DefaultPolynomial), DefaultSeed, buffer, 0, buffer.Length); + } + + public static UInt32 Compute(UInt32 seed, byte[] buffer) + { + return ~CalculateHash(InitializeTable(DefaultPolynomial), seed, buffer, 0, buffer.Length); + } + + public static UInt32 Compute(UInt32 polynomial, UInt32 seed, byte[] buffer) + { + return ~CalculateHash(InitializeTable(polynomial), seed, buffer, 0, buffer.Length); + } + + private static UInt32[] InitializeTable(UInt32 polynomial) + { + if (polynomial == DefaultPolynomial && defaultTable != null) + return defaultTable; + + UInt32[] createTable = new UInt32[256]; + for (int i = 0; i < 256; i++) + { + UInt32 entry = (UInt32)i; + for (int j = 0; j < 8; j++) + if ((entry & 1) == 1) + entry = (entry >> 1) ^ polynomial; + else + entry = entry >> 1; + createTable[i] = entry; + } + + if (polynomial == DefaultPolynomial) + defaultTable = createTable; + + return createTable; + } + + private static UInt32 CalculateHash(UInt32[] table, UInt32 seed, byte[] buffer, int start, int size) + { + UInt32 crc = seed; + for (int i = start; i < size; i++) + unchecked + { + crc = (crc >> 8) ^ table[buffer[i] ^ crc & 0xff]; + } + return crc; + } + + private byte[] UInt32ToBigEndianBytes(UInt32 x) + { + return new byte[] { + (byte)((x >> 24) & 0xff), + (byte)((x >> 16) & 0xff), + (byte)((x >> 8) & 0xff), + (byte)(x & 0xff) }; + } + } +} diff --git a/OpenSim/Framework/MuteData.cs b/OpenSim/Framework/MuteData.cs new file mode 100644 index 0000000000..7c946d6650 --- /dev/null +++ b/OpenSim/Framework/MuteData.cs @@ -0,0 +1,41 @@ +/* + * 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 OpenMetaverse; + +namespace OpenSim.Framework +{ + public class MuteData + { + public UUID AgentID; + public UUID MuteID; + public string MuteName; + public int MuteType; + public int MuteFlags; + public int Stamp; + } +} diff --git a/OpenSim/Region/CoreModules/Avatar/InstantMessage/MuteListModuleTst.cs b/OpenSim/Region/CoreModules/Avatar/InstantMessage/MuteListModuleTst.cs new file mode 100644 index 0000000000..7ade511590 --- /dev/null +++ b/OpenSim/Region/CoreModules/Avatar/InstantMessage/MuteListModuleTst.cs @@ -0,0 +1,224 @@ +/* + * 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.Text; +using log4net; +using Nini.Config; +using OpenMetaverse; +using OpenSim.Framework; +using OpenSim.Framework.Servers; +using OpenSim.Framework.Client; +using OpenSim.Region.Framework.Interfaces; +using OpenSim.Region.Framework.Scenes; +using Mono.Addins; +using OpenSim.Data; +using OpenSim.Data.MySQL; +using MySql.Data.MySqlClient; +using System.Security.Cryptography; + +namespace OpenSim.Region.CoreModules.Avatar.InstantMessage +{ + [Extension(Path = "/OpenSim/RegionModules", NodeName = "RegionModule", Id = "MuteListModuleTst")] + public class MuteModuleTst : ISharedRegionModule + { + private static readonly ILog m_log = LogManager.GetLogger( + MethodBase.GetCurrentMethod().DeclaringType); + + protected bool m_Enabled = false; + protected List m_SceneList = new List(); + protected MuteTableHandler m_MuteTable; + protected string m_DatabaseConnect; + + public void Initialise(IConfigSource config) + { + IConfig cnf = config.Configs["Messaging"]; + if (cnf == null) + return; + + if (cnf.GetString("MuteListModule", "None") != "MuteListModuleTst") + return; + + m_DatabaseConnect = cnf.GetString("MuteDatabaseConnect", String.Empty); + if (m_DatabaseConnect == String.Empty) + { + m_log.Debug("[MuteModuleTst]: MuteDatabaseConnect missing or empty"); + return; + } + + try + { + m_MuteTable = new MuteTableHandler(m_DatabaseConnect, "XMute", String.Empty); + } + catch + { + m_log.Error("[MuteListModuleTst]: Failed to open/create database table"); + return; + } + + m_Enabled = true; + } + + public void AddRegion(Scene scene) + { + if (!m_Enabled) + return; + + lock (m_SceneList) + { + m_SceneList.Add(scene); + + scene.EventManager.OnNewClient += OnNewClient; + } + } + + public void RegionLoaded(Scene scene) + { + if (!m_Enabled) + return; + + IXfer xfer = scene.RequestModuleInterface(); + if (xfer == null) + m_log.ErrorFormat("[MuteListModuleTst]: Xfer not availble in region {0}", scene.Name); + } + + public void RemoveRegion(Scene scene) + { + if (!m_Enabled) + return; + + lock (m_SceneList) + { + m_SceneList.Remove(scene); + } + } + + public void PostInitialise() + { + if (!m_Enabled) + return; + + m_log.Debug("[MuteListModuleTst]: Mute list enabled"); + } + + public string Name + { + get { return "MuteListModuleTst"; } + } + + public Type ReplaceableInterface + { + get { return null; } + } + + public void Close() + { + } + + private void OnNewClient(IClientAPI client) + { + client.OnMuteListRequest += OnMuteListRequest; + client.OnUpdateMuteListEntry += OnUpdateMuteListEntry; + client.OnRemoveMuteListEntry += OnRemoveMuteListEntry; + } + + private void OnMuteListRequest(IClientAPI client, uint crc) + { + IXfer xfer = client.Scene.RequestModuleInterface(); + if (xfer == null) + { + if(crc == 0) + client.SendEmpytMuteList(); + else + client.SendUseCachedMuteList(); + return; + } + + MuteData[] data = m_MuteTable.Get("AgentID", client.AgentId.ToString()); + if (data == null || data.Length == 0) + { + if(crc == 0) + client.SendEmpytMuteList(); + else + client.SendUseCachedMuteList(); + return; + } + + StringBuilder sb = new StringBuilder(16384); + + foreach (MuteData d in data) + sb.AppendFormat("{0} {1} {2}|{3}\n", + d.MuteType, + d.MuteID.ToString(), + d.MuteName, + d.MuteFlags); + + Byte[] filedata = Util.UTF8.GetBytes(sb.ToString()); + + uint dataCrc = Crc32.Compute(filedata); + + if (dataCrc == crc) + { + if(crc == 0) + client.SendEmpytMuteList(); + else + client.SendUseCachedMuteList(); + return; + } + + string filename = "mutes"+client.AgentId.ToString(); + xfer.AddNewFile(filename, filedata); + client.SendMuteListUpdate(filename); + } + + private void OnUpdateMuteListEntry(IClientAPI client, UUID muteID, string muteName, int muteType, uint muteFlags) + { + MuteData mute = new MuteData(); + + mute.AgentID = client.AgentId; + mute.MuteID = muteID; + mute.MuteName = muteName; + mute.MuteType = muteType; + mute.MuteFlags = (int)muteFlags; + mute.Stamp = Util.UnixTimeSinceEpoch(); + + m_MuteTable.Store(mute); + } + + private void OnRemoveMuteListEntry(IClientAPI client, UUID muteID, string muteName) + { + m_MuteTable.Delete(new string[] { "AgentID", + "MuteID", + "MuteName" }, + new string[] { client.AgentId.ToString(), + muteID.ToString(), + muteName }); + } + } +} + diff --git a/OpenSim/Region/CoreModules/Avatar/InstantMessage/XMuteModule.cs b/OpenSim/Region/CoreModules/Avatar/InstantMessage/XMuteModule.cs index fb5239fb32..ac542c2602 100644 --- a/OpenSim/Region/CoreModules/Avatar/InstantMessage/XMuteModule.cs +++ b/OpenSim/Region/CoreModules/Avatar/InstantMessage/XMuteModule.cs @@ -27,6 +27,7 @@ using System; using System.Collections.Generic; using System.Reflection; +using System.Text; using log4net; using Nini.Config; using OpenMetaverse; @@ -43,16 +44,6 @@ using System.Security.Cryptography; namespace OpenSim.Region.CoreModules.Avatar.InstantMessage { - public class MuteData - { - public UUID AgentID; - public UUID MuteID; - public string MuteName; - public int MuteType; - public int MuteFlags; - public int Stamp; - } - [Extension(Path = "/OpenSim/RegionModules", NodeName = "RegionModule", Id = "XMute")] public class XMuteModule : ISharedRegionModule { @@ -163,17 +154,16 @@ namespace OpenSim.Region.CoreModules.Avatar.InstantMessage } else { - List mutes = new List(); + StringBuilder sb = new StringBuilder(1024); foreach (MuteData d in data) - mutes.Add(String.Format("{0} {1} {2}|{3}", + sb.AppendFormat("{0} {1} {2}|{3}\n", d.MuteType, d.MuteID.ToString(), d.MuteName, - d.MuteFlags)); + d.MuteFlags); - Byte[] filedata = Util.UTF8.GetBytes(String.Join("\n", - mutes.ToArray()) + "\n"); + Byte[] filedata = Util.UTF8.GetBytes(sb.ToString()); uint dataCrc = Crc32.Compute(filedata); @@ -248,110 +238,5 @@ namespace OpenSim.Region.CoreModules.Avatar.InstantMessage } } } - - public class Crc32 : HashAlgorithm - { - public const UInt32 DefaultPolynomial = 0xedb88320; - public const UInt32 DefaultSeed = 0xffffffff; - - private UInt32 hash; - private UInt32 seed; - private UInt32[] table; - private static UInt32[] defaultTable; - - public Crc32() - { - table = InitializeTable(DefaultPolynomial); - seed = DefaultSeed; - Initialize(); - } - - public Crc32(UInt32 polynomial, UInt32 seed) - { - table = InitializeTable(polynomial); - this.seed = seed; - Initialize(); - } - - public override void Initialize() - { - hash = seed; - } - - protected override void HashCore(byte[] buffer, int start, int length) - { - hash = CalculateHash(table, hash, buffer, start, length); - } - - protected override byte[] HashFinal() - { - byte[] hashBuffer = UInt32ToBigEndianBytes(~hash); - this.HashValue = hashBuffer; - return hashBuffer; - } - - public override int HashSize - { - get { return 32; } - } - - public static UInt32 Compute(byte[] buffer) - { - return ~CalculateHash(InitializeTable(DefaultPolynomial), DefaultSeed, buffer, 0, buffer.Length); - } - - public static UInt32 Compute(UInt32 seed, byte[] buffer) - { - return ~CalculateHash(InitializeTable(DefaultPolynomial), seed, buffer, 0, buffer.Length); - } - - public static UInt32 Compute(UInt32 polynomial, UInt32 seed, byte[] buffer) - { - return ~CalculateHash(InitializeTable(polynomial), seed, buffer, 0, buffer.Length); - } - - private static UInt32[] InitializeTable(UInt32 polynomial) - { - if (polynomial == DefaultPolynomial && defaultTable != null) - return defaultTable; - - UInt32[] createTable = new UInt32[256]; - for (int i = 0; i < 256; i++) - { - UInt32 entry = (UInt32)i; - for (int j = 0; j < 8; j++) - if ((entry & 1) == 1) - entry = (entry >> 1) ^ polynomial; - else - entry = entry >> 1; - createTable[i] = entry; - } - - if (polynomial == DefaultPolynomial) - defaultTable = createTable; - - return createTable; - } - - private static UInt32 CalculateHash(UInt32[] table, UInt32 seed, byte[] buffer, int start, int size) - { - UInt32 crc = seed; - for (int i = start; i < size; i++) - unchecked - { - crc = (crc >> 8) ^ table[buffer[i] ^ crc & 0xff]; - } - return crc; - } - - private byte[] UInt32ToBigEndianBytes(UInt32 x) - { - return new byte[] { - (byte)((x >> 24) & 0xff), - (byte)((x >> 16) & 0xff), - (byte)((x >> 8) & 0xff), - (byte)(x & 0xff) }; - } - } } diff --git a/prebuild.xml b/prebuild.xml index 44946be43d..f39cbde24e 100644 --- a/prebuild.xml +++ b/prebuild.xml @@ -97,6 +97,8 @@ + + From a95e28616842f70bb64bf701c2534d75490e539e Mon Sep 17 00:00:00 2001 From: UbitUmarov Date: Mon, 11 Dec 2017 23:36:42 +0000 Subject: [PATCH 8/9] increase sample rate of WaitGetScenePresence() --- OpenSim/Region/Framework/Scenes/Scene.cs | 4 ++-- bin/config-include/Standalone.ini | 4 ++++ bin/config-include/StandaloneHypergrid.ini | 4 ++++ 3 files changed, 10 insertions(+), 2 deletions(-) diff --git a/OpenSim/Region/Framework/Scenes/Scene.cs b/OpenSim/Region/Framework/Scenes/Scene.cs index c06b3dd401..c223aaef79 100755 --- a/OpenSim/Region/Framework/Scenes/Scene.cs +++ b/OpenSim/Region/Framework/Scenes/Scene.cs @@ -4632,10 +4632,10 @@ Label_GroupsDone: /// protected virtual ScenePresence WaitGetScenePresence(UUID agentID) { - int ntimes = 30; + int ntimes = 120; // 30s ScenePresence sp = null; while ((sp = GetScenePresence(agentID)) == null && (ntimes-- > 0)) - Thread.Sleep(1000); + Thread.Sleep(250); if (sp == null) m_log.WarnFormat( diff --git a/bin/config-include/Standalone.ini b/bin/config-include/Standalone.ini index db7cb365cd..4e683e2ab8 100644 --- a/bin/config-include/Standalone.ini +++ b/bin/config-include/Standalone.ini @@ -22,6 +22,7 @@ InventoryAccessModule = "BasicInventoryAccessModule" MapImageService = "MapImageServiceModule" SearchModule = "BasicSearchModule" + MuteListService = "LocalMuteListServicesConnector" LibraryModule = true LLLoginServiceInConnector = true @@ -113,6 +114,9 @@ [MapImageService] LocalServiceModule = "OpenSim.Services.MapImageService.dll:MapImageService" +[MuteListService] + LocalServiceModule = "OpenSim.Services.MuteListService.dll:MuteListService" + ;; This should always be the very last thing on this file [Includes] Include-Common = "config-include/StandaloneCommon.ini" diff --git a/bin/config-include/StandaloneHypergrid.ini b/bin/config-include/StandaloneHypergrid.ini index 84867a9a3c..4f3994f9af 100644 --- a/bin/config-include/StandaloneHypergrid.ini +++ b/bin/config-include/StandaloneHypergrid.ini @@ -27,6 +27,7 @@ FriendsModule = "HGFriendsModule" UserManagementModule = "HGUserManagementModule" SearchModule = "BasicSearchModule" + MuteListService = "LocalMuteListServicesConnector" InventoryServiceInConnector = true AssetServiceInConnector = true @@ -190,6 +191,9 @@ UserAgentService = "OpenSim.Services.HypergridService.dll:UserAgentService" InGatekeeper = True +[MuteListService] + LocalServiceModule = "OpenSim.Services.MuteListService.dll:MuteListService" + ;; This should always be the very last thing on this file [Includes] Include-Common = "config-include/StandaloneCommon.ini" From d32debe6184b1d6575b97541b98c520a8c4360c1 Mon Sep 17 00:00:00 2001 From: UbitUmarov Date: Mon, 11 Dec 2017 23:58:27 +0000 Subject: [PATCH 9/9] commit what i did so far for core mutes module, befere i lose it --- OpenSim/Data/IMuteListData.cs | 44 +++++ OpenSim/Data/MySQL/MySQLMuteListData.cs | 67 +++++++ .../MySQL/Resources/MuteListStore.migrations | 16 ++ .../InstantMessage/MuteListModuleTst.cs | 135 ++++++------- .../Avatar/InstantMessage/XMuteModule.cs | 5 +- .../MuteList/LocalMuteListServiceConnector.cs | 180 ++++++++++++++++++ .../Services/Interfaces/IMuteLIstService.cs | 41 ++++ .../MuteListService/MuteListService.cs | 127 ++++++++++++ 8 files changed, 546 insertions(+), 69 deletions(-) create mode 100644 OpenSim/Data/IMuteListData.cs create mode 100644 OpenSim/Data/MySQL/MySQLMuteListData.cs create mode 100644 OpenSim/Data/MySQL/Resources/MuteListStore.migrations create mode 100644 OpenSim/Region/CoreModules/ServiceConnectorsOut/MuteList/LocalMuteListServiceConnector.cs create mode 100644 OpenSim/Services/Interfaces/IMuteLIstService.cs create mode 100644 OpenSim/Services/MuteListService/MuteListService.cs diff --git a/OpenSim/Data/IMuteListData.cs b/OpenSim/Data/IMuteListData.cs new file mode 100644 index 0000000000..b0235b2fa8 --- /dev/null +++ b/OpenSim/Data/IMuteListData.cs @@ -0,0 +1,44 @@ +/* + * 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 OpenMetaverse; +using OpenSim.Framework; + +namespace OpenSim.Data +{ + /// + /// An interface for connecting to the Mute List datastore + /// + public interface IMuteListData + { + bool Store(MuteData data); + MuteData[] Get(UUID agentID); + bool Delete(UUID agentID, UUID muteID, string muteName); + } +} diff --git a/OpenSim/Data/MySQL/MySQLMuteListData.cs b/OpenSim/Data/MySQL/MySQLMuteListData.cs new file mode 100644 index 0000000000..a5935a32fa --- /dev/null +++ b/OpenSim/Data/MySQL/MySQLMuteListData.cs @@ -0,0 +1,67 @@ +/* + * 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; +using System.Collections.Generic; +using System.Data; +using OpenMetaverse; +using OpenSim.Framework; +using MySql.Data.MySqlClient; + +namespace OpenSim.Data.MySQL +{ + public class MySqlMuteListData : MySQLGenericTableHandler, IMuteListData + { + public MySqlMuteListData(string connectionString) + : base(connectionString, "MuteList", "MuteListStore") + { + } + + public MuteData[] Get(UUID agentID) + { + MuteData[] data = base.Get("AgentID", agentID.ToString()); + return data; + } + + public bool Delete(UUID agentID, UUID muteID, string muteName) + { + string cmnd ="delete from MuteList where AgentID = ?AgentID and MuteID = ?MuteID and MuteName = ?MuteName"; + + using (MySqlCommand cmd = new MySqlCommand(cmnd)) + { + cmd.Parameters.AddWithValue("?AgentID", agentID.ToString()); + cmd.Parameters.AddWithValue("?MuteID", muteID.ToString()); + cmd.Parameters.AddWithValue("?MuteName", muteName); + + if (ExecuteNonQuery(cmd) > 0) + return true; + return false; + } + } + } +} \ No newline at end of file diff --git a/OpenSim/Data/MySQL/Resources/MuteListStore.migrations b/OpenSim/Data/MySQL/Resources/MuteListStore.migrations new file mode 100644 index 0000000000..5bde63edd8 --- /dev/null +++ b/OpenSim/Data/MySQL/Resources/MuteListStore.migrations @@ -0,0 +1,16 @@ +:VERSION 1 + +BEGIN; + +CREATE TABLE `MuteList` ( + `AgentID` char(36) NOT NULL, + `MuteID` char(36) NOT NULL DEFAULT '00000000-0000-0000-0000-000000000000', + `MuteName` varchar(64) NOT NULL DEFAULT '', + `MuteType` int(11) NOT NULL DEFAULT '1', + `MuteFlags` int(11) NOT NULL DEFAULT '0', + `Stamp` int(11) NOT NULL, + UNIQUE KEY `AgentID_2` (`AgentID`,`MuteID`,`MuteName`), + KEY `AgentID` (`AgentID`) +); + +COMMIT; diff --git a/OpenSim/Region/CoreModules/Avatar/InstantMessage/MuteListModuleTst.cs b/OpenSim/Region/CoreModules/Avatar/InstantMessage/MuteListModuleTst.cs index 7ade511590..6857f352c8 100644 --- a/OpenSim/Region/CoreModules/Avatar/InstantMessage/MuteListModuleTst.cs +++ b/OpenSim/Region/CoreModules/Avatar/InstantMessage/MuteListModuleTst.cs @@ -37,23 +37,21 @@ using OpenSim.Framework.Client; using OpenSim.Region.Framework.Interfaces; using OpenSim.Region.Framework.Scenes; using Mono.Addins; -using OpenSim.Data; -using OpenSim.Data.MySQL; -using MySql.Data.MySqlClient; -using System.Security.Cryptography; + +using OpenSim.Server.Base; +using OpenSim.Services.Interfaces; namespace OpenSim.Region.CoreModules.Avatar.InstantMessage { [Extension(Path = "/OpenSim/RegionModules", NodeName = "RegionModule", Id = "MuteListModuleTst")] - public class MuteModuleTst : ISharedRegionModule + public class MuteListModuleTst : ISharedRegionModule { private static readonly ILog m_log = LogManager.GetLogger( MethodBase.GetCurrentMethod().DeclaringType); protected bool m_Enabled = false; protected List m_SceneList = new List(); - protected MuteTableHandler m_MuteTable; - protected string m_DatabaseConnect; + protected IMuteListService m_service = null; public void Initialise(IConfigSource config) { @@ -64,37 +62,11 @@ namespace OpenSim.Region.CoreModules.Avatar.InstantMessage if (cnf.GetString("MuteListModule", "None") != "MuteListModuleTst") return; - m_DatabaseConnect = cnf.GetString("MuteDatabaseConnect", String.Empty); - if (m_DatabaseConnect == String.Empty) - { - m_log.Debug("[MuteModuleTst]: MuteDatabaseConnect missing or empty"); - return; - } - - try - { - m_MuteTable = new MuteTableHandler(m_DatabaseConnect, "XMute", String.Empty); - } - catch - { - m_log.Error("[MuteListModuleTst]: Failed to open/create database table"); - return; - } - m_Enabled = true; } public void AddRegion(Scene scene) { - if (!m_Enabled) - return; - - lock (m_SceneList) - { - m_SceneList.Add(scene); - - scene.EventManager.OnNewClient += OnNewClient; - } } public void RegionLoaded(Scene scene) @@ -104,17 +76,37 @@ namespace OpenSim.Region.CoreModules.Avatar.InstantMessage IXfer xfer = scene.RequestModuleInterface(); if (xfer == null) - m_log.ErrorFormat("[MuteListModuleTst]: Xfer not availble in region {0}", scene.Name); + { + m_log.ErrorFormat("[MuteListModuleTst]: Xfer not availble in region {0}. Module Disabled", scene.Name); + m_Enabled = false; + return; + } + + IMuteListService srv = scene.RequestModuleInterface(); + if(srv == null) + { + m_log.ErrorFormat("[MuteListModuleTst]: MuteListService not availble in region {0}. Module Disabled", scene.Name); + m_Enabled = false; + return; + } + lock (m_SceneList) + { + if(m_service == null) + m_service = srv; + m_SceneList.Add(scene); + scene.EventManager.OnNewClient += OnNewClient; + } } public void RemoveRegion(Scene scene) { - if (!m_Enabled) - return; - lock (m_SceneList) { - m_SceneList.Remove(scene); + if(m_SceneList.Contains(scene)) + { + m_SceneList.Remove(scene); + scene.EventManager.OnNewClient -= OnNewClient; + } } } @@ -123,7 +115,7 @@ namespace OpenSim.Region.CoreModules.Avatar.InstantMessage if (!m_Enabled) return; - m_log.Debug("[MuteListModuleTst]: Mute list enabled"); + m_log.Debug("[MuteListModuleTst]: enabled"); } public string Name @@ -149,6 +141,15 @@ namespace OpenSim.Region.CoreModules.Avatar.InstantMessage private void OnMuteListRequest(IClientAPI client, uint crc) { + if (!m_Enabled) + { + if(crc == 0) + client.SendEmpytMuteList(); + else + client.SendUseCachedMuteList(); + return; + } + IXfer xfer = client.Scene.RequestModuleInterface(); if (xfer == null) { @@ -159,8 +160,8 @@ namespace OpenSim.Region.CoreModules.Avatar.InstantMessage return; } - MuteData[] data = m_MuteTable.Get("AgentID", client.AgentId.ToString()); - if (data == null || data.Length == 0) + Byte[] data = m_service.MuteListRequest(client.AgentId, crc); + if (data == null) { if(crc == 0) client.SendEmpytMuteList(); @@ -169,20 +170,13 @@ namespace OpenSim.Region.CoreModules.Avatar.InstantMessage return; } - StringBuilder sb = new StringBuilder(16384); + if (data.Length == 0) + { + client.SendEmpytMuteList(); + return; + } - foreach (MuteData d in data) - sb.AppendFormat("{0} {1} {2}|{3}\n", - d.MuteType, - d.MuteID.ToString(), - d.MuteName, - d.MuteFlags); - - Byte[] filedata = Util.UTF8.GetBytes(sb.ToString()); - - uint dataCrc = Crc32.Compute(filedata); - - if (dataCrc == crc) + if (data.Length == 1) { if(crc == 0) client.SendEmpytMuteList(); @@ -191,33 +185,44 @@ namespace OpenSim.Region.CoreModules.Avatar.InstantMessage return; } - string filename = "mutes"+client.AgentId.ToString(); - xfer.AddNewFile(filename, filedata); + string filename = "mutes" + client.AgentId.ToString(); + xfer.AddNewFile(filename, data); client.SendMuteListUpdate(filename); } private void OnUpdateMuteListEntry(IClientAPI client, UUID muteID, string muteName, int muteType, uint muteFlags) { - MuteData mute = new MuteData(); + if (!m_Enabled) + return; - mute.AgentID = client.AgentId; + UUID agentID = client.AgentId; + if(muteType == 1) // agent + { + if(agentID == muteID) + return; + if(m_SceneList[0].Permissions.IsAdministrator(muteID)) + { + OnMuteListRequest(client, 0); + return; + } + } + + MuteData mute = new MuteData(); + mute.AgentID = agentID; mute.MuteID = muteID; mute.MuteName = muteName; mute.MuteType = muteType; mute.MuteFlags = (int)muteFlags; mute.Stamp = Util.UnixTimeSinceEpoch(); - m_MuteTable.Store(mute); + m_service.UpdateMute(mute); } private void OnRemoveMuteListEntry(IClientAPI client, UUID muteID, string muteName) { - m_MuteTable.Delete(new string[] { "AgentID", - "MuteID", - "MuteName" }, - new string[] { client.AgentId.ToString(), - muteID.ToString(), - muteName }); + if (!m_Enabled) + return; + m_service.RemoveMute(client.AgentId, muteID, muteName); } } } diff --git a/OpenSim/Region/CoreModules/Avatar/InstantMessage/XMuteModule.cs b/OpenSim/Region/CoreModules/Avatar/InstantMessage/XMuteModule.cs index ac542c2602..b61e848c3a 100644 --- a/OpenSim/Region/CoreModules/Avatar/InstantMessage/XMuteModule.cs +++ b/OpenSim/Region/CoreModules/Avatar/InstantMessage/XMuteModule.cs @@ -32,15 +32,12 @@ using log4net; using Nini.Config; using OpenMetaverse; using OpenSim.Framework; -using OpenSim.Framework.Servers; -using OpenSim.Framework.Client; using OpenSim.Region.Framework.Interfaces; using OpenSim.Region.Framework.Scenes; using Mono.Addins; -using OpenSim.Data; using OpenSim.Data.MySQL; using MySql.Data.MySqlClient; -using System.Security.Cryptography; + namespace OpenSim.Region.CoreModules.Avatar.InstantMessage { diff --git a/OpenSim/Region/CoreModules/ServiceConnectorsOut/MuteList/LocalMuteListServiceConnector.cs b/OpenSim/Region/CoreModules/ServiceConnectorsOut/MuteList/LocalMuteListServiceConnector.cs new file mode 100644 index 0000000000..833d88396e --- /dev/null +++ b/OpenSim/Region/CoreModules/ServiceConnectorsOut/MuteList/LocalMuteListServiceConnector.cs @@ -0,0 +1,180 @@ +/* + * 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 log4net; +using Mono.Addins; +using Nini.Config; +using System; +using System.Collections.Generic; +using System.Reflection; +using OpenSim.Framework; +using OpenSim.Server.Base; +using OpenSim.Region.Framework.Interfaces; +using OpenSim.Region.Framework.Scenes; +using OpenSim.Services.Interfaces; +using OpenMetaverse; + +namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Land +{ + [Extension(Path = "/OpenSim/RegionModules", NodeName = "RegionModule", Id = "LocalMuteListServicesConnector")] + public class LocalMuteListServicesConnector : ISharedRegionModule, IMuteListService + { + private static readonly ILog m_log = + LogManager.GetLogger( + MethodBase.GetCurrentMethod().DeclaringType); + + private List m_Scenes = new List(); + protected IMuteListService m_service = null; + + private bool m_Enabled = false; + + #region ISharedRegionModule + + public Type ReplaceableInterface + { + get { return null; } + } + + public string Name + { + get { return "LocalMuteListServicesConnector"; } + } + + public void Initialise(IConfigSource source) + { + IConfig moduleConfig = source.Configs["Modules"]; + + if (moduleConfig == null) + return; + + string name = moduleConfig.GetString("MuteListService", ""); + if(name != Name) + return; + + IConfig userConfig = source.Configs["MuteListService"]; + if (userConfig == null) + { + m_log.Error("[MuteList LOCALCONNECTOR]: MuteListService missing from configuration"); + return; + } + + string serviceDll = userConfig.GetString("LocalServiceModule", + String.Empty); + + if (serviceDll == String.Empty) + { + m_log.Error("[MuteList LOCALCONNECTOR]: No LocalServiceModule named in section MuteListService"); + return; + } + + Object[] args = new Object[] { source }; + try + { + m_service = ServerUtils.LoadPlugin(serviceDll, args); + } + catch + { + m_log.Error("[MuteList LOCALCONNECTOR]: Failed to load mute service"); + return; + } + + if (m_service == null) + { + m_log.Error("[MuteList LOCALCONNECTOR]: Can't load MuteList service"); + return; + } + + m_Enabled = true; + m_log.Info("[MuteList LOCALCONNECTOR]: enabled"); + } + + public void Close() + { + } + + public void AddRegion(Scene scene) + { + if (!m_Enabled) + return; + + lock(m_Scenes) + { + m_Scenes.Add(scene); + scene.RegisterModuleInterface(this); + } + } + + public void RegionLoaded(Scene scene) + { + } + + public void PostInitialise() + { + } + + public void RemoveRegion(Scene scene) + { + if (!m_Enabled) + return; + + lock(m_Scenes) + { + if (m_Scenes.Contains(scene)) + { + m_Scenes.Remove(scene); + scene.UnregisterModuleInterface(this); + } + } + } + + #endregion ISharedRegionModule + + #region IMuteListService + public Byte[] MuteListRequest(UUID agentID, uint crc) + { + if (!m_Enabled) + return null; + return m_service.MuteListRequest(agentID, crc); + } + + public bool UpdateMute(MuteData mute) + { + if (!m_Enabled) + return false; + return m_service.UpdateMute(mute); + } + + public bool RemoveMute(UUID agentID, UUID muteID, string muteName) + { + if (!m_Enabled) + return false; + return m_service.RemoveMute(agentID, muteID, muteName); + } + + #endregion IMuteListService + } +} diff --git a/OpenSim/Services/Interfaces/IMuteLIstService.cs b/OpenSim/Services/Interfaces/IMuteLIstService.cs new file mode 100644 index 0000000000..9ffd47fd0c --- /dev/null +++ b/OpenSim/Services/Interfaces/IMuteLIstService.cs @@ -0,0 +1,41 @@ +/* + * 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 OpenSim.Framework; +using OpenMetaverse; + +namespace OpenSim.Services.Interfaces +{ + public interface IMuteListService + { + Byte[] MuteListRequest(UUID agent, uint crc); + bool UpdateMute(MuteData mute); + bool RemoveMute(UUID agentID, UUID muteID, string muteName); + } +} \ No newline at end of file diff --git a/OpenSim/Services/MuteListService/MuteListService.cs b/OpenSim/Services/MuteListService/MuteListService.cs new file mode 100644 index 0000000000..7e5ded1765 --- /dev/null +++ b/OpenSim/Services/MuteListService/MuteListService.cs @@ -0,0 +1,127 @@ +/* + * 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.Text; +using OpenMetaverse; +using log4net; +using Nini.Config; +using OpenSim.Services.Base; +using OpenSim.Services.Interfaces; +using OpenSim.Data; +using OpenSim.Framework; + +namespace OpenSim.Services.EstateService +{ + public class MuteListService : ServiceBase, IMuteListService + { +// private static readonly ILog m_log = +// LogManager.GetLogger( +// MethodBase.GetCurrentMethod().DeclaringType); + + protected IMuteListData m_database; + + public MuteListService(IConfigSource config) + : base(config) + { + string dllName = String.Empty; + string connString = String.Empty; + + // Try reading the [DatabaseService] section, if it exists + IConfig dbConfig = config.Configs["DatabaseService"]; + if (dbConfig != null) + { + dllName = dbConfig.GetString("StorageProvider", String.Empty); + connString = dbConfig.GetString("ConnectionString", String.Empty); + connString = dbConfig.GetString("MuteConnectionString", connString); + } + + // Try reading the [MuteListStore] section, if it exists + IConfig muteConfig = config.Configs["MuteListStore"]; + if (muteConfig != null) + { + dllName = muteConfig.GetString("StorageProvider", dllName); + connString = muteConfig.GetString("ConnectionString", connString); + } + + // We tried, but this doesn't exist. We can't proceed + if (dllName == String.Empty) + throw new Exception("No StorageProvider configured"); + + m_database = LoadPlugin(dllName, new Object[] { connString }); + if (m_database == null) + throw new Exception("Could not find a storage interface in the given module"); + } + + public Byte[] MuteListRequest(UUID agentID, uint crc) + { + if(m_database == null) + return null; + + MuteData[] data = m_database.Get(agentID); + if (data == null || data.Length == 0) + return new Byte[0]; + + StringBuilder sb = new StringBuilder(16384); + foreach (MuteData d in data) + sb.AppendFormat("{0} {1} {2}|{3}\n", + d.MuteType, + d.MuteID.ToString(), + d.MuteName, + d.MuteFlags); + + Byte[] filedata = Util.UTF8.GetBytes(sb.ToString()); + + uint dataCrc = Crc32.Compute(filedata); + + if (dataCrc == crc) + { + if(crc == 0) + return new Byte[0]; + + Byte[] ret = new Byte[1] {1}; + return ret; + } + + return filedata; + } + + public bool UpdateMute(MuteData mute) + { + if(m_database == null) + return false; + return m_database.Store(mute); + } + + public bool RemoveMute(UUID agentID, UUID muteID, string muteName) + { + if(m_database == null) + return false; + return m_database.Delete(agentID, muteID, muteName); + } + } +}