From 9590e671e6efc5c8da74f22b7038f1ce10501620 Mon Sep 17 00:00:00 2001 From: Dr Scofield Date: Fri, 30 May 2008 12:29:30 +0000 Subject: [PATCH] while investigating why IRCBridgeModule.Close() was having no effect, i noticed that Scene.Close() will only call Close on non-shared region modules. i've now added code to SceneManager.Close() to collect all shared region module from each scene before calling Scene.Close() on it and then, once, all Scenes are closed, go through the list of collected shared region modules and close them as well. SceneManager.Close() is only called when we initiate a shutdown --- i've verified that a Scene restart does not trigger the shutdown of shared modules :-) also, this adds a couple of bug fixes to the IRCBridgeModule (which after all didn't take kindly to being closed) as well as a check to InterregionModule's Close() call. finally, this fixes the RestPlugin's XmlWriter so that it no longer includes the "xsd=..." and "xsi=..." junk. --- .../Rest/Regions/RestRegionPlugin.cs | 9 +++-- OpenSim/ApplicationPlugins/Rest/RestPlugin.cs | 8 ++++ .../Modules/Avatar/Chat/IRCBridgeModule.cs | 39 ++++++++++++------- .../Grid/Interregion/InterregionModule.cs | 3 +- OpenSim/Region/Environment/Scenes/Scene.cs | 6 ++- .../Region/Environment/Scenes/SceneManager.cs | 18 +++++++++ 6 files changed, 65 insertions(+), 18 deletions(-) diff --git a/OpenSim/ApplicationPlugins/Rest/Regions/RestRegionPlugin.cs b/OpenSim/ApplicationPlugins/Rest/Regions/RestRegionPlugin.cs index fa5f11707b..aeb91a9682 100644 --- a/OpenSim/ApplicationPlugins/Rest/Regions/RestRegionPlugin.cs +++ b/OpenSim/ApplicationPlugins/Rest/Regions/RestRegionPlugin.cs @@ -57,6 +57,12 @@ namespace OpenSim.ApplicationPlugins.Rest.Regions public partial class RestRegionPlugin : RestPlugin { private static XmlSerializerNamespaces _xmlNs; + + static RestRegionPlugin() + { + _xmlNs = new XmlSerializerNamespaces(); + _xmlNs.Add(String.Empty, String.Empty); + } #region overriding properties public override string Name @@ -91,9 +97,6 @@ namespace OpenSim.ApplicationPlugins.Rest.Regions } m_log.InfoFormat("{0} REST region plugin enabled", MsgID); - _xmlNs = new XmlSerializerNamespaces(); - _xmlNs.Add(String.Empty, String.Empty); - // add REST method handlers AddRestStreamHandler("GET", "/regions/", GetHandler); AddRestStreamHandler("POST", "/regions/", PostHandler); diff --git a/OpenSim/ApplicationPlugins/Rest/RestPlugin.cs b/OpenSim/ApplicationPlugins/Rest/RestPlugin.cs index 8373ea2708..ffabb2a5ec 100644 --- a/OpenSim/ApplicationPlugins/Rest/RestPlugin.cs +++ b/OpenSim/ApplicationPlugins/Rest/RestPlugin.cs @@ -135,6 +135,14 @@ namespace OpenSim.ApplicationPlugins.Rest get { return _prefix; } } + /// + /// Access to GOD password string + /// + protected string GodKey + { + get { return _godkey; } + } + /// /// Configuration of the plugin /// diff --git a/OpenSim/Region/Environment/Modules/Avatar/Chat/IRCBridgeModule.cs b/OpenSim/Region/Environment/Modules/Avatar/Chat/IRCBridgeModule.cs index 85262f5790..befa89f875 100644 --- a/OpenSim/Region/Environment/Modules/Avatar/Chat/IRCBridgeModule.cs +++ b/OpenSim/Region/Environment/Modules/Avatar/Chat/IRCBridgeModule.cs @@ -151,6 +151,7 @@ namespace OpenSim.Region.Environment.Modules.Avatar.Chat public void Close() { m_irc.Close(); + m_log.Info("[IRC] closed connection to IRC server"); } public string Name @@ -324,9 +325,9 @@ namespace OpenSim.Region.Environment.Modules.Avatar.Chat // if IRC is enabled then just keep trying using a monitor thread public void IRCConnectRun() { - while (true) + while (m_irc.Enabled) { - if ((m_irc.Enabled) && (!m_irc.Connected)) + if (!m_irc.Connected) { m_irc.Connect(m_scenes); } @@ -538,7 +539,7 @@ namespace OpenSim.Region.Environment.Modules.Avatar.Chat m_log.Info("[IRC]: ExtractMsg: " + input); Dictionary result = null; //string regex = @":(?\w*)!~(?\S*) PRIVMSG (?\S+) :(?.*)"; - string regex = @":(?\w*)!(?\S*) PRIVMSG (?\S+) :(?.*)"; + string regex = @":(?[\w-]*)!(?\S*) PRIVMSG (?\S+) :(?.*)"; Regex RE = new Regex(regex, RegexOptions.Multiline); MatchCollection matches = RE.Matches(input); @@ -566,7 +567,7 @@ namespace OpenSim.Region.Environment.Modules.Avatar.Chat { // IRC keep alive thread // send PING ever 15 seconds - while (true) + while (m_enabled) { try { @@ -579,8 +580,11 @@ namespace OpenSim.Region.Environment.Modules.Avatar.Chat } catch (IOException) { - m_log.Error("[IRC]: Disconnected from IRC server.(PingRun)"); - Reconnect(); + if (m_enabled) + { + m_log.Error("[IRC]: Disconnected from IRC server.(PingRun)"); + Reconnect(); + } } catch (Exception ex) { @@ -593,7 +597,7 @@ namespace OpenSim.Region.Environment.Modules.Avatar.Chat { string inputLine; LLVector3 pos = new LLVector3(128, 128, 20); - while (true) + while (m_enabled) { try { @@ -637,8 +641,11 @@ namespace OpenSim.Region.Environment.Modules.Avatar.Chat } catch (IOException) { - m_log.Error("[IRC]: ListenerRun IOException. Disconnected from IRC server ??? (ListenerRun)"); - Reconnect(); + if (m_enabled) + { + m_log.Error("[IRC]: ListenerRun IOException. Disconnected from IRC server ??? (ListenerRun)"); + Reconnect(); + } } catch (Exception ex) { @@ -838,13 +845,19 @@ namespace OpenSim.Region.Environment.Modules.Avatar.Chat public void Close() { - m_connected = false; - m_writer.WriteLine(String.Format("QUIT :{0} to {1} wormhole with {2} closing", m_nick, m_channel, m_server)); + m_writer.WriteLine(String.Format("QUIT :{0} to {1} wormhole to {2} closing", + m_nick, m_channel, m_server)); m_writer.Flush(); - listener.Abort(); - pingSender.Abort(); + + m_connected = false; + m_enabled = false; + + // listener.Abort(); + // pingSender.Abort(); + m_writer.Close(); m_reader.Close(); + m_tcp.Close(); } } diff --git a/OpenSim/Region/Environment/Modules/Grid/Interregion/InterregionModule.cs b/OpenSim/Region/Environment/Modules/Grid/Interregion/InterregionModule.cs index 89ee61aa4d..40d07de419 100644 --- a/OpenSim/Region/Environment/Modules/Grid/Interregion/InterregionModule.cs +++ b/OpenSim/Region/Environment/Modules/Grid/Interregion/InterregionModule.cs @@ -169,7 +169,8 @@ namespace OpenSim.Region.Environment.Modules.Grid.Interregion public void Close() { - ChannelServices.UnregisterChannel(m_tcpChannel); + if (null != m_tcpChannel) + ChannelServices.UnregisterChannel(m_tcpChannel); } public string Name diff --git a/OpenSim/Region/Environment/Scenes/Scene.cs b/OpenSim/Region/Environment/Scenes/Scene.cs index 2b667c9de5..c1e8602298 100644 --- a/OpenSim/Region/Environment/Scenes/Scene.cs +++ b/OpenSim/Region/Environment/Scenes/Scene.cs @@ -103,7 +103,11 @@ namespace OpenSim.Region.Environment.Scenes protected BaseHttpServer m_httpListener; - protected Dictionary Modules = new Dictionary(); + protected Dictionary m_modules = new Dictionary(); + public Dictionary Modules + { + get { return m_modules; } + } protected Dictionary ModuleInterfaces = new Dictionary(); protected Dictionary ModuleAPIMethods = new Dictionary(); protected Dictionary m_moduleCommanders = new Dictionary(); diff --git a/OpenSim/Region/Environment/Scenes/SceneManager.cs b/OpenSim/Region/Environment/Scenes/SceneManager.cs index c596f6e855..dc9ac3799b 100644 --- a/OpenSim/Region/Environment/Scenes/SceneManager.cs +++ b/OpenSim/Region/Environment/Scenes/SceneManager.cs @@ -32,6 +32,7 @@ using System.Reflection; using libsecondlife; using log4net; using OpenSim.Framework; +using OpenSim.Region.Environment.Interfaces; namespace OpenSim.Region.Environment.Scenes { @@ -78,10 +79,27 @@ namespace OpenSim.Region.Environment.Scenes public void Close() { + // collect known shared modules in sharedModules + Dictionary sharedModules = new Dictionary(); for (int i = 0; i < m_localScenes.Count; i++) { + // extract known shared modules from scene + foreach(string k in m_localScenes[i].Modules.Keys) + { + if (m_localScenes[i].Modules[k].IsSharedModule && + !sharedModules.ContainsKey(k)) + sharedModules[k] = m_localScenes[i].Modules[k]; + } + // close scene/region m_localScenes[i].Close(); } + + // all regions/scenes are now closed, we can now safely + // close all shared modules + foreach(IRegionModule mod in sharedModules.Values) + { + mod.Close(); + } } public void Close(Scene cscene)