2017-05-26 17:49:27 -05:00
|
|
|
|
|
|
|
|
|
#define USINGMEMORY
|
2015-05-09 11:46:25 -05:00
|
|
|
|
using System;
|
2015-08-17 15:38:42 -05:00
|
|
|
|
using System.Runtime.InteropServices;
|
2015-08-20 00:06:44 -05:00
|
|
|
|
using SharedLibrary;
|
2017-05-26 17:49:27 -05:00
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
using System.IO;
|
2018-02-06 23:19:06 -06:00
|
|
|
|
using SharedLibrary.Objects;
|
2015-03-08 16:20:10 -05:00
|
|
|
|
|
2017-11-25 19:29:58 -06:00
|
|
|
|
#if DEBUG
|
|
|
|
|
using SharedLibrary.Database;
|
|
|
|
|
#endif
|
|
|
|
|
|
2015-03-08 16:20:10 -05:00
|
|
|
|
namespace IW4MAdmin
|
|
|
|
|
{
|
|
|
|
|
class Program
|
|
|
|
|
{
|
2015-08-20 16:54:38 -05:00
|
|
|
|
static public double Version { get; private set; }
|
2017-06-19 13:58:01 -04:00
|
|
|
|
static private ApplicationManager ServerManager;
|
2015-03-08 23:28:57 -05:00
|
|
|
|
|
2015-03-08 16:20:10 -05:00
|
|
|
|
static void Main(string[] args)
|
|
|
|
|
{
|
2017-11-19 00:44:11 -06:00
|
|
|
|
System.Diagnostics.Process.GetCurrentProcess().PriorityClass = System.Diagnostics.ProcessPriorityClass.BelowNormal;
|
|
|
|
|
|
2017-11-16 17:09:19 -06:00
|
|
|
|
Version = 1.6;
|
2015-08-17 15:38:42 -05:00
|
|
|
|
handler = new ConsoleEventDelegate(OnProcessExit);
|
|
|
|
|
SetConsoleCtrlHandler(handler, true);
|
|
|
|
|
|
2017-08-08 21:44:52 -05:00
|
|
|
|
//double.TryParse(CheckUpdate(), out double latestVersion);
|
2015-03-08 23:28:57 -05:00
|
|
|
|
Console.WriteLine("=====================================================");
|
2015-03-09 15:11:09 -05:00
|
|
|
|
Console.WriteLine(" IW4M ADMIN");
|
2015-03-08 23:28:57 -05:00
|
|
|
|
Console.WriteLine(" by RaidMax ");
|
2017-08-08 21:44:52 -05:00
|
|
|
|
Console.WriteLine($" Version {Version}");
|
2015-03-08 23:28:57 -05:00
|
|
|
|
Console.WriteLine("=====================================================");
|
2015-07-06 14:51:08 -05:00
|
|
|
|
|
2017-05-26 17:49:27 -05:00
|
|
|
|
try
|
2015-07-06 14:51:08 -05:00
|
|
|
|
{
|
2017-05-26 17:49:27 -05:00
|
|
|
|
CheckDirectories();
|
2015-03-08 23:28:57 -05:00
|
|
|
|
|
2017-06-19 13:58:01 -04:00
|
|
|
|
ServerManager = ApplicationManager.GetInstance();
|
2017-05-26 17:49:27 -05:00
|
|
|
|
ServerManager.Init();
|
2015-03-08 23:28:57 -05:00
|
|
|
|
|
2017-06-01 12:42:28 -05:00
|
|
|
|
Task.Run(() =>
|
2017-05-26 17:49:27 -05:00
|
|
|
|
{
|
|
|
|
|
String userInput;
|
2017-11-25 19:29:58 -06:00
|
|
|
|
Player Origin = ServerManager.GetClientService().Get(1).Result.AsPlayer();
|
2015-08-22 01:04:30 -05:00
|
|
|
|
|
2017-05-26 17:49:27 -05:00
|
|
|
|
do
|
|
|
|
|
{
|
|
|
|
|
userInput = Console.ReadLine();
|
2017-06-12 13:50:00 -04:00
|
|
|
|
|
2017-08-08 21:44:52 -05:00
|
|
|
|
if (userInput?.ToLower() == "quit")
|
2017-05-26 17:49:27 -05:00
|
|
|
|
ServerManager.Stop();
|
|
|
|
|
|
|
|
|
|
if (ServerManager.Servers.Count == 0)
|
|
|
|
|
return;
|
2015-08-22 01:04:30 -05:00
|
|
|
|
|
2017-11-25 19:29:58 -06:00
|
|
|
|
Origin.CurrentServer = ServerManager.Servers[0];
|
2017-05-26 17:49:27 -05:00
|
|
|
|
Event E = new Event(Event.GType.Say, userInput, Origin, null, ServerManager.Servers[0]);
|
|
|
|
|
ServerManager.Servers[0].ExecuteEvent(E);
|
|
|
|
|
Console.Write('>');
|
|
|
|
|
|
2017-06-12 13:50:00 -04:00
|
|
|
|
} while (ServerManager.Running);
|
2017-06-01 12:42:28 -05:00
|
|
|
|
});
|
2017-05-26 17:49:27 -05:00
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
2017-11-25 19:29:58 -06:00
|
|
|
|
catch (Exception e)
|
2017-05-26 17:49:27 -05:00
|
|
|
|
{
|
|
|
|
|
Console.WriteLine($"Fatal Error during initialization: {e.Message}");
|
|
|
|
|
Console.WriteLine("Press any key to exit...");
|
|
|
|
|
Console.ReadKey();
|
|
|
|
|
return;
|
|
|
|
|
}
|
2015-03-10 15:45:20 -05:00
|
|
|
|
|
2018-02-06 23:19:06 -06:00
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
ServerManager.Start();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
catch (Exception e)
|
|
|
|
|
{
|
|
|
|
|
throw e;
|
|
|
|
|
}
|
2015-03-08 23:28:57 -05:00
|
|
|
|
}
|
2015-03-09 15:11:09 -05:00
|
|
|
|
|
2015-08-17 15:38:42 -05:00
|
|
|
|
static ConsoleEventDelegate handler;
|
|
|
|
|
|
|
|
|
|
static private bool OnProcessExit(int e)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
2017-05-26 17:49:27 -05:00
|
|
|
|
ServerManager.Stop();
|
|
|
|
|
return true;
|
2015-08-17 15:38:42 -05:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
catch
|
|
|
|
|
{
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private delegate bool ConsoleEventDelegate(int eventType);
|
|
|
|
|
[DllImport("kernel32.dll", SetLastError = true)]
|
|
|
|
|
private static extern bool SetConsoleCtrlHandler(ConsoleEventDelegate callback, bool add);
|
|
|
|
|
|
2017-05-26 17:49:27 -05:00
|
|
|
|
static void CheckDirectories()
|
2015-07-06 12:13:42 -05:00
|
|
|
|
{
|
2017-05-26 17:49:27 -05:00
|
|
|
|
if (!Directory.Exists("Lib"))
|
|
|
|
|
throw new Exception("Lib folder does not exist");
|
2015-07-06 12:13:42 -05:00
|
|
|
|
|
2017-05-26 17:49:27 -05:00
|
|
|
|
if (!Directory.Exists("Config"))
|
|
|
|
|
{
|
|
|
|
|
Console.WriteLine("Warning: Config folder does not exist");
|
|
|
|
|
Directory.CreateDirectory("Config");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!Directory.Exists("Config/Servers"))
|
|
|
|
|
Directory.CreateDirectory("Config/Servers");
|
|
|
|
|
|
|
|
|
|
if (!Directory.Exists("Logs"))
|
|
|
|
|
Directory.CreateDirectory("Logs");
|
|
|
|
|
|
|
|
|
|
if (!Directory.Exists("Database"))
|
|
|
|
|
Directory.CreateDirectory("Database");
|
2017-05-27 18:29:20 -05:00
|
|
|
|
|
|
|
|
|
if (!Directory.Exists("Plugins"))
|
|
|
|
|
Directory.CreateDirectory("Plugins");
|
2015-08-17 15:38:42 -05:00
|
|
|
|
}
|
2015-03-08 16:20:10 -05:00
|
|
|
|
}
|
|
|
|
|
}
|