GridServerBase.cs 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203
  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 OpenSim 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.IO;
  30. using System.Reflection;
  31. using System.Timers;
  32. using log4net;
  33. using OpenSim.Framework;
  34. using OpenSim.Framework.Console;
  35. using OpenSim.Framework.Servers;
  36. namespace OpenSim.Grid.GridServer
  37. {
  38. /// <summary>
  39. /// </summary>
  40. public class GridServerBase : BaseOpenSimServer, conscmd_callback
  41. {
  42. private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
  43. protected GridConfig m_config;
  44. protected GridManager m_gridManager;
  45. protected List<IGridPlugin> m_plugins = new List<IGridPlugin>();
  46. public void Work()
  47. {
  48. m_console.Notice("Enter help for a list of commands\n");
  49. while (true)
  50. {
  51. m_console.Prompt();
  52. }
  53. }
  54. public GridServerBase()
  55. {
  56. m_console = new ConsoleBase("Grid", this);
  57. MainConsole.Instance = m_console;
  58. }
  59. public override void RunCmd(string cmd, string[] cmdparams)
  60. {
  61. base.RunCmd(cmd, cmdparams);
  62. switch (cmd)
  63. {
  64. case "disable-reg":
  65. m_config.AllowRegionRegistration = false;
  66. m_log.Info("Region registration disabled");
  67. break;
  68. case "enable-reg":
  69. m_config.AllowRegionRegistration = true;
  70. m_log.Info("Region registration enabled");
  71. break;
  72. }
  73. }
  74. public override void Show(string[] showParams)
  75. {
  76. base.Show(showParams);
  77. switch (showParams[0])
  78. {
  79. case "status":
  80. if (m_config.AllowRegionRegistration)
  81. {
  82. m_log.Info("Region registration enabled.");
  83. }
  84. else
  85. {
  86. m_log.Info("Region registration disabled.");
  87. }
  88. break;
  89. }
  90. }
  91. protected override void StartupSpecific()
  92. {
  93. m_config = new GridConfig("GRID SERVER", (Path.Combine(Util.configDir(), "GridServer_Config.xml")));
  94. SetupGridManager();
  95. m_log.Info("[GRID]: Starting HTTP process");
  96. m_httpServer = new BaseHttpServer(m_config.HttpPort);
  97. AddHttpHandlers();
  98. LoadPlugins();
  99. m_httpServer.Start();
  100. // m_log.Info("[GRID]: Starting sim status checker");
  101. //
  102. // Timer simCheckTimer = new Timer(3600000 * 3); // 3 Hours between updates.
  103. // simCheckTimer.Elapsed += new ElapsedEventHandler(CheckSims);
  104. // simCheckTimer.Enabled = true;
  105. }
  106. protected void AddHttpHandlers()
  107. {
  108. m_httpServer.AddXmlRPCHandler("simulator_login", m_gridManager.XmlRpcSimulatorLoginMethod);
  109. m_httpServer.AddXmlRPCHandler("simulator_data_request", m_gridManager.XmlRpcSimulatorDataRequestMethod);
  110. m_httpServer.AddXmlRPCHandler("simulator_after_region_moved", m_gridManager.XmlRpcDeleteRegionMethod);
  111. m_httpServer.AddXmlRPCHandler("map_block", m_gridManager.XmlRpcMapBlockMethod);
  112. m_httpServer.AddXmlRPCHandler("search_for_region_by_name", m_gridManager.XmlRpcSearchForRegionMethod);
  113. // Message Server ---> Grid Server
  114. m_httpServer.AddXmlRPCHandler("register_messageserver", m_gridManager.XmlRPCRegisterMessageServer);
  115. m_httpServer.AddXmlRPCHandler("deregister_messageserver", m_gridManager.XmlRPCDeRegisterMessageServer);
  116. m_httpServer.AddStreamHandler(new RestStreamHandler("GET", "/sims/", m_gridManager.RestGetSimMethod));
  117. m_httpServer.AddStreamHandler(new RestStreamHandler("POST", "/sims/", m_gridManager.RestSetSimMethod));
  118. m_httpServer.AddStreamHandler(new RestStreamHandler("GET", "/regions/", m_gridManager.RestGetRegionMethod));
  119. m_httpServer.AddStreamHandler(new RestStreamHandler("POST", "/regions/", m_gridManager.RestSetRegionMethod));
  120. }
  121. protected void LoadPlugins()
  122. {
  123. PluginLoader<IGridPlugin> loader =
  124. new PluginLoader<IGridPlugin> (new GridPluginInitialiser (this));
  125. loader.Load ("/OpenSim/GridServer");
  126. m_plugins = loader.Plugins;
  127. }
  128. protected virtual void SetupGridManager()
  129. {
  130. m_log.Info("[DATA]: Connecting to Storage Server");
  131. m_gridManager = new GridManager();
  132. m_gridManager.AddPlugin(m_config.DatabaseProvider, m_config.DatabaseConnect);
  133. m_gridManager.Config = m_config;
  134. }
  135. public void CheckSims(object sender, ElapsedEventArgs e)
  136. {
  137. /*
  138. foreach (SimProfileBase sim in m_simProfileManager.SimProfiles.Values)
  139. {
  140. string SimResponse = String.Empty;
  141. try
  142. {
  143. WebRequest CheckSim = WebRequest.Create("http://" + sim.sim_ip + ":" + sim.sim_port.ToString() + "/checkstatus/");
  144. CheckSim.Method = "GET";
  145. CheckSim.ContentType = "text/plaintext";
  146. CheckSim.ContentLength = 0;
  147. StreamWriter stOut = new StreamWriter(CheckSim.GetRequestStream(), System.Text.Encoding.ASCII);
  148. stOut.Write(String.Empty);
  149. stOut.Close();
  150. StreamReader stIn = new StreamReader(CheckSim.GetResponse().GetResponseStream());
  151. SimResponse = stIn.ReadToEnd();
  152. stIn.Close();
  153. }
  154. catch
  155. {
  156. }
  157. if (SimResponse == "OK")
  158. {
  159. m_simProfileManager.SimProfiles[sim.UUID].online = true;
  160. }
  161. else
  162. {
  163. m_simProfileManager.SimProfiles[sim.UUID].online = false;
  164. }
  165. }
  166. */
  167. }
  168. public override void ShutdownSpecific()
  169. {
  170. foreach (IGridPlugin plugin in m_plugins) plugin.Dispose();
  171. }
  172. }
  173. }