Add support for multipal servers one same host.
Add support for passing arg as different bat file name.
This commit is contained in:
parent
d43de13e60
commit
aa15e8fc4d
Binary file not shown.
38
Program.cs
38
Program.cs
|
@ -1,17 +1,43 @@
|
|||
using System;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
using System.Threading;
|
||||
|
||||
namespace RustAutoStarter
|
||||
{
|
||||
class Program
|
||||
{
|
||||
static void Main(string[] args)
|
||||
{
|
||||
while (true)
|
||||
string startupfile = "CustomMap.bat"; //Sets default bat to run.
|
||||
if (args.Length == 1) //Checks if args have been passed
|
||||
startupfile = args[0]; //Sets passed args as the startup file to run.
|
||||
|
||||
//Check that starup bat exsists
|
||||
Console.WriteLine("Searching for startup bat " + Environment.CurrentDirectory + @"\" + startupfile);
|
||||
if (!File.Exists(Environment.CurrentDirectory + @"\" + startupfile))
|
||||
{
|
||||
Process[] pname = Process.GetProcessesByName("RustDedicated");
|
||||
if (pname.Length == 0)
|
||||
Console.WriteLine("Startup bat not found, If no args passed then default will be CustomMap.Bat");
|
||||
Console.ReadKey();
|
||||
Environment.Exit(0);
|
||||
}
|
||||
//Sets title of window to bat it will run.
|
||||
Console.Title = Environment.CurrentDirectory + @"\" + startupfile;
|
||||
while (true) //Makes it a constant loop
|
||||
{
|
||||
Process[] pname = Process.GetProcessesByName("RustDedicated"); //Gets all processes called RustDedicated
|
||||
//Loops though incase hosting multipal servers.
|
||||
bool found = false;
|
||||
foreach (Process p in pname)
|
||||
{
|
||||
if (Environment.CurrentDirectory == p.MainModule.FileName.Replace("\\RustDedicated.exe",""))
|
||||
{
|
||||
//Found so break for loop.
|
||||
found = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
//If not found then start up.
|
||||
if (!found)
|
||||
{
|
||||
DateTime now = DateTime.Now;
|
||||
Console.WriteLine("Rust server offline " + now);
|
||||
|
@ -21,7 +47,7 @@ namespace RustAutoStarter
|
|||
{
|
||||
proc = new Process();
|
||||
proc.StartInfo.WorkingDirectory = Environment.CurrentDirectory;
|
||||
proc.StartInfo.FileName = "CustomMap.bat";
|
||||
proc.StartInfo.FileName = startupfile;
|
||||
proc.Start();
|
||||
}
|
||||
catch (Exception ex)
|
||||
|
@ -29,7 +55,7 @@ namespace RustAutoStarter
|
|||
Console.WriteLine(ex.StackTrace.ToString());
|
||||
}
|
||||
}
|
||||
Thread.Sleep(10000);
|
||||
Thread.Sleep(10000); //Sleep for 10 secs
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -14,7 +14,7 @@
|
|||
<Deterministic>true</Deterministic>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
||||
<PlatformTarget>AnyCPU</PlatformTarget>
|
||||
<PlatformTarget>x64</PlatformTarget>
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
<DebugType>full</DebugType>
|
||||
<Optimize>false</Optimize>
|
||||
|
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Loading…
Reference in New Issue