1
0

Application.cs 5.5 KB

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