IW4M-Admin/Admin/Main.cs

88 lines
2.9 KiB
C#
Raw Normal View History

2015-03-08 17:20:10 -04:00
using System;
using System.Collections.Generic;
using System.Text;
using System.Threading;
2015-03-08 17:20:10 -04:00
namespace IW4MAdmin
{
class Program
{
static String IP;
static int Port;
static String RCON;
static public double Version = 0.2;
static public double latestVersion;
2015-03-08 17:20:10 -04:00
static void Main(string[] args)
{
double.TryParse(checkUpdate(), out latestVersion);
Console.WriteLine("=====================================================");
Console.WriteLine(" IW4M ADMIN");
Console.WriteLine(" by RaidMax ");
if (latestVersion != 0)
Console.WriteLine(" Version " + Version + " (latest " + latestVersion + ")");
else
Console.WriteLine(" Version " + Version + " (unable to retrieve latest)");
Console.WriteLine("=====================================================");
2015-03-08 17:20:10 -04:00
file Config = new file("config\\servers.cfg");
String[] SV_CONF = Config.readAll();
2015-03-08 17:20:10 -04:00
2015-03-09 21:34:31 -04:00
if (SV_CONF == null || SV_CONF.Length < 1 || SV_CONF[0] == String.Empty)
{
setupConfig();
2015-03-09 21:34:31 -04:00
SV_CONF = new file("config\\servers.cfg").readAll();
}
2015-03-08 17:20:10 -04:00
if (Config.getSize() > 0 && SV_CONF != null)
{
foreach (String S in SV_CONF)
{
if (S.Length < 1)
continue;
String[] sv = S.Split(':');
Console.WriteLine("Starting admin on port " + sv[1]);
Server IW4M;
IW4M = new Server(sv[0], Convert.ToInt32(sv[1]), sv[2]);
2015-03-08 17:20:10 -04:00
//Threading seems best here
Thread monitorThread = new Thread(new ThreadStart(IW4M.Monitor));
monitorThread.Start();
}
2015-03-08 17:20:10 -04:00
}
else
{
Console.WriteLine("[FATAL] CONFIG FILE DOES NOT EXIST OR IS INCORRECT!");
Utilities.Wait(5);
}
}
static void setupConfig()
{
Console.WriteLine("Hey there, it looks like you haven't set up a server yet. Let's get started!");
Console.Write("Please enter the IP: ");
IP = Console.ReadLine();
Console.Write("Please enter the Port: ");
Port = Convert.ToInt32(Console.ReadLine());
Console.Write("Please enter the RCON password: ");
RCON = Console.ReadLine();
file Config = new file("config\\servers.cfg", true);
Config.Write(IP + ":" + Port + ":" + RCON);
Console.WriteLine("Great! Let's go ahead and start 'er up.");
}
static String checkUpdate()
{
Connection Ver = new Connection("http://raidmax.org/IW4M/Admin/version.php");
return Ver.Read();
}
2015-03-08 17:20:10 -04:00
}
}