Application.cs 5.3 KB

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