Main.cs 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220
  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. */
  28. using System;
  29. using System.IO;
  30. using System.Timers;
  31. using OpenSim.Framework;
  32. using OpenSim.Framework.Console;
  33. using OpenSim.Framework.Servers;
  34. namespace OpenSim.Grid.GridServer
  35. {
  36. /// <summary>
  37. /// </summary>
  38. public class OpenGrid_Main : BaseOpenSimServer, conscmd_callback
  39. {
  40. private static readonly log4net.ILog m_log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
  41. public GridConfig Cfg;
  42. public static OpenGrid_Main thegrid;
  43. public static bool setuponly;
  44. //public LLUUID highestUUID;
  45. // private SimProfileManager m_simProfileManager;
  46. private GridManager m_gridManager;
  47. [STAThread]
  48. public static void Main(string[] args)
  49. {
  50. log4net.Config.XmlConfigurator.Configure();
  51. if (args.Length > 0)
  52. {
  53. if (args[0] == "-setuponly") setuponly = true;
  54. }
  55. m_log.Info("Starting...\n");
  56. thegrid = new OpenGrid_Main();
  57. thegrid.Startup();
  58. thegrid.Work();
  59. }
  60. private void Work()
  61. {
  62. m_console.Notice("Enter help for a list of commands\n");
  63. while (true)
  64. {
  65. m_console.Prompt();
  66. }
  67. }
  68. private OpenGrid_Main()
  69. {
  70. m_console = new ConsoleBase("OpenGrid", this);
  71. MainConsole.Instance = m_console;
  72. }
  73. public void managercallback(string cmd)
  74. {
  75. switch (cmd)
  76. {
  77. case "shutdown":
  78. RunCmd("shutdown", new string[0]);
  79. break;
  80. }
  81. }
  82. public void Startup()
  83. {
  84. Cfg = new GridConfig("GRID SERVER", (Path.Combine(Util.configDir(), "GridServer_Config.xml")));
  85. //Yeah srsly, that's it.
  86. if (setuponly) Environment.Exit(0);
  87. m_log.Info("[GRID]: Connecting to Storage Server");
  88. m_gridManager = new GridManager();
  89. m_gridManager.AddPlugin(Cfg.DatabaseProvider); // Made of win
  90. m_gridManager.config = Cfg;
  91. m_log.Info("[GRID]: Starting HTTP process");
  92. BaseHttpServer httpServer = new BaseHttpServer(Cfg.HttpPort);
  93. //GridManagementAgent GridManagerAgent = new GridManagementAgent(httpServer, "gridserver", Cfg.SimSendKey, Cfg.SimRecvKey, managercallback);
  94. httpServer.AddXmlRPCHandler("simulator_login", m_gridManager.XmlRpcSimulatorLoginMethod);
  95. httpServer.AddXmlRPCHandler("simulator_data_request", m_gridManager.XmlRpcSimulatorDataRequestMethod);
  96. httpServer.AddXmlRPCHandler("map_block", m_gridManager.XmlRpcMapBlockMethod);
  97. // Message Server ---> Grid Server
  98. httpServer.AddXmlRPCHandler("register_messageserver", m_gridManager.XmlRPCRegisterMessageServer);
  99. httpServer.AddXmlRPCHandler("deregister_messageserver", m_gridManager.XmlRPCDeRegisterMessageServer);
  100. httpServer.AddStreamHandler(new RestStreamHandler("GET", "/sims/", m_gridManager.RestGetSimMethod));
  101. httpServer.AddStreamHandler(new RestStreamHandler("POST", "/sims/", m_gridManager.RestSetSimMethod));
  102. httpServer.AddStreamHandler(new RestStreamHandler("GET", "/regions/", m_gridManager.RestGetRegionMethod));
  103. httpServer.AddStreamHandler(new RestStreamHandler("POST", "/regions/", m_gridManager.RestSetRegionMethod));
  104. //httpServer.AddRestHandler("GET", "/sims/", m_gridManager.RestGetSimMethod);
  105. //httpServer.AddRestHandler("POST", "/sims/", m_gridManager.RestSetSimMethod);
  106. //httpServer.AddRestHandler("GET", "/regions/", m_gridManager.RestGetRegionMethod);
  107. //httpServer.AddRestHandler("POST", "/regions/", m_gridManager.RestSetRegionMethod);
  108. httpServer.Start();
  109. m_log.Info("[GRID]: Starting sim status checker");
  110. Timer simCheckTimer = new Timer(3600000*3); // 3 Hours between updates.
  111. simCheckTimer.Elapsed += new ElapsedEventHandler(CheckSims);
  112. simCheckTimer.Enabled = true;
  113. }
  114. public void CheckSims(object sender, ElapsedEventArgs e)
  115. {
  116. /*
  117. foreach (SimProfileBase sim in m_simProfileManager.SimProfiles.Values)
  118. {
  119. string SimResponse = String.Empty;
  120. try
  121. {
  122. WebRequest CheckSim = WebRequest.Create("http://" + sim.sim_ip + ":" + sim.sim_port.ToString() + "/checkstatus/");
  123. CheckSim.Method = "GET";
  124. CheckSim.ContentType = "text/plaintext";
  125. CheckSim.ContentLength = 0;
  126. StreamWriter stOut = new StreamWriter(CheckSim.GetRequestStream(), System.Text.Encoding.ASCII);
  127. stOut.Write(String.Empty);
  128. stOut.Close();
  129. StreamReader stIn = new StreamReader(CheckSim.GetResponse().GetResponseStream());
  130. SimResponse = stIn.ReadToEnd();
  131. stIn.Close();
  132. }
  133. catch
  134. {
  135. }
  136. if (SimResponse == "OK")
  137. {
  138. m_simProfileManager.SimProfiles[sim.UUID].online = true;
  139. }
  140. else
  141. {
  142. m_simProfileManager.SimProfiles[sim.UUID].online = false;
  143. }
  144. }
  145. */
  146. }
  147. public override void RunCmd(string cmd, string[] cmdparams)
  148. {
  149. base.RunCmd(cmd, cmdparams);
  150. switch (cmd)
  151. {
  152. case "help":
  153. m_console.Notice("shutdown - shutdown the grid (USE CAUTION!)");
  154. break;
  155. case "shutdown":
  156. m_console.Close();
  157. Environment.Exit(0);
  158. break;
  159. }
  160. }
  161. /*private void ConfigDB(IGenericConfig configData)
  162. {
  163. try
  164. {
  165. string attri = String.Empty;
  166. attri = configData.GetAttribute("DataBaseProvider");
  167. if (attri == String.Empty)
  168. {
  169. GridDll = "OpenSim.Framework.Data.DB4o.dll";
  170. configData.SetAttribute("DataBaseProvider", "OpenSim.Framework.Data.DB4o.dll");
  171. }
  172. else
  173. {
  174. GridDll = attri;
  175. }
  176. configData.Commit();
  177. }
  178. catch
  179. {
  180. }
  181. }*/
  182. }
  183. }