Skip to content

Commit

Permalink
Update Program.cs
Browse files Browse the repository at this point in the history
  • Loading branch information
VirtualBrightPlayz committed Jan 4, 2021
1 parent 66dacc4 commit 41a3957
Showing 1 changed file with 43 additions and 72 deletions.
115 changes: 43 additions & 72 deletions SimpleConsole/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using System.Diagnostics;
using System.Drawing;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Net.Mime;
using System.Net.NetworkInformation;
Expand Down Expand Up @@ -38,6 +39,10 @@ static void Main(string[] args)
if (portfound)
{
Console.WriteLine("Loading");
List<string> cmdargs = new List<string>();
string command = string.Empty;



if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
{
Expand All @@ -46,101 +51,67 @@ static void Main(string[] args)
{
Console.WriteLine("Starting game server...");

Process process = new Process();

// Stop the process from opening a new window
process.StartInfo.RedirectStandardOutput = true;
process.StartInfo.UseShellExecute = false;
process.StartInfo.CreateNoWindow = true;

// Setup executable and parameters
string file = AppDomain.CurrentDomain.BaseDirectory + "/SCP_ET.exe";
Console.WriteLine(file);
process.StartInfo.FileName = file;
process.StartInfo.Arguments = "-consoleport " + port + " -logfile " +
AppDomain.CurrentDomain.BaseDirectory + "/logs/SCP-ETServerLog-" +
DateTime.UtcNow.Ticks + ".txt";
Console.WriteLine(process.StartInfo.Arguments);
// Go
process.Start();
gameprocess = process;
command = file;
cmdargs.Add("-consoleport");
cmdargs.Add(port.ToString());
cmdargs.Add("-logfile");
cmdargs.Add(AppDomain.CurrentDomain.BaseDirectory + "/logs/SCP-ETServerLog-" + DateTime.UtcNow.Ticks + ".txt");
}
else
{
Console.WriteLine("Starting game server...");

Process process = new Process();

// Stop the process from opening a new window
process.StartInfo.RedirectStandardOutput = true;
process.StartInfo.UseShellExecute = false;
process.StartInfo.CreateNoWindow = true;

// Setup executable and parameters
process.StartInfo.FileName = GetArg("-gamelocation") + "/SCP_ET.exe";
process.StartInfo.Arguments = "-consoleport " + port + " -logfile " +
GetArg("-gamelocation") + "/logs/SCP-ETServerLog-" +
DateTime.UtcNow.Ticks + ".txt";
Console.WriteLine(process.StartInfo.Arguments);

// Go
process.Start();
gameprocess = process;
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");
}
}

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

Process process = new Process();

// Stop the process from opening a new window
process.StartInfo.RedirectStandardOutput = true;
process.StartInfo.UseShellExecute = false;
process.StartInfo.CreateNoWindow = true;

// Setup executable and parameters
process.StartInfo.FileName = AppDomain.CurrentDomain.BaseDirectory + "/scp_et.x86_64";
process.StartInfo.Arguments = "-consoleport " + port + " -logfile " +
AppDomain.CurrentDomain.BaseDirectory + "/logs/SCP-ETServerLog-" +
DateTime.UtcNow.Ticks + ".txt";
Console.WriteLine(process.StartInfo.Arguments);

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

Process process = new Process();

// Stop the process from opening a new window
process.StartInfo.RedirectStandardOutput = true;
process.StartInfo.UseShellExecute = false;
process.StartInfo.CreateNoWindow = true;

// Setup executable and parameters
process.StartInfo.FileName = GetArg("-gamelocation") + "/scp_et.x86_64";
process.StartInfo.Arguments = "-consoleport " + port + " -logfile " +
GetArg("-gamelocation") + "/logs/SCP-ETServerLog-" +
DateTime.UtcNow.Ticks + ".txt";
Console.WriteLine(process.StartInfo.Arguments);

// Go
process.Start();
gameprocess = process;
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");
}
}

console = new TcpConsoleClient();
console.ConnectToTcpServer();
listeninput();
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();
}
}
}

Expand Down

0 comments on commit 41a3957

Please sign in to comment.