Example #1
0
        static void Main(string[] args)
        {
            IPGlobalProperties ipGlobalProperties = IPGlobalProperties.GetIPGlobalProperties();

            TcpConnectionInformation[] tcpConnInfoArray = ipGlobalProperties.GetActiveTcpConnections();
            IP = GetArg("-ip");
            if (string.IsNullOrEmpty(IP))
            {
                IP = "127.0.0.1";
            }
            string tempport = GetArg("-port");

            if (!string.IsNullOrEmpty(tempport) && int.TryParse(tempport, out port))
            {
                portfound = true;
            }
            else
            {
                //look for a port that is not in use
                port = new Random().Next(50000, 60000);
                foreach (TcpConnectionInformation tcpi in tcpConnInfoArray)
                {
                    if (tcpi.LocalEndPoint.Port == port)
                    {
                        portfound = false;
                        Console.WriteLine("console port was already in use");
                        break;
                    }
                }
            }

            if (portfound)
            {
                Console.WriteLine("Loading");
                List <string> cmdargs = new List <string>();
                string        command = string.Empty;


                if (!Directory.Exists("logs"))
                {
                    Console.WriteLine("Logs folder not found, creating");
                    Directory.CreateDirectory("logs");
                }

                if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
                {
                    Console.WriteLine("Platform windows");
                    if (string.IsNullOrEmpty(GetArg("-gamelocation")))
                    {
                        Console.WriteLine("Starting game server...");

                        string file = "SCP_ET.exe";
                        Console.WriteLine(file);
                        command = file;
                        cmdargs.Add("-consoleport");
                        cmdargs.Add(port.ToString());
                        if (GetArg("-gameoutput") != "true")
                        {
                            cmdargs.Add("-logfile");
                            cmdargs.Add("logs/SCP-ETServerLog-" + DateTime.UtcNow.Ticks + ".txt");
                        }
                    }
                    else
                    {
                        Console.WriteLine("Starting game server...");

                        string file = GetArg("-gamelocation") + "/SCP_ET.exe";
                        Console.WriteLine(file);
                        command = file;
                        cmdargs.Add("-consoleport");
                        cmdargs.Add(port.ToString());
                        if (GetArg("-gameoutput") != "true")
                        {
                            cmdargs.Add("-logfile");
                            cmdargs.Add(GetArg("-gamelocation") + "/logs/SCP-ETServerLog-" + DateTime.UtcNow.Ticks + ".txt");
                        }
                    }
                }
                else if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
                {
                    Console.WriteLine("Platform linux");
                    if (string.IsNullOrEmpty(GetArg("-gamelocation")))
                    {
                        Console.WriteLine("Starting game server...");

                        string file = "scp_et.x86_64";
                        Console.WriteLine(file);
                        command = file;
                        cmdargs.Add("-consoleport");
                        cmdargs.Add(port.ToString());
                        if (GetArg("-gameoutput") != "true")
                        {
                            cmdargs.Add("-logfile");
                            cmdargs.Add("logs/SCP-ETServerLog-" + DateTime.UtcNow.Ticks + ".txt");
                        }
                    }
                    else
                    {
                        Console.WriteLine("Starting game server...");

                        string file = GetArg("-gamelocation") + "/scp_et.x86_64";
                        Console.WriteLine(file);
                        command = file;
                        cmdargs.Add("-consoleport");
                        cmdargs.Add(port.ToString());
                        if (GetArg("-gameoutput") != "true")
                        {
                            cmdargs.Add("-logfile");
                            cmdargs.Add(GetArg("-gamelocation") + "/logs/SCP-ETServerLog-" + DateTime.UtcNow.Ticks + ".txt");
                        }
                    }
                }

                ProcessStartInfo info2 = new ProcessStartInfo(Path.GetFullPath(command), string.Join(' ', cmdargs));
                info2.RedirectStandardError  = true;
                info2.RedirectStandardOutput = true;

                using (Process cmd = Process.Start(info2))
                {
                    console = new TcpConsoleClient();
                    console.ConnectToTcpServer();
                    AppDomain.CurrentDomain.DomainUnload       += (s, e) => { cmd.Kill(); cmd.WaitForExit(); };
                    AppDomain.CurrentDomain.ProcessExit        += (s, e) => { cmd.Kill(); cmd.WaitForExit(); };
                    AppDomain.CurrentDomain.UnhandledException += (s, e) => { cmd.Kill(); cmd.WaitForExit(); };
                    cmd.ErrorDataReceived += (sender, args) =>
                    {
                        if (string.IsNullOrWhiteSpace(args.Data))
                        {
                            return;
                        }
                        Console.WriteLine($"[GAME-ERR] {args.Data}");
                    };
                    cmd.OutputDataReceived += (sender, args) =>
                    {
                        if (string.IsNullOrWhiteSpace(args.Data))
                        {
                            return;
                        }
                        Console.WriteLine($"[GAME-OUT] {args.Data}");
                    };

                    cmd.Exited += (sender, arg) =>
                    {
                        Console.WriteLine("Game process has exited");
                        Thread.Sleep(1000);
                        Environment.Exit(1);
                    };

                    cmd.BeginErrorReadLine();
                    cmd.BeginOutputReadLine();

                    listeninput(cmd);
                }
            }
        }
Example #2
0
        static void Main(string[] args)
        {
            IPGlobalProperties ipGlobalProperties = IPGlobalProperties.GetIPGlobalProperties();

            TcpConnectionInformation[] tcpConnInfoArray = ipGlobalProperties.GetActiveTcpConnections();
            IP = GetArg("-ip");
            if (string.IsNullOrEmpty(IP))
            {
                IP = "127.0.0.1";
            }
            string tempport = GetArg("-port");

            if (!string.IsNullOrEmpty(tempport) && int.TryParse(tempport, out port))
            {
                portfound = true;
            }
            else
            {
                //look for a port that is not in use
                port = new Random().Next(50000, 60000);
                foreach (TcpConnectionInformation tcpi in tcpConnInfoArray)
                {
                    if (tcpi.LocalEndPoint.Port == port)
                    {
                        portfound = false;
                        Console.WriteLine("console port was already in use");
                        break;
                    }
                }
            }

            if (portfound)
            {
                Console.WriteLine("Loading");
                List <string> cmdargs = new List <string>();
                string        command = string.Empty;



                if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
                {
                    Console.WriteLine("Platform windows");
                    if (string.IsNullOrEmpty(GetArg("-gamelocation")))
                    {
                        Console.WriteLine("Starting game server...");

                        string file = "SCP_ET.exe";
                        Console.WriteLine(file);
                        command = file;
                        cmdargs.Add("-consoleport");
                        cmdargs.Add(port.ToString());
                        cmdargs.Add("-logfile");
                        cmdargs.Add("logs/SCP-ETServerLog-" + DateTime.UtcNow.Ticks + ".txt");
                    }
                    else
                    {
                        Console.WriteLine("Starting game server...");

                        string file = GetArg("-gamelocation") + "/SCP_ET.exe";
                        Console.WriteLine(file);
                        command = file;
                        cmdargs.Add("-consoleport");
                        cmdargs.Add(port.ToString());
                        cmdargs.Add("-logfile");
                        cmdargs.Add(GetArg("-gamelocation") + "/logs/SCP-ETServerLog-" + DateTime.UtcNow.Ticks + ".txt");
                    }
                }
                else if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
                {
                    Console.WriteLine("Platform linux");
                    if (string.IsNullOrEmpty(GetArg("-gamelocation")))
                    {
                        Console.WriteLine("Starting game server...");

                        string file = "scp_et.x86_64";
                        Console.WriteLine(file);
                        command = file;
                        cmdargs.Add("-consoleport");
                        cmdargs.Add(port.ToString());
                        cmdargs.Add("-logfile");
                        cmdargs.Add("logs/SCP-ETServerLog-" + DateTime.UtcNow.Ticks + ".txt");
                    }
                    else
                    {
                        Console.WriteLine("Starting game server...");

                        string file = GetArg("-gamelocation") + "/scp_et.x86_64";
                        Console.WriteLine(file);
                        command = file;
                        cmdargs.Add("-consoleport");
                        cmdargs.Add(port.ToString());
                        cmdargs.Add("-logfile");
                        cmdargs.Add(GetArg("-gamelocation") + "/logs/SCP-ETServerLog-" + DateTime.UtcNow.Ticks + ".txt");
                    }
                }

                ProcessStartInfo info2 = new ProcessStartInfo(Path.GetFullPath(command), string.Join(' ', cmdargs));

                using (Process cmd = Process.Start(info2))
                {
                    console = new TcpConsoleClient();
                    console.ConnectToTcpServer();
                    AppDomain.CurrentDomain.DomainUnload       += (s, e) => { cmd.Kill(); cmd.WaitForExit(); };
                    AppDomain.CurrentDomain.ProcessExit        += (s, e) => { cmd.Kill(); cmd.WaitForExit(); };
                    AppDomain.CurrentDomain.UnhandledException += (s, e) => { cmd.Kill(); cmd.WaitForExit(); };
                    listeninput();
                }
            }
        }