1
0

GridServerBase.cs 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  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 void managercallback(string cmd)
  60. {
  61. switch (cmd)
  62. {
  63. case "shutdown":
  64. RunCmd("shutdown", new string[0]);
  65. break;
  66. }
  67. }
  68. public override void Startup()
  69. {
  70. base.Startup();
  71. Config();
  72. SetupGridManager();
  73. m_log.Info("[GRID]: Starting HTTP process");
  74. m_httpServer = new BaseHttpServer(m_config.HttpPort);
  75. AddHttpHandlers();
  76. LoadPlugins();
  77. m_httpServer.Start();
  78. // m_log.Info("[GRID]: Starting sim status checker");
  79. //
  80. // Timer simCheckTimer = new Timer(3600000 * 3); // 3 Hours between updates.
  81. // simCheckTimer.Elapsed += new ElapsedEventHandler(CheckSims);
  82. // simCheckTimer.Enabled = true;
  83. }
  84. protected void AddHttpHandlers()
  85. {
  86. m_httpServer.AddXmlRPCHandler("simulator_login", m_gridManager.XmlRpcSimulatorLoginMethod);
  87. m_httpServer.AddXmlRPCHandler("simulator_data_request", m_gridManager.XmlRpcSimulatorDataRequestMethod);
  88. m_httpServer.AddXmlRPCHandler("simulator_after_region_moved", m_gridManager.XmlRpcDeleteRegionMethod);
  89. m_httpServer.AddXmlRPCHandler("map_block", m_gridManager.XmlRpcMapBlockMethod);
  90. // Message Server ---> Grid Server
  91. m_httpServer.AddXmlRPCHandler("register_messageserver", m_gridManager.XmlRPCRegisterMessageServer);
  92. m_httpServer.AddXmlRPCHandler("deregister_messageserver", m_gridManager.XmlRPCDeRegisterMessageServer);
  93. m_httpServer.AddStreamHandler(new RestStreamHandler("GET", "/sims/", m_gridManager.RestGetSimMethod));
  94. m_httpServer.AddStreamHandler(new RestStreamHandler("POST", "/sims/", m_gridManager.RestSetSimMethod));
  95. m_httpServer.AddStreamHandler(new RestStreamHandler("GET", "/regions/", m_gridManager.RestGetRegionMethod));
  96. m_httpServer.AddStreamHandler(new RestStreamHandler("POST", "/regions/", m_gridManager.RestSetRegionMethod));
  97. }
  98. protected void LoadPlugins()
  99. {
  100. PluginLoader<IGridPlugin> loader =
  101. new PluginLoader<IGridPlugin> (new GridPluginInitialiser (this));
  102. loader.Load ("/OpenSim/GridServer");
  103. m_plugins = loader.Plugins;
  104. }
  105. protected virtual void SetupGridManager()
  106. {
  107. m_log.Info("[DATA]: Connecting to Storage Server");
  108. m_gridManager = new GridManager();
  109. m_gridManager.AddPlugin(m_config.DatabaseProvider, m_config.DatabaseConnect);
  110. m_gridManager.Config = m_config;
  111. }
  112. public void Config()
  113. {
  114. m_config = new GridConfig("GRID SERVER", (Path.Combine(Util.configDir(), "GridServer_Config.xml")));
  115. }
  116. public void CheckSims(object sender, ElapsedEventArgs e)
  117. {
  118. /*
  119. foreach (SimProfileBase sim in m_simProfileManager.SimProfiles.Values)
  120. {
  121. string SimResponse = String.Empty;
  122. try
  123. {
  124. WebRequest CheckSim = WebRequest.Create("http://" + sim.sim_ip + ":" + sim.sim_port.ToString() + "/checkstatus/");
  125. CheckSim.Method = "GET";
  126. CheckSim.ContentType = "text/plaintext";
  127. CheckSim.ContentLength = 0;
  128. StreamWriter stOut = new StreamWriter(CheckSim.GetRequestStream(), System.Text.Encoding.ASCII);
  129. stOut.Write(String.Empty);
  130. stOut.Close();
  131. StreamReader stIn = new StreamReader(CheckSim.GetResponse().GetResponseStream());
  132. SimResponse = stIn.ReadToEnd();
  133. stIn.Close();
  134. }
  135. catch
  136. {
  137. }
  138. if (SimResponse == "OK")
  139. {
  140. m_simProfileManager.SimProfiles[sim.UUID].online = true;
  141. }
  142. else
  143. {
  144. m_simProfileManager.SimProfiles[sim.UUID].online = false;
  145. }
  146. }
  147. */
  148. }
  149. public override void Shutdown()
  150. {
  151. foreach (IGridPlugin plugin in m_plugins) plugin.Dispose();
  152. base.Shutdown();
  153. }
  154. }
  155. }