2017-05-26 18:49:27 -04:00
|
|
|
|
|
|
|
|
|
#define USINGMEMORY
|
2015-05-09 12:46:25 -04:00
|
|
|
|
using System;
|
2015-08-17 16:38:42 -04:00
|
|
|
|
using System.Runtime.InteropServices;
|
2015-08-20 01:06:44 -04:00
|
|
|
|
using SharedLibrary;
|
2017-05-26 18:49:27 -04:00
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
using System.IO;
|
2015-03-08 17:20:10 -04:00
|
|
|
|
|
|
|
|
|
namespace IW4MAdmin
|
|
|
|
|
{
|
|
|
|
|
class Program
|
|
|
|
|
{
|
2015-08-20 17:54:38 -04:00
|
|
|
|
static public double Version { get; private set; }
|
2017-05-26 18:49:27 -04:00
|
|
|
|
static private Manager ServerManager;
|
2015-03-09 00:28:57 -04:00
|
|
|
|
|
2015-03-08 17:20:10 -04:00
|
|
|
|
static void Main(string[] args)
|
|
|
|
|
{
|
2017-05-26 18:49:27 -04:00
|
|
|
|
Version = 1.3;
|
2015-08-17 16:38:42 -04:00
|
|
|
|
handler = new ConsoleEventDelegate(OnProcessExit);
|
|
|
|
|
SetConsoleCtrlHandler(handler, true);
|
|
|
|
|
|
2017-05-28 21:07:33 -04:00
|
|
|
|
double.TryParse(CheckUpdate(), out double latestVersion);
|
2015-03-09 00:28:57 -04:00
|
|
|
|
Console.WriteLine("=====================================================");
|
2015-03-09 16:11:09 -04:00
|
|
|
|
Console.WriteLine(" IW4M ADMIN");
|
2015-03-09 00:28:57 -04:00
|
|
|
|
Console.WriteLine(" by RaidMax ");
|
2015-03-09 21:28:37 -04:00
|
|
|
|
if (latestVersion != 0)
|
|
|
|
|
Console.WriteLine(" Version " + Version + " (latest " + latestVersion + ")");
|
2015-03-09 16:11:09 -04:00
|
|
|
|
else
|
2017-05-26 18:49:27 -04:00
|
|
|
|
Console.WriteLine(" Version " + Version + " (unable to retrieve latest)");
|
2015-03-09 00:28:57 -04:00
|
|
|
|
Console.WriteLine("=====================================================");
|
2015-07-06 15:51:08 -04:00
|
|
|
|
|
2017-05-26 18:49:27 -04:00
|
|
|
|
try
|
2015-07-06 15:51:08 -04:00
|
|
|
|
{
|
2017-05-26 18:49:27 -04:00
|
|
|
|
CheckDirectories();
|
2015-03-09 00:28:57 -04:00
|
|
|
|
|
2017-05-26 18:49:27 -04:00
|
|
|
|
ServerManager = Manager.GetInstance();
|
|
|
|
|
ServerManager.Init();
|
2015-03-09 00:28:57 -04:00
|
|
|
|
|
2017-06-01 13:42:28 -04:00
|
|
|
|
Task.Run(() =>
|
2017-05-26 18:49:27 -04:00
|
|
|
|
{
|
|
|
|
|
String userInput;
|
|
|
|
|
Player Origin = new Player("IW4MAdmin", "", -1, Player.Permission.Console, -1, "", 0, "");
|
2015-08-22 02:04:30 -04:00
|
|
|
|
|
2017-05-26 18:49:27 -04:00
|
|
|
|
do
|
|
|
|
|
{
|
|
|
|
|
userInput = Console.ReadLine();
|
|
|
|
|
if (userInput.ToLower() == "quit")
|
|
|
|
|
ServerManager.Stop();
|
|
|
|
|
|
|
|
|
|
if (ServerManager.Servers.Count == 0)
|
|
|
|
|
return;
|
2015-08-22 02:04:30 -04:00
|
|
|
|
|
2017-05-26 18:49:27 -04:00
|
|
|
|
Event E = new Event(Event.GType.Say, userInput, Origin, null, ServerManager.Servers[0]);
|
|
|
|
|
Origin.lastEvent = E;
|
|
|
|
|
ServerManager.Servers[0].ExecuteEvent(E);
|
|
|
|
|
Console.Write('>');
|
|
|
|
|
|
|
|
|
|
} while (userInput != null && ServerManager.Running);
|
2017-06-01 13:42:28 -04:00
|
|
|
|
});
|
2017-05-26 18:49:27 -04:00
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
catch(Exception e)
|
|
|
|
|
{
|
|
|
|
|
Console.WriteLine($"Fatal Error during initialization: {e.Message}");
|
|
|
|
|
Console.WriteLine("Press any key to exit...");
|
|
|
|
|
Console.ReadKey();
|
|
|
|
|
return;
|
|
|
|
|
}
|
2015-03-10 16:45:20 -04:00
|
|
|
|
|
2017-05-26 18:49:27 -04:00
|
|
|
|
ServerManager.Start();
|
2015-03-09 00:28:57 -04:00
|
|
|
|
}
|
2015-03-09 16:11:09 -04:00
|
|
|
|
|
2015-08-17 16:38:42 -04:00
|
|
|
|
static ConsoleEventDelegate handler;
|
|
|
|
|
|
|
|
|
|
static private bool OnProcessExit(int e)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
2017-05-26 18:49:27 -04:00
|
|
|
|
ServerManager.Stop();
|
|
|
|
|
return true;
|
2015-08-17 16:38:42 -04: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 18:49:27 -04:00
|
|
|
|
static private String CheckUpdate()
|
2015-03-09 16:11:09 -04:00
|
|
|
|
{
|
2015-03-09 21:28:37 -04:00
|
|
|
|
Connection Ver = new Connection("http://raidmax.org/IW4M/Admin/version.php");
|
2015-03-09 16:11:09 -04:00
|
|
|
|
return Ver.Read();
|
|
|
|
|
}
|
2015-03-10 16:45:20 -04:00
|
|
|
|
|
2017-05-26 18:49:27 -04:00
|
|
|
|
static void CheckDirectories()
|
2015-07-06 13:13:42 -04:00
|
|
|
|
{
|
2017-05-26 18:49:27 -04:00
|
|
|
|
if (!Directory.Exists("Lib"))
|
|
|
|
|
throw new Exception("Lib folder does not exist");
|
2015-07-06 13:13:42 -04:00
|
|
|
|
|
2017-05-26 18:49:27 -04: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 19:29:20 -04:00
|
|
|
|
|
|
|
|
|
if (!Directory.Exists("Plugins"))
|
|
|
|
|
Directory.CreateDirectory("Plugins");
|
2015-08-17 16:38:42 -04:00
|
|
|
|
}
|
2015-03-08 17:20:10 -04:00
|
|
|
|
}
|
|
|
|
|
}
|