Main.cs 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221
  1. /*
  2. Copyright (c) OpenSim project, http://osgrid.org/
  3. * All rights reserved.
  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 <organization> 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 <copyright holder> ``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 <copyright holder> 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.IO;
  29. using System.Text;
  30. using System.Timers;
  31. using System.Net;
  32. using System.Reflection;
  33. using libsecondlife;
  34. using OpenSim.Framework;
  35. using OpenSim.Framework.Sims;
  36. using OpenSim.Framework.Console;
  37. using OpenSim.Framework.Interfaces;
  38. using OpenSim.Servers;
  39. namespace OpenGridServices.GridServer
  40. {
  41. /// <summary>
  42. /// </summary>
  43. public class OpenGrid_Main : BaseServer, conscmd_callback
  44. {
  45. private string ConfigDll = "OpenGrid.Config.GridConfigDb4o.dll";
  46. private string GridDll = "OpenGrid.Framework.Data.DB4o.dll";
  47. public GridConfig Cfg;
  48. public static OpenGrid_Main thegrid;
  49. //public LLUUID highestUUID;
  50. // private SimProfileManager m_simProfileManager;
  51. private GridManager m_gridManager;
  52. private ConsoleBase m_console;
  53. [STAThread]
  54. public static void Main(string[] args)
  55. {
  56. Console.WriteLine("Starting...\n");
  57. thegrid = new OpenGrid_Main();
  58. thegrid.Startup();
  59. thegrid.Work();
  60. }
  61. private void Work()
  62. {
  63. m_console.WriteLine("\nEnter help for a list of commands\n");
  64. while (true)
  65. {
  66. m_console.MainConsolePrompt();
  67. }
  68. }
  69. private OpenGrid_Main()
  70. {
  71. m_console = new ConsoleBase("opengrid-gridserver-console.log", "OpenGrid", this, false);
  72. MainConsole.Instance = m_console;
  73. }
  74. public void Startup()
  75. {
  76. m_console.WriteLine("Main.cs:Startup() - Loading configuration");
  77. Cfg = this.LoadConfigDll(this.ConfigDll);
  78. Cfg.InitConfig();
  79. m_console.WriteLine("Main.cs:Startup() - Connecting to Storage Server");
  80. m_gridManager = new GridManager();
  81. m_gridManager.AddPlugin(GridDll); // Made of win
  82. m_gridManager.defaultRecvKey = Cfg.SimRecvKey;
  83. m_console.WriteLine("Main.cs:Startup() - Starting HTTP process");
  84. BaseHttpServer httpServer = new BaseHttpServer(8001);
  85. httpServer.AddXmlRPCHandler("simulator_login", m_gridManager.XmlRpcLoginToSimulatorMethod);
  86. httpServer.AddRestHandler("GET", "/sims/", m_gridManager.RestGetSimMethod);
  87. httpServer.AddRestHandler("POST", "/sims/", m_gridManager.RestSetSimMethod);
  88. httpServer.AddRestHandler("GET", "/regions/", m_gridManager.RestGetRegionMethod);
  89. httpServer.AddRestHandler("POST", "/regions/", m_gridManager.RestSetRegionMethod);
  90. // lbsa71 : This code snippet taken from old http server.
  91. // I have no idea what this was supposed to do - looks like an infinite recursion to me.
  92. // case "regions":
  93. //// DIRTY HACK ALERT
  94. //Console.WriteLine("/regions/ accessed");
  95. //TheSim = OpenGrid_Main.thegrid._regionmanager.GetProfileByHandle((ulong)Convert.ToUInt64(rest_params[1]));
  96. //respstring = ParseREST("/regions/" + rest_params[1], requestBody, HTTPmethod);
  97. //break;
  98. // lbsa71 : I guess these were never used?
  99. //Listener.Prefixes.Add("http://+:8001/gods/");
  100. //Listener.Prefixes.Add("http://+:8001/highestuuid/");
  101. //Listener.Prefixes.Add("http://+:8001/uuidblocks/");
  102. httpServer.Start();
  103. m_console.WriteLine("Main.cs:Startup() - Starting sim status checker");
  104. Timer simCheckTimer = new Timer( 300000 ); // 5 minutes
  105. simCheckTimer.Elapsed += new ElapsedEventHandler(CheckSims);
  106. simCheckTimer.Enabled = true;
  107. }
  108. private GridConfig LoadConfigDll(string dllName)
  109. {
  110. Assembly pluginAssembly = Assembly.LoadFrom(dllName);
  111. GridConfig config = null;
  112. foreach (Type pluginType in pluginAssembly.GetTypes())
  113. {
  114. if (pluginType.IsPublic)
  115. {
  116. if (!pluginType.IsAbstract)
  117. {
  118. Type typeInterface = pluginType.GetInterface("IGridConfig", true);
  119. if (typeInterface != null)
  120. {
  121. IGridConfig plug = (IGridConfig)Activator.CreateInstance(pluginAssembly.GetType(pluginType.ToString()));
  122. config = plug.GetConfigObject();
  123. break;
  124. }
  125. typeInterface = null;
  126. }
  127. }
  128. }
  129. pluginAssembly = null;
  130. return config;
  131. }
  132. public void CheckSims(object sender, ElapsedEventArgs e)
  133. {
  134. /*
  135. foreach (SimProfileBase sim in m_simProfileManager.SimProfiles.Values)
  136. {
  137. string SimResponse = "";
  138. try
  139. {
  140. WebRequest CheckSim = WebRequest.Create("http://" + sim.sim_ip + ":" + sim.sim_port.ToString() + "/checkstatus/");
  141. CheckSim.Method = "GET";
  142. CheckSim.ContentType = "text/plaintext";
  143. CheckSim.ContentLength = 0;
  144. StreamWriter stOut = new StreamWriter(CheckSim.GetRequestStream(), System.Text.Encoding.ASCII);
  145. stOut.Write("");
  146. stOut.Close();
  147. StreamReader stIn = new StreamReader(CheckSim.GetResponse().GetResponseStream());
  148. SimResponse = stIn.ReadToEnd();
  149. stIn.Close();
  150. }
  151. catch
  152. {
  153. }
  154. if (SimResponse == "OK")
  155. {
  156. m_simProfileManager.SimProfiles[sim.UUID].online = true;
  157. }
  158. else
  159. {
  160. m_simProfileManager.SimProfiles[sim.UUID].online = false;
  161. }
  162. }
  163. */
  164. }
  165. public void RunCmd(string cmd, string[] cmdparams)
  166. {
  167. switch (cmd)
  168. {
  169. case "help":
  170. m_console.WriteLine("shutdown - shutdown the grid (USE CAUTION!)");
  171. break;
  172. case "shutdown":
  173. m_console.Close();
  174. Environment.Exit(0);
  175. break;
  176. }
  177. }
  178. public void Show(string ShowWhat)
  179. {
  180. }
  181. }
  182. }