GridServerBase.cs 7.2 KB

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