From 98f90f4eed231724f1105f19d9bc29cb23b3e5bf Mon Sep 17 00:00:00 2001 From: TomTheDragon Date: Sun, 5 Nov 2017 17:33:13 -0500 Subject: 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 +++--- .../World/LegacyMap/TexturedMapTileRenderer.cs | 43 +++++++++++++--------- 2 files changed, 32 insertions(+), 23 deletions(-) (limited to 'OpenSim/Region') diff --git a/OpenSim/Region/CoreModules/World/LegacyMap/ShadedMapTileRenderer.cs b/OpenSim/Region/CoreModules/World/LegacyMap/ShadedMapTileRenderer.cs index 708286c..0b37179 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 4b3ee18..c71f5c0 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); } } } -- cgit v1.1 From 873d42005fed47ba6e7c9bc2184e33f496ff9ce7 Mon Sep 17 00:00:00 2001 From: UbitUmarov Date: Tue, 14 Nov 2017 03:49:32 +0000 Subject: add AGENT_LIST_EXCLUDENPC bit mask option to llGetAgentList scope to exclude NPCs --- .../Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs | 10 ++++++++++ .../Region/ScriptEngine/Shared/Api/Runtime/LSL_Constants.cs | 1 + 2 files changed, 11 insertions(+) (limited to 'OpenSim/Region') diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs index fa32986..d36d9a0 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 e4c1ca0..2f249a7 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); -- cgit v1.1 From d35ab8c86ceb721302bfde309815107911fb1c02 Mon Sep 17 00:00:00 2001 From: Melanie Thielker Date: Tue, 14 Nov 2017 12:12:07 +0000 Subject: 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. --- .../Avatar/InstantMessage/XMuteModule.cs | 357 +++++++++++++++++++++ 1 file changed, 357 insertions(+) create mode 100644 OpenSim/Region/CoreModules/Avatar/InstantMessage/XMuteModule.cs (limited to 'OpenSim/Region') diff --git a/OpenSim/Region/CoreModules/Avatar/InstantMessage/XMuteModule.cs b/OpenSim/Region/CoreModules/Avatar/InstantMessage/XMuteModule.cs new file mode 100644 index 0000000..fb5239f --- /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) }; + } + } +} + -- cgit v1.1 From 2f13b68d4f4fd634eaee005bdf4c4a8e21c21c9a Mon Sep 17 00:00:00 2001 From: UbitUmarov Date: Thu, 16 Nov 2017 17:50:06 +0000 Subject: add missing part of mutes list protocol --- .../Region/ClientStack/Linden/UDP/LLClientView.cs | 35 ++++++++++++++++++++-- .../Server/IRCClientView.cs | 5 ++++ .../Region/OptionalModules/World/NPC/NPCAvatar.cs | 4 +++ 3 files changed, 42 insertions(+), 2 deletions(-) (limited to 'OpenSim/Region') diff --git a/OpenSim/Region/ClientStack/Linden/UDP/LLClientView.cs b/OpenSim/Region/ClientStack/Linden/UDP/LLClientView.cs index 4a76ffc..2ff6ced 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 d39c224..469dd67 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 151a202..bb23f2f 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) { } -- cgit v1.1 From 1e3cb827562f580aea60deab640f98078107e8a3 Mon Sep 17 00:00:00 2001 From: UbitUmarov Date: Fri, 17 Nov 2017 01:30:39 +0000 Subject: move some sharable items out of Xmute to Framework; add another test mutelistmodule, ignore it --- .../Avatar/InstantMessage/MuteListModuleTst.cs | 224 +++++++++++++++++++++ .../Avatar/InstantMessage/XMuteModule.cs | 125 +----------- 2 files changed, 229 insertions(+), 120 deletions(-) create mode 100644 OpenSim/Region/CoreModules/Avatar/InstantMessage/MuteListModuleTst.cs (limited to 'OpenSim/Region') diff --git a/OpenSim/Region/CoreModules/Avatar/InstantMessage/MuteListModuleTst.cs b/OpenSim/Region/CoreModules/Avatar/InstantMessage/MuteListModuleTst.cs new file mode 100644 index 0000000..7ade511 --- /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 fb5239f..ac542c2 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) }; - } - } } -- cgit v1.1 From a95e28616842f70bb64bf701c2534d75490e539e Mon Sep 17 00:00:00 2001 From: UbitUmarov Date: Mon, 11 Dec 2017 23:36:42 +0000 Subject: increase sample rate of WaitGetScenePresence() --- OpenSim/Region/Framework/Scenes/Scene.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'OpenSim/Region') diff --git a/OpenSim/Region/Framework/Scenes/Scene.cs b/OpenSim/Region/Framework/Scenes/Scene.cs index c06b3dd..c223aae 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( -- cgit v1.1 From d32debe6184b1d6575b97541b98c520a8c4360c1 Mon Sep 17 00:00:00 2001 From: UbitUmarov Date: Mon, 11 Dec 2017 23:58:27 +0000 Subject: commit what i did so far for core mutes module, befere i lose it --- .../Avatar/InstantMessage/MuteListModuleTst.cs | 135 ++++++++-------- .../Avatar/InstantMessage/XMuteModule.cs | 5 +- .../MuteList/LocalMuteListServiceConnector.cs | 180 +++++++++++++++++++++ 3 files changed, 251 insertions(+), 69 deletions(-) create mode 100644 OpenSim/Region/CoreModules/ServiceConnectorsOut/MuteList/LocalMuteListServiceConnector.cs (limited to 'OpenSim/Region') diff --git a/OpenSim/Region/CoreModules/Avatar/InstantMessage/MuteListModuleTst.cs b/OpenSim/Region/CoreModules/Avatar/InstantMessage/MuteListModuleTst.cs index 7ade511..6857f35 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); - - 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 (data.Length == 0) + { + client.SendEmpytMuteList(); + return; + } - 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; + + UUID agentID = client.AgentId; + if(muteType == 1) // agent + { + if(agentID == muteID) + return; + if(m_SceneList[0].Permissions.IsAdministrator(muteID)) + { + OnMuteListRequest(client, 0); + return; + } + } - mute.AgentID = client.AgentId; + 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 ac542c2..b61e848 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 0000000..833d883 --- /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 + } +} -- cgit v1.1