Пример #1
0
        public async Task <Process> Start(string param)
        {
            string workingDir = Functions.Path.GetServerFiles(_serverId);
            string hldsPath   = Path.Combine(workingDir, "hlds.exe");

            if (!File.Exists(hldsPath))
            {
                Error = $"hlds.exe not found ({hldsPath})";
                return(null);
            }

            if (string.IsNullOrWhiteSpace(param))
            {
                Error = "Start Parameter not set";
                return(null);
            }

            WindowsFirewall firewall = new WindowsFirewall("hlds.exe", hldsPath);

            if (!await firewall.IsRuleExist())
            {
                firewall.AddRule();
            }

            Process p = new Process();

            p.StartInfo.WorkingDirectory = workingDir;
            p.StartInfo.FileName         = hldsPath;
            p.StartInfo.Arguments        = param;
            p.StartInfo.WindowStyle      = ProcessWindowStyle.Minimized;
            p.Start();

            return(p);
        }
Пример #2
0
        public async Task <Process> Run()
        {
            string exePath = Path.Combine(MainWindow.WGSM_PATH, @"installer\steamcmd\steamcmd.exe");

            if (!File.Exists(exePath))
            {
                Error = $"steamcmd.exe not found ({exePath})";
                return(null);
            }

            WindowsFirewall firewall = new WindowsFirewall("steamcmd.exe", exePath);

            if (!await firewall.IsRuleExist())
            {
                firewall.AddRule();
            }

            Process p = new Process();

            p.StartInfo.FileName    = exePath;
            p.StartInfo.Arguments   = _param;
            p.StartInfo.WindowStyle = ProcessWindowStyle.Minimized;
            p.Start();

            return(p);
        }
Пример #3
0
        public Process Run()
        {
            string exePath = MainWindow.WGSM_PATH + @"\installer\steamcmd\steamcmd.exe";

            if (!File.Exists(exePath))
            {
                Error = "steamcmd.exe not found (" + exePath + ")";
                return(null);
            }

            WindowsFirewall firewall = new WindowsFirewall("steamcmd.exe", exePath);

            if (!firewall.IsRuleExist())
            {
                firewall.AddRule();
            }

            Process p = new Process();

            p.StartInfo.FileName    = exePath;
            p.StartInfo.Arguments   = Param;
            p.StartInfo.WindowStyle = ProcessWindowStyle.Minimized;
            p.Start();

            return(p);
        }
Пример #4
0
        public async Task <Process> Run()
        {
            string exeFile = "steamcmd.exe";
            string exePath = Path.Combine(_installPath, exeFile);

            if (!File.Exists(exePath))
            {
                //If steamcmd.exe not exists, download steamcmd.exe
                if (!await Download())
                {
                    Error = $"Fail to download {exeFile}";
                    return(null);
                }
            }

            if (_param == null)
            {
                Error = "Steam account is not set";
                return(null);
            }

            Console.WriteLine($"SteamCMD Param: {_param}");

            WindowsFirewall firewall = new WindowsFirewall(exeFile, exePath);

            if (!await firewall.IsRuleExist())
            {
                firewall.AddRule();
            }

            Process p = new Process
            {
                StartInfo =
                {
                    WorkingDirectory       = _installPath,
                    FileName               = exePath,
                    Arguments              = _param,
                    WindowStyle            = ProcessWindowStyle.Minimized,
                    CreateNoWindow         = true,
                    UseShellExecute        = false,
                    RedirectStandardInput  = true,
                    StandardOutputEncoding = System.Text.Encoding.UTF8,
                    RedirectStandardOutput = true,
                    RedirectStandardError  = true
                },
                EnableRaisingEvents = true
            };

            p.Start();

            return(p);
        }
Пример #5
0
        public async Task <string> GetRemoteBuild(string appId)
        {
            string exePath = Path.Combine(_installPath, "steamcmd.exe");

            if (!File.Exists(exePath))
            {
                //If steamcmd.exe not exists, download steamcmd.exe
                if (!await Download())
                {
                    Error = "Fail to download steamcmd.exe";
                    return("");
                }
            }

            WindowsFirewall firewall = new WindowsFirewall("steamcmd.exe", exePath);

            if (!await firewall.IsRuleExist())
            {
                firewall.AddRule();
            }

            Process p = new Process
            {
                StartInfo =
                {
                    FileName               = exePath,
                    //Sometimes it fails to get if appID < 90
                    Arguments              = $"+login anonymous +app_info_update 1 +app_info_print {appId} +app_info_print {appId} +app_info_print {appId} +app_info_print {appId} +quit",
                    WindowStyle            = ProcessWindowStyle.Minimized,
                    CreateNoWindow         = true,
                    UseShellExecute        = false,
                    RedirectStandardOutput = true
                }
            };

            p.Start();

            string output = await p.StandardOutput.ReadToEndAsync();

            Regex regex   = new Regex("\"public\"\r\n.{0,}{\r\n.{0,}\"buildid\".{1,}\"(.*?)\"");
            var   matches = regex.Matches(output);

            if (matches.Count < 1 || matches[1].Groups.Count < 2)
            {
                Error = $"Fail to get remote build";
                return("");
            }

            return(matches[0].Groups[1].Value);
        }
Пример #6
0
        public async Task <Process> Start()
        {
            string fxServerPath = Functions.Path.GetServerFiles(_serverId, @"server\FXServer.exe");

            if (!File.Exists(fxServerPath))
            {
                Error = $"FXServer.exe not found ({fxServerPath})";
                return(null);
            }

            string citizenPath = Functions.Path.GetServerFiles(_serverId, @"server\citizen");

            if (!Directory.Exists(citizenPath))
            {
                Error = $"Directory citizen not found ({citizenPath})";
                return(null);
            }

            string serverDataPath = Functions.Path.GetServerFiles(_serverId, "cfx-server-data-master");

            if (!Directory.Exists(serverDataPath))
            {
                Error = $"Directory cfx-server-data-master not found ({serverDataPath})";
                return(null);
            }

            string configPath = Path.Combine(serverDataPath, "server.cfg");

            if (!File.Exists(configPath))
            {
                Notice = $"server.cfg not found ({configPath})";
            }

            WindowsFirewall firewall = new WindowsFirewall("FXServer.exe", fxServerPath);

            if (!await firewall.IsRuleExist())
            {
                firewall.AddRule();
            }

            Process p = new Process();

            p.StartInfo.WorkingDirectory = serverDataPath;
            p.StartInfo.FileName         = fxServerPath;
            p.StartInfo.Arguments        = $"+set citizen_dir \"{citizenPath}\" {_param}";
            p.StartInfo.WindowStyle      = ProcessWindowStyle.Minimized;
            p.Start();

            return(p);
        }
Пример #7
0
        public async Task <Process> Start()
        {
            int isJavaInstalled = IsJavaJREInstalled();

            if (isJavaInstalled == 0)
            {
                Error = "Java is not installed";
                return(null);
            }

            string workingDir = Functions.Path.GetServerFiles(_serverId);

            string serverJarPath = Path.Combine(workingDir, "server.jar");

            if (!File.Exists(serverJarPath))
            {
                Error = $"server.jar not found ({serverJarPath})";
                return(null);
            }

            string configPath = Path.Combine(workingDir, "server.properties");

            if (!File.Exists(configPath))
            {
                Notice = $"server.properties not found ({configPath}). Generated a new one.";
            }

            string javaPath = (isJavaInstalled == 1) ? "java" : "C:\\Program Files (x86)\\Java\\jre1.8.0_231\\bin\\java.exe";

            if (isJavaInstalled == 2)
            {
                WindowsFirewall firewall = new WindowsFirewall("java.exe", javaPath);
                if (!await firewall.IsRuleExist())
                {
                    firewall.AddRule();
                }
            }

            Process p = new Process();

            p.StartInfo.WorkingDirectory = workingDir;
            p.StartInfo.FileName         = javaPath;
            p.StartInfo.Arguments        = $"{_param} -jar server.jar nogui";
            p.StartInfo.WindowStyle      = ProcessWindowStyle.Minimized;
            p.Start();

            return(p);
        }
Пример #8
0
        public async Task <Process> Start()
        {
            string workingDir = Functions.Path.GetServerFiles(_serverId);

            string phpPath = workingDir + @"\bin\php\php.exe";

            if (!File.Exists(phpPath))
            {
                Error = $"php.exe not found ({phpPath})";
                return(null);
            }

            string PMMPPath = workingDir + @"\PocketMine-MP.phar";

            if (!File.Exists(PMMPPath))
            {
                Error = $"PocketMine-MP.phar not found ({PMMPPath})";
                return(null);
            }

            string serverConfigPath = workingDir + @"\server.properties";

            if (!File.Exists(serverConfigPath))
            {
                Error = $"server.properties not found ({serverConfigPath})";
                return(null);
            }

            WindowsFirewall firewall = new WindowsFirewall("php.exe", phpPath);

            if (!await firewall.IsRuleExist())
            {
                firewall.AddRule();
            }

            Process p = new Process();

            p.StartInfo.WorkingDirectory = workingDir;
            p.StartInfo.FileName         = phpPath;
            p.StartInfo.Arguments        = @"-c bin\php PocketMine-MP.phar";
            p.StartInfo.WindowStyle      = ProcessWindowStyle.Minimized;
            p.Start();

            return(p);
        }
Пример #9
0
        public (Process Process, string Error, string Notice) Start()
        {
            string workingDir = Functions.Path.GetServerFiles(ServerID);

            string phpPath = workingDir + @"\bin\php\php.exe";

            if (!File.Exists(phpPath))
            {
                return(null, "php.exe not found (" + phpPath + ")", "");
            }

            string PMMPPath = workingDir + @"\PocketMine-MP.phar";

            if (!File.Exists(PMMPPath))
            {
                return(null, "PocketMine-MP.phar not found (" + PMMPPath + ")", "");
            }

            string serverConfigPath = workingDir + @"\server.properties";

            if (!File.Exists(serverConfigPath))
            {
                return(null, "server.properties not found (" + serverConfigPath + ")", "");
            }

            WindowsFirewall firewall = new WindowsFirewall("php.exe", phpPath);

            if (!firewall.IsRuleExist())
            {
                firewall.AddRule();
            }

            Process p = new Process();

            p.StartInfo.WorkingDirectory = workingDir;
            p.StartInfo.FileName         = phpPath;
            p.StartInfo.Arguments        = @"-c bin\php PocketMine-MP.phar";
            p.StartInfo.WindowStyle      = ProcessWindowStyle.Minimized;
            p.Start();

            return(p, "", "");
        }
Пример #10
0
        public (Process Process, string Error, string Notice) Start()
        {
            string workingDir = Functions.Path.GetServerFiles(ServerID);
            string hldsPath   = workingDir + @"\hlds.exe";

            if (!File.Exists(hldsPath))
            {
                return(null, "hlds.exe not found (" + hldsPath + ")", "");
            }

            if (string.IsNullOrWhiteSpace(Param))
            {
                return(null, "Start Parameter not set", "");
            }

            string serverConfigPath = workingDir + @"\czero\server.cfg";

            if (!File.Exists(serverConfigPath))
            {
                return(null, "", "server.cfg not found (" + serverConfigPath + ")");
            }

            WindowsFirewall firewall = new WindowsFirewall("hlds.exe", hldsPath);

            if (!firewall.IsRuleExist())
            {
                firewall.AddRule();
            }

            Process p = new Process();

            p.StartInfo.WorkingDirectory = workingDir;
            p.StartInfo.FileName         = hldsPath;
            p.StartInfo.Arguments        = Param;
            p.StartInfo.WindowStyle      = ProcessWindowStyle.Minimized;
            p.Start();

            return(p, "", "");
        }
Пример #11
0
        public async Task <Process> Start(string param, string customSrcdsName = "srcds.exe", bool setWorkingDirectory = true)
        {
            string workingDir = Functions.Path.GetServerFiles(_serverId);
            string srcdsPath  = Path.Combine(workingDir, customSrcdsName);

            if (!File.Exists(srcdsPath))
            {
                Error = $"{customSrcdsName} not found ({srcdsPath})";
                return(null);
            }

            if (string.IsNullOrWhiteSpace(param))
            {
                Error = "Start Parameter not set";
                return(null);
            }

            WindowsFirewall firewall = new WindowsFirewall(customSrcdsName, srcdsPath);

            if (!await firewall.IsRuleExist())
            {
                firewall.AddRule();
            }

            Process p = new Process();

            if (setWorkingDirectory)
            {
                p.StartInfo.WorkingDirectory = workingDir;
            }
            p.StartInfo.FileName    = srcdsPath;
            p.StartInfo.Arguments   = param;
            p.StartInfo.WindowStyle = ProcessWindowStyle.Minimized;
            p.Start();

            return(p);
        }
Пример #12
0
        public async Task <Process> Start()
        {
            string exeName    = "7DaysToDieServer.exe";
            string workingDir = Functions.ServerPath.GetServersServerFiles(_serverData.ServerID);
            string exePath    = Path.Combine(workingDir, exeName);

            if (!File.Exists(exePath))
            {
                Error = $"{exeName} not found ({exePath})";
                return(null);
            }

            string configPath = Functions.ServerPath.GetServersServerFiles(_serverData.ServerID, "serverconfig.xml");

            if (!File.Exists(configPath))
            {
                Notice = $"serverconfig.xml not found ({configPath})";
            }

            string logFile = @"7DaysToDieServer_Data\output_log_dedi__" + DateTime.Now.ToString("yyyy-MM-dd-HH-mm-ss") + ".txt";
            string param   = $"-logfile \"{Path.Combine(workingDir, logFile)}\" -quit -batchmode -nographics -configfile=serverconfig.xml -dedicated {_serverData.ServerParam}";

            WindowsFirewall firewall = new WindowsFirewall(exeName, exePath);

            if (!await firewall.IsRuleExist())
            {
                firewall.AddRule();
            }

            Process p;

            if (!AllowsEmbedConsole)
            {
                p = new Process
                {
                    StartInfo =
                    {
                        WorkingDirectory = workingDir,
                        FileName         = exePath,
                        Arguments        = param,
                        WindowStyle      = ProcessWindowStyle.Minimized
                    },
                    EnableRaisingEvents = true
                };
                p.Start();
            }
            else
            {
                p = new Process
                {
                    StartInfo =
                    {
                        WorkingDirectory       = workingDir,
                        FileName               = exePath,
                        Arguments              = param,
                        WindowStyle            = ProcessWindowStyle.Minimized,
                        UseShellExecute        = false,
                        RedirectStandardOutput = true,
                        RedirectStandardError  = true
                    },
                    EnableRaisingEvents = true
                };
                var serverConsole = new Functions.ServerConsole(_serverData.ServerID);
                p.OutputDataReceived += serverConsole.AddOutput;
                p.ErrorDataReceived  += serverConsole.AddOutput;
                p.Start();
                p.BeginOutputReadLine();
                p.BeginErrorReadLine();
            }

            return(p);
        }
Пример #13
0
        public async Task <Process> Start()
        {
            // Use DZSALModServer.exe if the exe exist, otherwise use original
            string dzsaPath = Functions.ServerPath.GetServersServerFiles(_serverData.ServerID, "DZSALModServer.exe");

            if (File.Exists(dzsaPath))
            {
                StartPath = "DZSALModServer.exe";

                WindowsFirewall firewall = new WindowsFirewall(StartPath, dzsaPath);
                if (!await firewall.IsRuleExist())
                {
                    firewall.AddRule();
                }
            }
            else
            {
                string serverPath = Functions.ServerPath.GetServersServerFiles(_serverData.ServerID, StartPath);
                if (!File.Exists(serverPath))
                {
                    Error = $"{StartPath} not found ({serverPath})";
                    return(null);
                }
            }

            string configPath = Functions.ServerPath.GetServersServerFiles(_serverData.ServerID, "serverDZ.cfg");

            if (!File.Exists(configPath))
            {
                Notice = $"{Path.GetFileName(configPath)} not found ({configPath})";
            }

            string param = $" {_serverData.ServerParam}";

            param += string.IsNullOrEmpty(_serverData.ServerIP) ? string.Empty : $" -ip={_serverData.ServerIP}";
            param += string.IsNullOrEmpty(_serverData.ServerPort) ? string.Empty : $" -port={_serverData.ServerPort}";

            string modPath = Functions.ServerPath.GetServersConfigs(_serverData.ServerID, "DayZActivatedMods.cfg");

            if (File.Exists(modPath))
            {
                string modParam = string.Empty;
                foreach (string modName in File.ReadLines(modPath))
                {
                    modParam += $"{modName.Trim()};";
                }

                if (!string.IsNullOrWhiteSpace(modParam))
                {
                    param += $" \"-mod={modParam}\"";
                }
            }

            Process p = new Process
            {
                StartInfo =
                {
                    WorkingDirectory = Functions.ServerPath.GetServersServerFiles(_serverData.ServerID),
                    FileName         = Functions.ServerPath.GetServersServerFiles(_serverData.ServerID, StartPath),
                    Arguments        = param,
                    WindowStyle      = ProcessWindowStyle.Minimized,
                    UseShellExecute  = false
                },
                EnableRaisingEvents = true
            };

            p.Start();

            return(p);
        }
Пример #14
0
        public async Task <Process> Start()
        {
            string exeFile = "MordhauServer.exe";
            string exePath = Functions.ServerPath.GetServerFiles(_serverData.ServerID, exeFile);

            if (!File.Exists(exePath))
            {
                Error = $"{exeFile} not found ({exePath})";
                return(null);
            }

            string          shipExeFile = "MordhauServer-Win64-Shipping.exe";
            string          shipExePath = Functions.ServerPath.GetServerFiles(_serverData.ServerID, @"Mordhau\Binaries\Win64", shipExeFile);
            WindowsFirewall firewall    = new WindowsFirewall(shipExeFile, shipExePath);

            if (!await firewall.IsRuleExist())
            {
                firewall.AddRule();
            }

            if (!File.Exists(shipExePath))
            {
                Error = $"{shipExeFile} not found ({shipExePath})";
                return(null);
            }

            string configFile = "Game.ini";
            string configPath = Functions.ServerPath.GetServerFiles(_serverData.ServerID, @"Mordhau\Saved\Config\WindowsServer", configFile);

            if (!File.Exists(configPath))
            {
                Notice = $"{configFile} not found ({configPath})";
            }

            string param = string.IsNullOrWhiteSpace(_serverData.ServerMap) ? "" : $"{_serverData.ServerMap}";

            param += string.IsNullOrWhiteSpace(_serverData.ServerIP) ? "" : $" -MultiHome={_serverData.ServerIP}";
            param += string.IsNullOrWhiteSpace(_serverData.ServerPort) ? "" : $" -Port={_serverData.ServerPort}";
            param += $" {_serverData.ServerParam}" + ((ToggleConsole) ? " -log" : "");

            Process p;

            if (ToggleConsole)
            {
                p = new Process
                {
                    StartInfo =
                    {
                        FileName    = shipExePath,
                        Arguments   = param,
                        WindowStyle = ProcessWindowStyle.Minimized,
                    },
                    EnableRaisingEvents = true
                };
                p.Start();
            }
            else
            {
                p = new Process
                {
                    StartInfo =
                    {
                        FileName               = shipExePath,
                        Arguments              = param,
                        WindowStyle            = ProcessWindowStyle.Hidden,
                        CreateNoWindow         = true,
                        UseShellExecute        = false,
                        RedirectStandardOutput = true,
                        RedirectStandardError  = true
                    },
                    EnableRaisingEvents = true
                };
                var serverConsole = new Functions.ServerConsole(_serverData.ServerID);
                p.OutputDataReceived += serverConsole.AddOutput;
                p.ErrorDataReceived  += serverConsole.AddOutput;
                p.Start();
                p.BeginOutputReadLine();
                p.BeginErrorReadLine();
            }

            return(p);
        }
Пример #15
0
        public async Task <Process> Start()
        {
            string javaPath = JavaHelper.FindJavaExecutableAbsolutePath();

            if (javaPath.Length == 0)
            {
                Error = "Java is not installed";
                return(null);
            }

            string workingDir = Functions.ServerPath.GetServersServerFiles(_serverData.ServerID);

            string serverJarPath = Path.Combine(workingDir, "server.jar");

            if (!File.Exists(serverJarPath))
            {
                Error = $"server.jar not found ({serverJarPath})";
                return(null);
            }

            string configPath = Path.Combine(workingDir, "server.properties");

            if (!File.Exists(configPath))
            {
                Notice = $"server.properties not found ({configPath}). Generated a new one.";
            }

            WindowsFirewall firewall = new WindowsFirewall("java.exe", javaPath);

            if (!await firewall.IsRuleExist())
            {
                firewall.AddRule();
            }

            Process p;

            if (!AllowsEmbedConsole)
            {
                p = new Process
                {
                    StartInfo =
                    {
                        WorkingDirectory = workingDir,
                        FileName         = javaPath,
                        Arguments        = $"{_serverData.ServerParam} -jar server.jar nogui",
                        WindowStyle      = ProcessWindowStyle.Minimized,
                        UseShellExecute  = false
                    },
                    EnableRaisingEvents = true
                };
                p.Start();
            }
            else
            {
                p = new Process
                {
                    StartInfo =
                    {
                        WorkingDirectory       = workingDir,
                        FileName               = javaPath,
                        Arguments              = $"{_serverData.ServerParam} -jar server.jar nogui",
                        WindowStyle            = ProcessWindowStyle.Minimized,
                        CreateNoWindow         = true,
                        UseShellExecute        = false,
                        RedirectStandardInput  = true,
                        RedirectStandardOutput = true,
                        RedirectStandardError  = true
                    },
                    EnableRaisingEvents = true
                };
                var serverConsole = new Functions.ServerConsole(_serverData.ServerID);
                p.OutputDataReceived += serverConsole.AddOutput;
                p.ErrorDataReceived  += serverConsole.AddOutput;
                p.Start();
                p.BeginOutputReadLine();
                p.BeginErrorReadLine();
            }

            return(p);
        }
Пример #16
0
        public async Task <string> GetRemoteBuild(string appId)
        {
            string exePath = Path.Combine(_installPath, "steamcmd.exe");

            if (!File.Exists(exePath))
            {
                //If steamcmd.exe not exists, download steamcmd.exe
                if (!await Download())
                {
                    Error = "Fail to download steamcmd.exe";
                    return(string.Empty);
                }
            }

            WindowsFirewall firewall = new WindowsFirewall("steamcmd.exe", exePath);

            if (!await firewall.IsRuleExist())
            {
                await firewall.AddRule();
            }

            // Removes appinfo.vdf as a fix for not always getting up to date version info from SteamCMD.
            await Task.Run(() =>
            {
                string vdfPath = Path.Combine(_installPath, "appcache", "appinfo.vdf");
                try
                {
                    if (File.Exists(vdfPath))
                    {
                        File.Delete(vdfPath);
                        Debug.WriteLine($"Deleted appinfo.vdf ({vdfPath})");
                    }
                }
                catch
                {
                    Debug.WriteLine($"File to delete appinfo.vdf ({vdfPath})");
                }
            });

            Process p = new Process
            {
                StartInfo =
                {
                    FileName               = exePath,
                    //Sometimes it fails to get if appID < 90
                    Arguments              = $"+login anonymous +app_info_update 1 +app_info_print {appId} +app_info_print {appId} +app_info_print {appId} +app_info_print {appId} +quit",
                    WindowStyle            = ProcessWindowStyle.Minimized,
                    CreateNoWindow         = true,
                    UseShellExecute        = false,
                    RedirectStandardOutput = true
                }
            };

            p.Start();
            SendEnterPreventFreeze(p);

            string output = await p.StandardOutput.ReadToEndAsync();

            Regex regex   = new Regex("\"public\"\r\n.{0,}{\r\n.{0,}\"buildid\".{1,}\"(.*?)\"");
            var   matches = regex.Matches(output);

            if (matches.Count < 1 || matches[1].Groups.Count < 2)
            {
                Error = $"Fail to get remote build";
                return(string.Empty);
            }

            return(matches[0].Groups[1].Value);
        }
Пример #17
0
        public async Task <Process> Start()
        {
            Java isJavaInstalled = IsJavaJREInstalled();

            if (isJavaInstalled == Java.NotInstall)
            {
                Error = "Java is not installed";
                return(null);
            }

            string workingDir = Functions.ServerPath.GetServersServerFiles(_serverData.ServerID);

            string serverJarPath = Path.Combine(workingDir, "server.jar");

            if (!File.Exists(serverJarPath))
            {
                Error = $"server.jar not found ({serverJarPath})";
                return(null);
            }

            string configPath = Path.Combine(workingDir, "server.properties");

            if (!File.Exists(configPath))
            {
                Notice = $"server.properties not found ({configPath}). Generated a new one.";
            }

            string javaPath = (isJavaInstalled == Java.InstalledGlobal) ? "java" : "C:\\Program Files (x86)\\Java\\jre1.8.0_231\\bin\\java.exe";

            if (isJavaInstalled == Java.InstalledAbsolute)
            {
                WindowsFirewall firewall = new WindowsFirewall("java.exe", javaPath);
                if (!await firewall.IsRuleExist())
                {
                    firewall.AddRule();
                }
            }

            Process p;

            if (ToggleConsole)
            {
                p = new Process
                {
                    StartInfo =
                    {
                        WorkingDirectory = workingDir,
                        FileName         = javaPath,
                        Arguments        = $"{_serverData.ServerParam} -jar server.jar nogui",
                        WindowStyle      = ProcessWindowStyle.Minimized,
                    },
                    EnableRaisingEvents = true
                };
                p.Start();
            }
            else
            {
                p = new Process
                {
                    StartInfo =
                    {
                        WorkingDirectory       = workingDir,
                        FileName               = javaPath,
                        Arguments              = $"{_serverData.ServerParam} -jar server.jar nogui",
                        WindowStyle            = ProcessWindowStyle.Minimized,
                        CreateNoWindow         = true,
                        UseShellExecute        = false,
                        RedirectStandardInput  = true,
                        RedirectStandardOutput = true,
                        RedirectStandardError  = true
                    },
                    EnableRaisingEvents = true
                };
                var serverConsole = new Functions.ServerConsole(_serverData.ServerID);
                p.OutputDataReceived += serverConsole.AddOutput;
                p.ErrorDataReceived  += serverConsole.AddOutput;
                p.Start();
                p.BeginOutputReadLine();
                p.BeginErrorReadLine();
            }

            return(p);
        }
Пример #18
0
        private static IWindowsFirewall WinFwScan()

        /*
         * Windows Firewall information can be found using the INetFwMgr interface in the NetFwTypeLib namespace.
         * The firewall manager object, HNetCfg.FwMgr, is a COM object; type is retrieved at runtime and instantiated
         * using Activator.CreateInstance()
         */

        /* Each firewall rule in the Windows Firewall has associated remote ports.
         * This subroutine handles retrieving them, and storing them in the WinFW object in the
         * scan result. The WinFW object has a RulesByPort dict that allows looking up
         * what rules are associated with any given port (i.e. GetRulesByPort(string PortNumber))
         * See the ConsoleApp in this solution for a usage example.
         *
         * The RemotePorts property in INetFwRule is just a string; it has comma-separated ports,
         * some actually using alphabetical names instead of numbers. This gets pulled out into
         * a list of strings, so that a program using ports 80 and 443 can be found via
         * GetRulesByPort("80") or GetRulesByPort("443")
         */
        {
            WindowsFirewall WinFW = new WindowsFirewall();

            //Instantiate Firewall Manager object and get current profile
            Type          tNetFirewall = Type.GetTypeFromProgID("HNetCfg.FwMgr", false);
            INetFwMgr     FwMgr        = (INetFwMgr)Activator.CreateInstance(tNetFirewall);
            INetFwProfile FwProfile    = FwMgr.LocalPolicy.CurrentProfile;

            // Populate basic properties
            WinFW.Enabled           = FwProfile.FirewallEnabled;
            WinFW.GloballyOpenPorts = new List <int>();

            foreach (int p in FwProfile.GloballyOpenPorts)
            {
                WinFW.GloballyOpenPorts.Add(p);
            }

            //Get Rule objects
            Type          tFwPolicy = Type.GetTypeFromProgID("HNetCfg.FwPolicy2", false);
            INetFwPolicy2 FwPolicy  = (INetFwPolicy2)Activator.CreateInstance(tFwPolicy);
            INetFwRules   FwRules   = FwPolicy.Rules;

            // Create a new rule for each rule object, pass it to the AddRule method of the
            // WinFW object
            foreach (INetFwRule Rule in FwRules)
            {
                WinFWRule R = new WinFWRule();
                R.Name            = Rule.Name;
                R.Description     = Rule.Description;
                R.ApplicationName = Rule.ApplicationName;
                R.ServiceName     = Rule.serviceName;
                R.Enabled         = Rule.Enabled;
                R.RemotePorts     = new List <string>();
                if (Rule.RemotePorts != null)
                {
                    //Separate by commas
                    R.RemotePorts.AddRange(Rule.RemotePorts.Split(','));
                }
                WinFW.AddRule(R);
            }

            return(WinFW);
        }