Application.cs 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  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.Net;
  29. using log4net.Config;
  30. using Nini.Config;
  31. using OpenSim.Framework;
  32. using OpenSim.Framework.Console;
  33. namespace OpenSim
  34. {
  35. public class Application
  36. {
  37. public static string iniFilePath = "";
  38. //could move our main function into OpenSimMain and kill this class
  39. [STAThread]
  40. public static void Main(string[] args)
  41. {
  42. // First line
  43. AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(CurrentDomain_UnhandledException);
  44. XmlConfigurator.Configure();
  45. Console.Write("Performing compatibility checks... ");
  46. string supported = String.Empty;
  47. if (Util.IsEnvironmentSupported(ref supported))
  48. {
  49. Console.WriteLine(" Environment is compatible.\n");
  50. }
  51. else
  52. {
  53. Console.WriteLine(" Environment is unsupported (" + supported + ")\n");
  54. }
  55. Culture.SetCurrentCulture();
  56. ArgvConfigSource configSource = new ArgvConfigSource(args);
  57. configSource.Alias.AddAlias("On", true);
  58. configSource.Alias.AddAlias("Off", false);
  59. configSource.Alias.AddAlias("True", true);
  60. configSource.Alias.AddAlias("False", false);
  61. configSource.AddSwitch("Startup", "background");
  62. configSource.AddSwitch("Startup", "inifile");
  63. configSource.AddSwitch("Startup", "gridmode");
  64. configSource.AddSwitch("Startup", "physics");
  65. configSource.AddSwitch("Startup", "useexecutepath");
  66. configSource.AddConfig("StandAlone");
  67. configSource.AddConfig("Network");
  68. bool background = configSource.Configs["Startup"].GetBoolean("background", false);
  69. if (background)
  70. {
  71. OpenSimBase sim = new OpenSimBackground(configSource);
  72. sim.Startup();
  73. }
  74. else
  75. {
  76. OpenSimBase sim = new OpenSim(configSource);
  77. sim.Startup();
  78. while (true)
  79. {
  80. MainConsole.Instance.Prompt();
  81. }
  82. }
  83. }
  84. private static bool _IsHandlingException = false; // Make sure we don't go recursive on ourself
  85. /// <summary>
  86. /// Global exception handler -- all unhandlet exceptions end up here :)
  87. /// </summary>
  88. /// <param name="sender"></param>
  89. /// <param name="e"></param>
  90. private static void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e)
  91. {
  92. if (_IsHandlingException)
  93. return;
  94. _IsHandlingException = true;
  95. // TODO: Add config option to allow users to turn off error reporting
  96. // TODO: Post error report (disabled for now)
  97. string msg = String.Empty;
  98. msg += "\r\n";
  99. msg += "APPLICATION EXCEPTION DETECTED: " + e.ToString() + "\r\n";
  100. msg += "\r\n";
  101. msg += "Exception: " + e.ExceptionObject.ToString() + "\r\n";
  102. Exception ex = (Exception)e.ExceptionObject;
  103. if (ex.InnerException != null)
  104. msg += "InnerException: " + ex.InnerException.ToString() + "\r\n";
  105. msg += "\r\n";
  106. msg += "Application is terminating: " + e.IsTerminating.ToString() + "\r\n";
  107. // Do we not always want to see exception messages?
  108. // if (e.IsTerminating)
  109. MainConsole.Instance.Error("[APPLICATION]: " + msg);
  110. // Try to post errormessage to an URL
  111. try
  112. {
  113. // DISABLED UNTIL WE CAN DISCUSS IF THIS IS MORALLY RIGHT OR NOT
  114. // Note! Needs reference to System.Web
  115. //System.Net.WebClient wc = new WebClient();
  116. //wc.DownloadData("http://www.opensimulator.org/ErrorReport.php?Msg=" +
  117. // System.Web.HttpUtility.UrlEncode(msg));
  118. //wc.Dispose();
  119. }
  120. catch (WebException)
  121. {
  122. // Ignore
  123. }
  124. _IsHandlingException=false;
  125. }
  126. }
  127. }