From 7e136c67fd89f6c559420093acdee867967773bb Mon Sep 17 00:00:00 2001 From: Melanie Date: Wed, 21 Aug 2019 21:15:58 +0100 Subject: [PATCH] Call SetServer on consoles reflectively to avoid having type checks in places where it tends to be forgotten to update them. --- OpenSim/Framework/Console/RemoteConsole.cs | 2 ++ OpenSim/Framework/ICommandConsole.cs | 0 OpenSim/Framework/IConsole.cs | 2 +- OpenSim/Region/Application/OpenSim.cs | 13 ++++++------- OpenSim/Server/Base/HttpServerBase.cs | 8 +++++--- 5 files changed, 14 insertions(+), 11 deletions(-) mode change 100644 => 100755 OpenSim/Framework/ICommandConsole.cs mode change 100644 => 100755 OpenSim/Server/Base/HttpServerBase.cs diff --git a/OpenSim/Framework/Console/RemoteConsole.cs b/OpenSim/Framework/Console/RemoteConsole.cs index 16b46363b6..11006a98fe 100755 --- a/OpenSim/Framework/Console/RemoteConsole.cs +++ b/OpenSim/Framework/Console/RemoteConsole.cs @@ -46,6 +46,8 @@ namespace OpenSim.Framework.Console // public class RemoteConsole : CommandConsole { + private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); + // Connection specific data, indexed by a session ID // we create when a client connects. protected class ConsoleConnection diff --git a/OpenSim/Framework/ICommandConsole.cs b/OpenSim/Framework/ICommandConsole.cs old mode 100644 new mode 100755 diff --git a/OpenSim/Framework/IConsole.cs b/OpenSim/Framework/IConsole.cs index 963e07f7a9..22f62df3dc 100755 --- a/OpenSim/Framework/IConsole.cs +++ b/OpenSim/Framework/IConsole.cs @@ -38,7 +38,7 @@ namespace OpenSim.Framework string Prompt(string p, string def = null, List excludedCharacters = null, bool echo = true); - // Displays a command prompt and returns a default value, user may only enter 1 of 2 options + // Displays a prompt and returns a default value, user may only enter 1 of 2 options string Prompt(string prompt, string defaultresponse, List options); } } \ No newline at end of file diff --git a/OpenSim/Region/Application/OpenSim.cs b/OpenSim/Region/Application/OpenSim.cs index 6a56a3660a..5cfca6cd1e 100755 --- a/OpenSim/Region/Application/OpenSim.cs +++ b/OpenSim/Region/Application/OpenSim.cs @@ -49,6 +49,7 @@ using OpenSim.Framework.Monitoring; using OpenSim.Region.Framework.Interfaces; using OpenSim.Region.Framework.Scenes; using OpenSim.Services.Interfaces; +using OpenSim.Framework.Servers.HttpServer; namespace OpenSim { @@ -228,16 +229,14 @@ namespace OpenSim m_log.InfoFormat("[OPENSIM] Enabling remote managed stats fetch. URL = {0}", urlBase); } - if (m_console is RemoteConsole) + MethodInfo mi = m_console.GetType().GetMethod("SetServer", BindingFlags.Public | BindingFlags.Instance, null, new Type[] { typeof(BaseHttpServer) }, null); + + if (mi != null) { if (m_consolePort == 0) - { - ((RemoteConsole)m_console).SetServer(m_httpServer); - } + mi.Invoke(m_console, new object[] { m_httpServer }); else - { - ((RemoteConsole)m_console).SetServer(MainServer.GetHttpServer(m_consolePort)); - } + mi.Invoke(m_console, new object[] { MainServer.GetHttpServer(m_consolePort) }); } // Hook up to the watchdog timer diff --git a/OpenSim/Server/Base/HttpServerBase.cs b/OpenSim/Server/Base/HttpServerBase.cs old mode 100644 new mode 100755 index 3357250f0a..5e76156ee8 --- a/OpenSim/Server/Base/HttpServerBase.cs +++ b/OpenSim/Server/Base/HttpServerBase.cs @@ -149,12 +149,14 @@ namespace OpenSim.Server.Base MainServer.RegisterHttpConsoleCommands(MainConsole.Instance); - if (MainConsole.Instance is RemoteConsole) + MethodInfo mi = m_console.GetType().GetMethod("SetServer", BindingFlags.Public | BindingFlags.Instance, null, new Type[] { typeof(BaseHttpServer) }, null); + + if (mi != null) { if (m_consolePort == 0) - ((RemoteConsole)MainConsole.Instance).SetServer(MainServer.Instance); + mi.Invoke(MainConsole.Instance, new object[] { MainServer.Instance }); else - ((RemoteConsole)MainConsole.Instance).SetServer(MainServer.GetHttpServer(m_consolePort)); + mi.Invoke(MainConsole.Instance, new object[] { MainServer.GetHttpServer(m_consolePort) }); } } }