IW4M-Admin/WebfrontCore/Application/Main.cs

106 lines
3.7 KiB
C#
Raw Normal View History


2015-05-09 12:46:25 -04:00
using System;
2015-08-17 16:38:42 -04:00
using System.Runtime.InteropServices;
using SharedLibrary;
using System.Threading.Tasks;
using System.IO;
using SharedLibrary.Objects;
2018-02-21 20:29:23 -05:00
using System.Reflection;
2018-03-06 02:22:19 -05:00
using System.Linq;
2018-02-21 20:29:23 -05:00
2015-03-08 17:20:10 -04:00
namespace IW4MAdmin
{
2018-02-21 20:29:23 -05:00
public class Program
2015-03-08 17:20:10 -04:00
{
2015-08-20 17:54:38 -04:00
static public double Version { get; private set; }
2018-02-21 20:29:23 -05:00
static public ApplicationManager ServerManager = ApplicationManager.GetInstance();
2018-03-06 02:22:19 -05:00
public static string OperatingDirectory = Path.GetDirectoryName(Assembly.GetEntryAssembly().Location) + Path.DirectorySeparatorChar;
public static void Start()
2015-03-08 17:20:10 -04:00
{
2018-02-21 20:29:23 -05:00
AppDomain.CurrentDomain.SetData("DataDirectory", OperatingDirectory);
System.Diagnostics.Process.GetCurrentProcess().PriorityClass = System.Diagnostics.ProcessPriorityClass.BelowNormal;
Version = 1.6;
2015-08-17 16:38:42 -04:00
Console.WriteLine("=====================================================");
Console.WriteLine(" IW4M ADMIN");
Console.WriteLine(" by RaidMax ");
Console.WriteLine($" Version {Version}");
Console.WriteLine("=====================================================");
try
{
/*var v1 = SharedLibrary.Helpers.Vector3.Parse("(737, 1117, 268)");
var v2 = SharedLibrary.Helpers.Vector3.Parse("(1510, 672.98, -228.66)");
double angleBetween = v1.AngleBetween(v2);*/
CheckDirectories();
ServerManager = ApplicationManager.GetInstance();
SharedLibrary.Database.Repair.Run(ServerManager.Logger);
ServerManager.Init().Wait();
Task.Run(() => ServerManager.Start());
2018-02-21 20:29:23 -05:00
Task.Run(() =>
{
String userInput;
Player Origin = ServerManager.GetClientService().Get(1).Result.AsPlayer();
do
{
userInput = Console.ReadLine();
if (userInput?.ToLower() == "quit")
ServerManager.Stop();
if (ServerManager.Servers.Count == 0)
return;
Origin.CurrentServer = ServerManager.Servers[0];
Event E = new Event(Event.GType.Say, userInput, Origin, null, ServerManager.Servers[0]);
ServerManager.Servers[0].ExecuteEvent(E);
Console.Write('>');
} while (ServerManager.Running);
2018-03-06 02:22:19 -05:00
Console.WriteLine("Shutdown complete");
});
}
catch (Exception e)
{
Console.WriteLine($"Fatal Error during initialization: {e.Message}");
Console.WriteLine("Press any key to exit...");
Console.ReadKey();
return;
}
}
static void CheckDirectories()
{
2018-02-21 20:29:23 -05:00
string curDirectory = Path.GetDirectoryName(Assembly.GetEntryAssembly().Location) + Path.DirectorySeparatorChar;
2018-02-21 20:29:23 -05:00
if (!Directory.Exists($"{curDirectory}Config"))
{
Console.WriteLine("Warning: Config folder does not exist");
2018-02-21 20:29:23 -05:00
Directory.CreateDirectory($"{curDirectory}Config");
}
2018-02-21 20:29:23 -05:00
if (!Directory.Exists($"{curDirectory}Config/Servers"))
Directory.CreateDirectory($"{curDirectory}Config/Servers");
2018-02-21 20:29:23 -05:00
if (!Directory.Exists($"{curDirectory}Logs"))
Directory.CreateDirectory($"{curDirectory}Logs");
2018-02-21 20:29:23 -05:00
if (!Directory.Exists($"{curDirectory}Plugins"))
Directory.CreateDirectory($"{curDirectory}Plugins");
2015-08-17 16:38:42 -04:00
}
2015-03-08 17:20:10 -04:00
}
}