示例#1
0
        public static void Main(string[] args)
        {
            //Ensures that all the files are downloaded in the Torch directory.
            Directory.SetCurrentDirectory(new FileInfo(typeof(Program).Assembly.Location).Directory.ToString());

            foreach (var file in Directory.GetFiles(Directory.GetCurrentDirectory(), "*.old"))
            {
                File.Delete(file);
            }

            AppDomain.CurrentDomain.AssemblyResolve    += CurrentDomain_AssemblyResolve;
            AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException;

            if (!Environment.UserInteractive)
            {
                using (var service = new TorchService())
                {
                    ServiceBase.Run(service);
                }
                return;
            }

            //CommandLine reflection triggers assembly loading, so DS update must be completely separated.
            if (!args.Contains("-noupdate"))
            {
                if (!Directory.Exists("DedicatedServer64"))
                {
                    _log.Error("Game libraries not found. Press the Enter key to install the dedicated server.");
                    Console.ReadLine();
                }
                RunSteamCmd();
            }

            InitConfig();

            if (!_config.Parse(args))
            {
                return;
            }

            if (!string.IsNullOrEmpty(_config.WaitForPID))
            {
                try
                {
                    var pid      = int.Parse(_config.WaitForPID);
                    var waitProc = Process.GetProcessById(pid);
                    _log.Warn($"Waiting for process {pid} to exit.");
                    waitProc.WaitForExit();
                    _log.Info("Continuing in 5 seconds.");
                    Thread.Sleep(5000);
                }
                catch
                {
                    // ignored
                }
            }

            _restartOnCrash = _config.RestartOnCrash;
            RunServer(_config);
        }
示例#2
0
        public bool Initialize(string[] args)
        {
            if (_init)
            {
                return(false);
            }

#if !DEBUG
            AppDomain.CurrentDomain.UnhandledException += HandleException;
#endif

            // This is what happens when Keen is bad and puts extensions into the System namespace.
            if (!Enumerable.Contains(args, "-noupdate"))
            {
                RunSteamCmd();
            }

            var basePath  = new FileInfo(typeof(Program).Assembly.Location).Directory.ToString();
            var apiSource = Path.Combine(basePath, "DedicatedServer64", "steam_api64.dll");
            var apiTarget = Path.Combine(basePath, "steam_api64.dll");

            if (!File.Exists(apiTarget))
            {
                File.Copy(apiSource, apiTarget);
            }

            _config = InitConfig();
            if (!_config.Parse(args))
            {
                return(false);
            }

            if (!string.IsNullOrEmpty(_config.WaitForPID))
            {
                try
                {
                    var pid      = int.Parse(_config.WaitForPID);
                    var waitProc = Process.GetProcessById(pid);
                    Log.Info("Continuing in 5 seconds.");
                    Log.Warn($"Waiting for process {pid} to close");
                    while (!waitProc.HasExited)
                    {
                        Console.Write(".");
                        Thread.Sleep(1000);
                    }
                }
                catch
                {
                    // ignored
                }
            }

            _init = true;
            return(true);
        }
示例#3
0
        public bool Initialize(string[] args)
        {
            if (_init)
            {
                return(false);
            }

#if !DEBUG
            AppDomain.CurrentDomain.UnhandledException += HandleException;
#endif

            if (!args.Contains("-noupdate"))
            {
                RunSteamCmd();
            }

            _config = InitConfig();
            if (!_config.Parse(args))
            {
                return(false);
            }

            if (!string.IsNullOrEmpty(_config.WaitForPID))
            {
                try
                {
                    var pid      = int.Parse(_config.WaitForPID);
                    var waitProc = Process.GetProcessById(pid);
                    Log.Info("Continuing in 5 seconds.");
                    Log.Warn($"Waiting for process {pid} to close");
                    while (!waitProc.HasExited)
                    {
                        Console.Write(".");
                        Thread.Sleep(1000);
                    }
                }
                catch
                {
                    // ignored
                }
            }

            _init = true;
            return(true);
        }
示例#4
0
文件: Initializer.cs 项目: susu/Torch
        public bool Initialize(string[] args)
        {
            if (_init)
            {
                return(false);
            }

            AppDomain.CurrentDomain.UnhandledException += HandleException;

            if (!args.Contains("-noupdate"))
            {
                RunSteamCmd();
            }

            _resolver = new TorchAssemblyResolver(Path.Combine(_basePath, "DedicatedServer64"));
            _config   = InitConfig();
            if (!_config.Parse(args))
            {
                return(false);
            }

            if (!string.IsNullOrEmpty(_config.WaitForPID))
            {
                try
                {
                    var pid      = int.Parse(_config.WaitForPID);
                    var waitProc = Process.GetProcessById(pid);
                    Log.Info("Continuing in 5 seconds.");
                    Thread.Sleep(5000);
                    if (!waitProc.HasExited)
                    {
                        Log.Warn($"Killing old process {pid}.");
                        waitProc.Kill();
                    }
                }
                catch
                {
                    // ignored
                }
            }

            _init = true;
            return(true);
        }
示例#5
0
        public bool Initialize(string[] args)
        {
            if (_init)
            {
                return(false);
            }

#if !DEBUG
            AppDomain.CurrentDomain.UnhandledException += HandleException;
#endif

#if DEBUG
            //enables logging debug messages when built in debug mode. Amazing.
            LogManager.Configuration.AddRule(LogLevel.Debug, LogLevel.Debug, "main");
            LogManager.Configuration.AddRule(LogLevel.Debug, LogLevel.Debug, "console");
            LogManager.Configuration.AddRule(LogLevel.Debug, LogLevel.Debug, "wpf");
            LogManager.ReconfigExistingLoggers();
            Log.Debug("Debug logging enabled.");
#endif

            // This is what happens when Keen is bad and puts extensions into the System namespace.
            if (!Enumerable.Contains(args, "-noupdate"))
            {
                RunSteamCmd();
            }

            var basePath  = new FileInfo(typeof(Program).Assembly.Location).Directory.ToString();
            var apiSource = Path.Combine(basePath, "DedicatedServer64", "steam_api64.dll");
            var apiTarget = Path.Combine(basePath, "steam_api64.dll");

            if (!File.Exists(apiTarget))
            {
                File.Copy(apiSource, apiTarget);
            }
            else if (File.GetLastWriteTime(apiTarget) < File.GetLastWriteTime(apiSource))
            {
                File.Delete(apiTarget);
                File.Copy(apiSource, apiTarget);
            }

            var havokSource = Path.Combine(basePath, "DedicatedServer64", "Havok.dll");
            var havokTarget = Path.Combine(basePath, "Havok.dll");

            if (!File.Exists(havokTarget))
            {
                File.Copy(havokSource, havokTarget);
            }
            else if (File.GetLastWriteTime(havokTarget) < File.GetLastWriteTime(havokSource))
            {
                File.Delete(havokTarget);
                File.Copy(havokSource, havokTarget);
            }

            _config = InitConfig();
            if (!_config.Parse(args))
            {
                return(false);
            }

            if (!string.IsNullOrEmpty(_config.WaitForPID))
            {
                try
                {
                    var pid      = int.Parse(_config.WaitForPID);
                    var waitProc = Process.GetProcessById(pid);
                    Log.Info("Continuing in 5 seconds.");
                    Log.Warn($"Waiting for process {pid} to close");
                    while (!waitProc.HasExited)
                    {
                        Console.Write(".");
                        Thread.Sleep(1000);
                    }
                }
                catch
                {
                    // ignored
                }
            }

            _init = true;
            return(true);
        }