コード例 #1
0
ファイル: TorchUI.xaml.cs プロジェクト: DrWathson/Torch
        public TorchUI(TorchServer server)
        {
            _config = (TorchConfig)server.Config;
            _server = server;
            InitializeComponent();
            _startTime         = DateTime.Now;
            _uiUpdate.Elapsed += UiUpdate_Elapsed;

            Left   = _config.WindowPosition.X;
            Top    = _config.WindowPosition.Y;
            Width  = _config.WindowSize.X;
            Height = _config.WindowSize.Y;

            Chat.BindServer(server);
            PlayerList.BindServer(server);
            Plugins.BindServer(server);
        }
コード例 #2
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);
        }
コード例 #3
0
        public TorchUI(TorchServer server)
        {
            _config = (TorchConfig)server.Config;
            _server = server;
            InitializeComponent();

            Left   = _config.WindowPosition.X;
            Top    = _config.WindowPosition.Y;
            Width  = _config.WindowSize.X;
            Height = _config.WindowSize.Y;

            //TODO: data binding for whole server
            DataContext = server;
            Chat.BindServer(server);
            PlayerList.BindServer(server);
            Plugins.BindServer(server);
            LoadConfig((TorchConfig)server.Config);
        }
コード例 #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 static void InitConfig()
        {
            var configName = "Torch.cfg";
            var configPath = Path.Combine(Directory.GetCurrentDirectory(), configName);

            if (File.Exists(configName))
            {
                _log.Info($"Loading config {configPath}");
                _config = TorchConfig.LoadFrom(configPath);
            }
            else
            {
                _log.Info($"Generating default config at {configPath}");
                _config = new TorchConfig {
                    InstancePath = Path.GetFullPath("Instance")
                };
                _config.Save(configPath);
            }
        }
コード例 #6
0
ファイル: TorchServer.cs プロジェクト: Lambertto10101/Torch
        /// <inheritdoc />
        public TorchServer(TorchConfig config = null)
        {
            DedicatedInstance = new InstanceManager(this);
            AddManager(DedicatedInstance);
            AddManager(new EntityControlManager(this));
            AddManager(new RemoteAPIManager(this));
            Config = config ?? new TorchConfig();

            var sessionManager = Managers.GetManager <ITorchSessionManager>();

            sessionManager.AddFactory(x => new MultiplayerManagerDedicated(this));

            // Needs to be done at some point after MyVRageWindows.Init
            // where the debug listeners are registered
            if (!((TorchConfig)Config).EnableAsserts)
            {
                MyDebug.Listeners.Clear();
            }
        }
コード例 #7
0
        private TorchConfig InitConfig()
        {
            var configName = "Torch.cfg";
            var configPath = Path.Combine(Directory.GetCurrentDirectory(), configName);

            if (File.Exists(configName))
            {
                Log.Info($"Loading config {configPath}");
                return(TorchConfig.LoadFrom(configPath));
            }
            else
            {
                Log.Info($"Generating default config at {configPath}");
                var config = new TorchConfig {
                    InstancePath = Path.GetFullPath("Instance")
                };
                config.Save(configPath);
                return(config);
            }
        }
コード例 #8
0
        /// <inheritdoc />
        protected override void OnStart(string[] args)
        {
            base.OnStart(args);

            string configName = args.Length > 0 ? args[0] : "Torch.cfg";
            var    options    = new TorchConfig("Torch");

            if (File.Exists(configName))
            {
                options = TorchConfig.LoadFrom(configName);
            }
            else
            {
                options.Save(configName);
            }

            _server = new TorchServer(options);
            _server.Init();
            _server.RunArgs = args;
            Task.Run(() => _server.Start());
        }
コード例 #9
0
ファイル: TorchUI.xaml.cs プロジェクト: raydleemsc/Torch
        public TorchUI(TorchServer server)
        {
            _config = (TorchConfig)server.Config;
            _server = server;
            //TODO: data binding for whole server
            DataContext = server;
            InitializeComponent();

            AttachConsole();

            Left   = _config.WindowPosition.X;
            Top    = _config.WindowPosition.Y;
            Width  = _config.WindowSize.X;
            Height = _config.WindowSize.Y;

            Chat.BindServer(server);
            PlayerList.BindServer(server);
            Plugins.BindServer(server);
            LoadConfig((TorchConfig)server.Config);

            Themes.uiSource = this;
            Themes.SetConfig(_config);
            Title = $"{_config.InstanceName} - Torch {server.TorchVersion}, SE {server.GameVersion}";
        }
コード例 #10
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);
        }
コード例 #11
0
        public static void RunServer(TorchConfig config)
        {
            /*
             * if (!parser.ParseArguments(args, config))
             * {
             *  _log.Error($"Parsing arguments failed: {string.Join(" ", args)}");
             *  return;
             * }
             *
             * if (!string.IsNullOrEmpty(config.Config) && File.Exists(config.Config))
             * {
             *  config = ServerConfig.LoadFrom(config.Config);
             *  parser.ParseArguments(args, config);
             * }*/

            //RestartOnCrash autostart autosave=15
            //gamepath ="C:\Program Files\Space Engineers DS" instance="Hydro Survival" instancepath="C:\ProgramData\SpaceEngineersDedicated\Hydro Survival"

            /*
             * if (config.InstallService)
             * {
             *  var serviceName = $"\"Torch - {config.InstanceName}\"";
             *  // Working on installing the service properly instead of with sc.exe
             *  _log.Info($"Installing service '{serviceName}");
             *  var exePath = $"\"{Assembly.GetExecutingAssembly().Location}\"";
             *  var createInfo = new ServiceCreateInfo
             *  {
             *      Name = config.InstanceName,
             *      BinaryPath = exePath,
             *  };
             *  _log.Info("Service Installed");
             *
             *  var runArgs = string.Join(" ", args.Skip(1));
             *  _log.Info($"Installing Torch as a service with arguments '{runArgs}'");
             *  var startInfo = new ProcessStartInfo
             *  {
             *      FileName = "sc.exe",
             *      Arguments = $"create Torch binPath=\"{Assembly.GetExecutingAssembly().Location} {runArgs}\"",
             *      CreateNoWindow = true,
             *      UseShellExecute = true,
             *      Verb = "runas"
             *  };
             *  Process.Start(startInfo).WaitForExit();
             *  _log.Info("Torch service installed");
             *  return;
             * }
             *
             * if (config.UninstallService)
             * {
             *  _log.Info("Uninstalling Torch service");
             *  var startInfo = new ProcessStartInfo
             *  {
             *      FileName = "sc.exe",
             *      Arguments = "delete Torch",
             *      CreateNoWindow = true,
             *      UseShellExecute = true,
             *      Verb = "runas"
             *  };
             *  Process.Start(startInfo).WaitForExit();
             *  _log.Info("Torch service uninstalled");
             *  return;
             * }*/

            _server = new TorchServer(config);

            _server.Init();
            if (config.NoGui || config.Autostart)
            {
                new Thread(() => _server.Start()).Start();
            }

            if (!config.NoGui)
            {
                var ui = new TorchUI((TorchServer)_server);
                ui.ShowDialog();
            }
        }
コード例 #12
0
        public static void Main(string[] args)
        {
            if (!Environment.UserInteractive)
            {
                using (var service = new TorchService())
                {
                    ServiceBase.Run(service);
                }
                return;
            }

            var         configName = /*args.FirstOrDefault() ??*/ "TorchConfig.xml";
            var         configPath = Path.Combine(Directory.GetCurrentDirectory(), configName);
            TorchConfig options;

            if (File.Exists(configName))
            {
                _log.Info($"Loading config {configPath}");
                options = TorchConfig.LoadFrom(configPath);
            }
            else
            {
                _log.Info($"Generating default config at {configPath}");
                options = new TorchConfig();
                options.Save(configPath);
            }

            bool gui = true;

            foreach (var arg in args)
            {
                switch (arg)
                {
                case "-noupdate":
                    options.EnableAutomaticUpdates = false;
                    break;

                case "-nogui":
                    gui = false;
                    break;
                }
            }

            /*
             * if (!parser.ParseArguments(args, options))
             * {
             *  _log.Error($"Parsing arguments failed: {string.Join(" ", args)}");
             *  return;
             * }
             *
             * if (!string.IsNullOrEmpty(options.Config) && File.Exists(options.Config))
             * {
             *  options = ServerConfig.LoadFrom(options.Config);
             *  parser.ParseArguments(args, options);
             * }*/

            //RestartOnCrash autostart autosave=15
            //gamepath ="C:\Program Files\Space Engineers DS" instance="Hydro Survival" instancepath="C:\ProgramData\SpaceEngineersDedicated\Hydro Survival"

            /*
             * if (options.InstallService)
             * {
             *  var serviceName = $"\"Torch - {options.InstanceName}\"";
             *  // Working on installing the service properly instead of with sc.exe
             *  _log.Info($"Installing service '{serviceName}");
             *  var exePath = $"\"{Assembly.GetExecutingAssembly().Location}\"";
             *  var createInfo = new ServiceCreateInfo
             *  {
             *      Name = options.InstanceName,
             *      BinaryPath = exePath,
             *  };
             *  _log.Info("Service Installed");
             *
             *  var runArgs = string.Join(" ", args.Skip(1));
             *  _log.Info($"Installing Torch as a service with arguments '{runArgs}'");
             *  var startInfo = new ProcessStartInfo
             *  {
             *      FileName = "sc.exe",
             *      Arguments = $"create Torch binPath=\"{Assembly.GetExecutingAssembly().Location} {runArgs}\"",
             *      CreateNoWindow = true,
             *      UseShellExecute = true,
             *      Verb = "runas"
             *  };
             *  Process.Start(startInfo).WaitForExit();
             *  _log.Info("Torch service installed");
             *  return;
             * }
             *
             * if (options.UninstallService)
             * {
             *  _log.Info("Uninstalling Torch service");
             *  var startInfo = new ProcessStartInfo
             *  {
             *      FileName = "sc.exe",
             *      Arguments = "delete Torch",
             *      CreateNoWindow = true,
             *      UseShellExecute = true,
             *      Verb = "runas"
             *  };
             *  Process.Start(startInfo).WaitForExit();
             *  _log.Info("Torch service uninstalled");
             *  return;
             * }*/

            _server = new TorchServer(options);
            _server.Init();
            if (gui)
            {
                var ui = new TorchUI((TorchServer)_server);
                ui.LoadConfig(options);
                ui.ShowDialog();
            }
            else
            {
                _server.Start();
            }
        }
コード例 #13
0
 public TorchServer(TorchConfig config = null)
 {
     Config = config ?? new TorchConfig();
 }