IW4M-Admin/Admin/Main.cs

88 lines
2.8 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 double Version = 0.2;
2015-03-08 17:20:10 -04:00
static void Main(string[] args)
{
Console.WriteLine("=====================================================");
Console.WriteLine(" IW4M ADMIN");
Console.WriteLine(" by RaidMax ");
String latestVer = checkUpdate();
if (latestVer != null)
Console.WriteLine(" Version " + Version + " (latest " + latestVer + ")");
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
if (SV_CONF == null || SV_CONF.Length < 1)
{
setupConfig();
SV_CONF = new file("config\\servers.cfg").getParameters(3);
}
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.txt");
return Ver.Read();
}
2015-03-08 17:20:10 -04:00
}
}