GridServerPlugin.cs 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  1. /*
  2. * Copyright (c) Contributors, http://opensimulator.org/
  3. * See CONTRIBUTORS.TXT for a full list of copyright holders.
  4. *
  5. * Redistribution and use in source and binary forms, with or without
  6. * modification, are permitted provided that the following conditions are met:
  7. * * Redistributions of source code must retain the above copyright
  8. * notice, this list of conditions and the following disclaimer.
  9. * * Redistributions in binary form must reproduce the above copyright
  10. * notice, this list of conditions and the following disclaimer in the
  11. * documentation and/or other materials provided with the distribution.
  12. * * Neither the name of the OpenSimulator Project nor the
  13. * names of its contributors may be used to endorse or promote products
  14. * derived from this software without specific prior written permission.
  15. *
  16. * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
  17. * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  18. * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  19. * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
  20. * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  21. * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  22. * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  23. * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  24. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  25. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  26. */
  27. using System;
  28. using System.Collections.Generic;
  29. using System.Reflection;
  30. using System.Text;
  31. using log4net;
  32. using OpenSim.Framework;
  33. using OpenSim.Framework.Console;
  34. using OpenSim.Grid.Framework;
  35. using OpenSim.Grid;
  36. namespace OpenSim.Grid.GridServer.Modules
  37. {
  38. public class GridServerPlugin : IGridPlugin
  39. {
  40. private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
  41. protected GridXmlRpcModule m_gridXmlRpcModule;
  42. protected GridMessagingModule m_gridMessageModule;
  43. protected GridRestModule m_gridRestModule;
  44. protected GridDBService m_gridDBService;
  45. protected string m_version;
  46. protected GridConfig m_config;
  47. protected IGridServiceCore m_core;
  48. protected CommandConsole m_console;
  49. #region IGridPlugin Members
  50. public void Initialise(GridServerBase gridServer)
  51. {
  52. m_core = gridServer;
  53. m_config = gridServer.Config;
  54. m_version = gridServer.Version;
  55. m_console = MainConsole.Instance;
  56. AddConsoleCommands();
  57. SetupGridServices();
  58. }
  59. #endregion
  60. #region IPlugin Members
  61. public string Version
  62. {
  63. get { return "0.0"; }
  64. }
  65. public string Name
  66. {
  67. get { return "GridServerPlugin"; }
  68. }
  69. public void Initialise()
  70. {
  71. }
  72. #endregion
  73. protected virtual void SetupGridServices()
  74. {
  75. // m_log.Info("[DATA]: Connecting to Storage Server");
  76. m_gridDBService = new GridDBService();
  77. m_gridDBService.AddPlugin(m_config.DatabaseProvider, m_config.DatabaseConnect);
  78. //Register the database access service so modules can fetch it
  79. // RegisterInterface<GridDBService>(m_gridDBService);
  80. m_gridMessageModule = new GridMessagingModule();
  81. m_gridMessageModule.Initialise(m_version, m_gridDBService, m_core, m_config);
  82. m_gridXmlRpcModule = new GridXmlRpcModule();
  83. m_gridXmlRpcModule.Initialise(m_version, m_gridDBService, m_core, m_config);
  84. m_gridRestModule = new GridRestModule();
  85. m_gridRestModule.Initialise(m_version, m_gridDBService, m_core, m_config);
  86. m_gridMessageModule.PostInitialise();
  87. m_gridXmlRpcModule.PostInitialise();
  88. m_gridRestModule.PostInitialise();
  89. }
  90. #region Console Command Handlers
  91. protected virtual void AddConsoleCommands()
  92. {
  93. m_console.Commands.AddCommand("gridserver", false,
  94. "enable registration",
  95. "enable registration",
  96. "Enable new regions to register", HandleRegistration);
  97. m_console.Commands.AddCommand("gridserver", false,
  98. "disable registration",
  99. "disable registration",
  100. "Disable registering new regions", HandleRegistration);
  101. m_console.Commands.AddCommand("gridserver", false, "show status",
  102. "show status",
  103. "Show registration status", HandleShowStatus);
  104. }
  105. private void HandleRegistration(string module, string[] cmd)
  106. {
  107. switch (cmd[0])
  108. {
  109. case "enable":
  110. m_config.AllowRegionRegistration = true;
  111. m_log.Info("Region registration enabled");
  112. break;
  113. case "disable":
  114. m_config.AllowRegionRegistration = false;
  115. m_log.Info("Region registration disabled");
  116. break;
  117. }
  118. }
  119. private void HandleShowStatus(string module, string[] cmd)
  120. {
  121. if (m_config.AllowRegionRegistration)
  122. {
  123. m_log.Info("Region registration enabled.");
  124. }
  125. else
  126. {
  127. m_log.Info("Region registration disabled.");
  128. }
  129. }
  130. #endregion
  131. #region IDisposable Members
  132. public void Dispose()
  133. {
  134. }
  135. #endregion
  136. }
  137. }