GridServerPlugin.cs 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  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. public void PostInitialise()
  60. {
  61. }
  62. #endregion
  63. #region IPlugin Members
  64. public string Version
  65. {
  66. get { return "0.0"; }
  67. }
  68. public string Name
  69. {
  70. get { return "GridServerPlugin"; }
  71. }
  72. public void Initialise()
  73. {
  74. }
  75. #endregion
  76. protected virtual void SetupGridServices()
  77. {
  78. // m_log.Info("[DATA]: Connecting to Storage Server");
  79. m_gridDBService = new GridDBService();
  80. m_gridDBService.AddPlugin(m_config.DatabaseProvider, m_config.DatabaseConnect);
  81. //Register the database access service so modules can fetch it
  82. // RegisterInterface<GridDBService>(m_gridDBService);
  83. m_gridMessageModule = new GridMessagingModule();
  84. m_gridMessageModule.Initialise(m_version, m_gridDBService, m_core, m_config);
  85. m_gridXmlRpcModule = new GridXmlRpcModule();
  86. m_gridXmlRpcModule.Initialise(m_version, m_gridDBService, m_core, m_config);
  87. m_gridRestModule = new GridRestModule();
  88. m_gridRestModule.Initialise(m_version, m_gridDBService, m_core, m_config);
  89. m_gridMessageModule.PostInitialise();
  90. m_gridXmlRpcModule.PostInitialise();
  91. m_gridRestModule.PostInitialise();
  92. }
  93. #region Console Command Handlers
  94. protected virtual void AddConsoleCommands()
  95. {
  96. m_console.Commands.AddCommand("gridserver", false,
  97. "enable registration",
  98. "enable registration",
  99. "Enable new regions to register", HandleRegistration);
  100. m_console.Commands.AddCommand("gridserver", false,
  101. "disable registration",
  102. "disable registration",
  103. "Disable registering new regions", HandleRegistration);
  104. m_console.Commands.AddCommand("gridserver", false, "show status",
  105. "show status",
  106. "Show registration status", HandleShowStatus);
  107. }
  108. private void HandleRegistration(string module, string[] cmd)
  109. {
  110. switch (cmd[0])
  111. {
  112. case "enable":
  113. m_config.AllowRegionRegistration = true;
  114. m_log.Info("Region registration enabled");
  115. break;
  116. case "disable":
  117. m_config.AllowRegionRegistration = false;
  118. m_log.Info("Region registration disabled");
  119. break;
  120. }
  121. }
  122. private void HandleShowStatus(string module, string[] cmd)
  123. {
  124. if (m_config.AllowRegionRegistration)
  125. {
  126. m_log.Info("Region registration enabled.");
  127. }
  128. else
  129. {
  130. m_log.Info("Region registration disabled.");
  131. }
  132. }
  133. #endregion
  134. #region IDisposable Members
  135. public void Dispose()
  136. {
  137. }
  138. #endregion
  139. }
  140. }