2015-05-09 12:46:25 -04:00
|
|
|
|
#define USINGMEMORY
|
|
|
|
|
using System;
|
2015-03-08 17:20:10 -04:00
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Text;
|
2015-03-09 16:11:09 -04:00
|
|
|
|
using System.Threading;
|
2015-08-17 16:38:42 -04:00
|
|
|
|
using System.Runtime.InteropServices;
|
2015-08-20 01:06:44 -04:00
|
|
|
|
using SharedLibrary;
|
2015-03-08 17:20:10 -04:00
|
|
|
|
|
|
|
|
|
namespace IW4MAdmin
|
|
|
|
|
{
|
|
|
|
|
class Program
|
|
|
|
|
{
|
2015-08-17 16:38:42 -04:00
|
|
|
|
static public double Version = 0.92;
|
2015-03-09 21:28:37 -04:00
|
|
|
|
static public double latestVersion;
|
2015-05-09 12:46:25 -04:00
|
|
|
|
static public bool usingMemory = true;
|
2015-07-06 13:13:42 -04:00
|
|
|
|
static private Manager serverManager;
|
2015-08-20 01:06:44 -04:00
|
|
|
|
static private IW4MAdmin_Web.WebFront frontEnd;
|
2015-03-09 00:28:57 -04:00
|
|
|
|
|
2015-03-08 17:20:10 -04:00
|
|
|
|
static void Main(string[] args)
|
|
|
|
|
{
|
2015-08-17 16:38:42 -04:00
|
|
|
|
handler = new ConsoleEventDelegate(OnProcessExit);
|
|
|
|
|
SetConsoleCtrlHandler(handler, true);
|
|
|
|
|
|
2015-03-09 21:28:37 -04:00
|
|
|
|
double.TryParse(checkUpdate(), out 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
|
|
|
|
|
Console.WriteLine(" Version " + Version + " (unable to retrieve latest)");
|
2015-03-09 00:28:57 -04:00
|
|
|
|
Console.WriteLine("=====================================================");
|
2015-08-20 01:06:44 -04:00
|
|
|
|
|
2015-07-06 15:51:08 -04:00
|
|
|
|
serverManager = new IW4MAdmin.Manager();
|
|
|
|
|
|
|
|
|
|
Thread serverMGRThread = new Thread(serverManager.Init);
|
2015-08-20 01:06:44 -04:00
|
|
|
|
serverMGRThread.Name = "Server Manager thread";
|
2015-07-06 15:51:08 -04:00
|
|
|
|
serverMGRThread.Start();
|
|
|
|
|
|
|
|
|
|
while(!serverManager.isReady())
|
|
|
|
|
{
|
|
|
|
|
Utilities.Wait(1);
|
|
|
|
|
}
|
2015-03-09 00:28:57 -04:00
|
|
|
|
|
2015-07-06 13:13:42 -04:00
|
|
|
|
if (serverManager.getServers() != null)
|
2015-08-17 16:38:42 -04:00
|
|
|
|
Program.getManager().mainLog.Write("IW4M Now Initialized! Visit http://127.0.0.1:1624 for server overview.");
|
2015-03-09 00:28:57 -04:00
|
|
|
|
|
2015-07-17 18:53:51 -04:00
|
|
|
|
if (serverManager.getServers().Count > 0)
|
|
|
|
|
{
|
2015-08-20 01:06:44 -04:00
|
|
|
|
frontEnd = new IW4MAdmin_Web.WebFront();
|
2015-07-17 18:53:51 -04:00
|
|
|
|
frontEnd.Init();
|
|
|
|
|
}
|
2015-03-10 16:45:20 -04:00
|
|
|
|
|
2015-08-20 01:06:44 -04:00
|
|
|
|
serverMGRThread.Join();
|
|
|
|
|
serverManager.mainLog.Write("Shutting down IW4MAdmin...", Log.Level.Debug);
|
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
|
|
|
|
|
{
|
|
|
|
|
foreach (Server S in IW4MAdmin.Program.getServers())
|
|
|
|
|
{
|
|
|
|
|
if (S == null)
|
|
|
|
|
continue;
|
|
|
|
|
|
2015-08-20 01:06:44 -04:00
|
|
|
|
S.isRunning = false;
|
|
|
|
|
|
|
|
|
|
if (Utilities.shutdownInterface(S.pID()))
|
2015-08-17 16:38:42 -04:00
|
|
|
|
Program.getManager().mainLog.Write("Successfully removed IW4MAdmin from server with PID " + S.pID(), Log.Level.Debug);
|
|
|
|
|
else
|
|
|
|
|
Program.getManager().mainLog.Write("Could not remove IW4MAdmin from server with PID " + S.pID(), Log.Level.Debug);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Program.getManager().shutDown();
|
2015-08-20 01:06:44 -04:00
|
|
|
|
frontEnd.webSchedule.Stop();
|
|
|
|
|
frontEnd.webSchedule.Dispose();
|
2015-08-17 16:38:42 -04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
catch
|
|
|
|
|
{
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private delegate bool ConsoleEventDelegate(int eventType);
|
|
|
|
|
[DllImport("kernel32.dll", SetLastError = true)]
|
|
|
|
|
private static extern bool SetConsoleCtrlHandler(ConsoleEventDelegate callback, bool add);
|
|
|
|
|
|
2015-07-06 13:13:42 -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
|
|
|
|
|
2015-07-06 15:51:08 -04:00
|
|
|
|
static public Server[] getServers()
|
2015-07-06 13:13:42 -04:00
|
|
|
|
{
|
2015-07-06 15:51:08 -04:00
|
|
|
|
return serverManager.getServers().ToArray();
|
2015-07-06 13:13:42 -04:00
|
|
|
|
}
|
|
|
|
|
|
2015-08-17 16:38:42 -04:00
|
|
|
|
static public Manager getManager()
|
|
|
|
|
{
|
|
|
|
|
return serverManager;
|
|
|
|
|
}
|
|
|
|
|
|
2015-07-24 15:46:32 -04:00
|
|
|
|
#if DEBUG2
|
2015-03-10 16:45:20 -04:00
|
|
|
|
static List<Server> checkConfig()
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
file Config = new file("config\\servers.cfg");
|
|
|
|
|
String[] SV_CONF = Config.readAll();
|
|
|
|
|
List<Server> Servers = new List<Server>();
|
2015-03-10 17:56:01 -04:00
|
|
|
|
Config.Close();
|
2015-03-10 16:45:20 -04:00
|
|
|
|
|
|
|
|
|
if (SV_CONF == null || SV_CONF.Length < 1 || SV_CONF[0] == String.Empty)
|
|
|
|
|
{
|
|
|
|
|
setupConfig(); // get our first time server
|
2015-03-10 17:56:01 -04:00
|
|
|
|
Config = new file("config\\servers.cfg", true);
|
2015-03-10 16:45:20 -04:00
|
|
|
|
Config.Write(IP + ':' + Port + ':' + RCON);
|
2015-03-10 17:56:01 -04:00
|
|
|
|
Config.Close();
|
2015-05-09 12:46:25 -04:00
|
|
|
|
Servers.Add(new Server(IP, Port, RCON, 0));
|
2015-03-10 16:45:20 -04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
foreach (String L in SV_CONF)
|
|
|
|
|
{
|
|
|
|
|
String[] server_line = L.Split(':');
|
|
|
|
|
int newPort;
|
|
|
|
|
if (server_line.Length < 3 || !int.TryParse(server_line[1], out newPort))
|
|
|
|
|
{
|
|
|
|
|
Console.WriteLine("You have an error in your server.cfg");
|
|
|
|
|
continue;
|
|
|
|
|
}
|
2015-05-09 12:46:25 -04:00
|
|
|
|
Servers.Add(new Server(server_line[0], newPort, server_line[2],0));
|
2015-03-10 16:45:20 -04:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return Servers;
|
|
|
|
|
}
|
2015-07-03 00:10:01 -04:00
|
|
|
|
#endif
|
2015-03-08 17:20:10 -04:00
|
|
|
|
}
|
|
|
|
|
}
|