diff --git a/ChraftServer/ChraftServer.csproj b/ChraftServer/ChraftServer.csproj index ae1a9a25..d7d13f99 100644 --- a/ChraftServer/ChraftServer.csproj +++ b/ChraftServer/ChraftServer.csproj @@ -67,6 +67,9 @@ x86 + + .\Mono.Posix.dll + diff --git a/ChraftServer/MainService.cs b/ChraftServer/MainService.cs index 485c6c52..7a5fa030 100644 --- a/ChraftServer/MainService.cs +++ b/ChraftServer/MainService.cs @@ -80,7 +80,7 @@ protected override void OnStop() private void UnhandledException_Handler(object sender, UnhandledExceptionEventArgs e) { - Server.Logger.Log((Exception)e.ExceptionObject); + Server.Logger.Log(LogLevel.Debug, ((Exception)e.ExceptionObject).StackTrace); } public void Run(string[] args) diff --git a/ChraftServer/Mono.Posix.dll b/ChraftServer/Mono.Posix.dll new file mode 100644 index 00000000..c8096f93 Binary files /dev/null and b/ChraftServer/Mono.Posix.dll differ diff --git a/ChraftServer/Program.cs b/ChraftServer/Program.cs index d7625dbe..0d2aaa30 100644 --- a/ChraftServer/Program.cs +++ b/ChraftServer/Program.cs @@ -21,6 +21,8 @@ using System.IO; using System.Linq; using System.Reflection; +using System.Text; +using Mono.Unix.Native; namespace ChraftServer { @@ -31,8 +33,7 @@ internal static class Program /// private static void Main(string[] args) { - Environment.CurrentDirectory = Path.GetDirectoryName(typeof(Program).Assembly.Location); - + Environment.CurrentDirectory = Path.GetDirectoryName(MainService.IsRunningInMono ? GetExecutablePath() : typeof (Program).Assembly.Location); //Install command-line argument if (args.Any(a => a.Equals("-install", StringComparison.InvariantCultureIgnoreCase))) { @@ -91,6 +92,15 @@ private static void ShowUsage() Console.WriteLine("\tChraftServer -uninstall\r\n\t\tUninstall Chraft Windows Service"); Console.WriteLine("\tChraftServer\r\n\t\tRun Chraft from the console"); } + + public static string GetExecutablePath() + { + var builder = new StringBuilder(8192); + if (Syscall.readlink("/proc/self/exe", builder) >= 0) + return builder.ToString(); + else + return null; + } } }