Main.cs 8.4 KB

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