2018-04-09 15:17:10 -04:00
|
|
|
|
using System;
|
2017-05-26 18:49:27 -04:00
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
using System.IO;
|
2018-02-21 20:29:23 -05:00
|
|
|
|
using System.Reflection;
|
|
|
|
|
|
2018-04-09 15:17:10 -04:00
|
|
|
|
using SharedLibraryCore;
|
|
|
|
|
using SharedLibraryCore.Objects;
|
|
|
|
|
using SharedLibraryCore.Database;
|
2018-04-23 01:43:48 -04:00
|
|
|
|
using System.Text;
|
|
|
|
|
using System.Threading;
|
2018-05-05 16:36:26 -04:00
|
|
|
|
using SharedLibraryCore.Localization;
|
2018-10-12 22:28:22 -04:00
|
|
|
|
using IW4MAdmin.Application.Migration;
|
2018-04-09 15:17:10 -04:00
|
|
|
|
|
2018-04-08 14:48:40 -04:00
|
|
|
|
namespace IW4MAdmin.Application
|
2015-03-08 17:20:10 -04:00
|
|
|
|
{
|
2018-02-21 20:29:23 -05:00
|
|
|
|
public class Program
|
2015-03-08 17:20:10 -04:00
|
|
|
|
{
|
2015-08-20 17:54:38 -04:00
|
|
|
|
static public double Version { get; private set; }
|
2018-10-05 23:10:39 -04:00
|
|
|
|
static public ApplicationManager ServerManager;
|
2018-05-10 01:34:29 -04:00
|
|
|
|
private static ManualResetEventSlim OnShutdownComplete = new ManualResetEventSlim();
|
2015-03-09 00:28:57 -04:00
|
|
|
|
|
2018-04-08 14:48:40 -04:00
|
|
|
|
public static void Main(string[] args)
|
2015-03-08 17:20:10 -04:00
|
|
|
|
{
|
2018-12-31 21:52:19 -05:00
|
|
|
|
AppDomain.CurrentDomain.SetData("DataDirectory", Utilities.OperatingDirectory);
|
2018-04-23 01:43:48 -04:00
|
|
|
|
Console.OutputEncoding = Encoding.UTF8;
|
2018-04-26 02:13:04 -04:00
|
|
|
|
Console.ForegroundColor = ConsoleColor.Gray;
|
2017-11-19 01:44:11 -05:00
|
|
|
|
|
2018-09-13 15:34:42 -04:00
|
|
|
|
Version = Utilities.GetVersionAsDouble();
|
2015-08-17 16:38:42 -04:00
|
|
|
|
|
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 ");
|
2018-09-13 15:34:42 -04:00
|
|
|
|
Console.WriteLine($" Version {Utilities.GetVersionAsString()}");
|
2015-03-09 00:28:57 -04:00
|
|
|
|
Console.WriteLine("=====================================================");
|
2015-07-06 15:51:08 -04:00
|
|
|
|
|
2018-05-05 16:36:26 -04:00
|
|
|
|
Index loc = null;
|
|
|
|
|
|
2017-05-26 18:49:27 -04:00
|
|
|
|
try
|
2015-07-06 15:51:08 -04:00
|
|
|
|
{
|
2018-10-13 19:49:08 -04:00
|
|
|
|
ServerManager = ApplicationManager.GetInstance();
|
|
|
|
|
Localization.Configure.Initialize(ServerManager.GetApplicationSettings().Configuration()?.CustomLocale);
|
2018-10-12 19:59:17 -04:00
|
|
|
|
loc = Utilities.CurrentLocalization.LocalizationIndex;
|
2018-10-10 20:22:08 -04:00
|
|
|
|
Console.CancelKeyPress += new ConsoleCancelEventHandler(OnCancelKey);
|
|
|
|
|
|
2017-05-26 18:49:27 -04:00
|
|
|
|
CheckDirectories();
|
2018-10-12 22:28:22 -04:00
|
|
|
|
// do any needed migrations
|
|
|
|
|
// todo: move out
|
|
|
|
|
ConfigurationMigration.MoveConfigFolder10518(null);
|
2015-03-09 00:28:57 -04:00
|
|
|
|
|
2018-09-02 17:59:27 -04:00
|
|
|
|
ServerManager.Logger.WriteInfo($"Version is {Version}");
|
|
|
|
|
|
2018-04-19 01:48:14 -04:00
|
|
|
|
var api = API.Master.Endpoint.Get();
|
2018-05-08 00:58:46 -04:00
|
|
|
|
|
2018-04-19 01:48:14 -04:00
|
|
|
|
var version = new API.Master.VersionInfo()
|
|
|
|
|
{
|
|
|
|
|
CurrentVersionStable = 99.99f
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
version = api.GetVersion().Result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
catch (Exception e)
|
|
|
|
|
{
|
2018-04-22 16:04:18 -04:00
|
|
|
|
ServerManager.Logger.WriteWarning(loc["MANAGER_VERSION_FAIL"]);
|
2018-04-19 01:48:14 -04:00
|
|
|
|
while (e.InnerException != null)
|
|
|
|
|
{
|
|
|
|
|
e = e.InnerException;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ServerManager.Logger.WriteDebug(e.Message);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (version.CurrentVersionStable == 99.99f)
|
|
|
|
|
{
|
|
|
|
|
Console.ForegroundColor = ConsoleColor.Red;
|
2018-04-22 16:04:18 -04:00
|
|
|
|
Console.WriteLine(loc["MANAGER_VERSION_FAIL"]);
|
2018-04-26 02:13:04 -04:00
|
|
|
|
Console.ForegroundColor = ConsoleColor.Gray;
|
2018-04-19 01:48:14 -04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#if !PRERELEASE
|
|
|
|
|
else if (version.CurrentVersionStable > Version)
|
|
|
|
|
{
|
|
|
|
|
Console.ForegroundColor = ConsoleColor.DarkYellow;
|
2018-04-22 16:04:18 -04:00
|
|
|
|
Console.WriteLine($"IW4MAdmin {loc["MANAGER_VERSION_UPDATE"]} [v{version.CurrentVersionStable.ToString("0.0")}]");
|
|
|
|
|
Console.WriteLine($"{loc["MANAGER_VERSION_CURRENT"]} [v{Version.ToString("0.0")}]");
|
2018-04-26 02:13:04 -04:00
|
|
|
|
Console.ForegroundColor = ConsoleColor.Gray;
|
2018-04-19 01:48:14 -04:00
|
|
|
|
}
|
|
|
|
|
#else
|
|
|
|
|
else if (version.CurrentVersionPrerelease > Version)
|
|
|
|
|
{
|
|
|
|
|
Console.ForegroundColor = ConsoleColor.DarkYellow;
|
2018-04-22 16:04:18 -04:00
|
|
|
|
Console.WriteLine($"IW4MAdmin-Prerelease {loc["MANAGER_VERSION_UPDATE"]} [v{version.CurrentVersionPrerelease.ToString("0.0")}-pr]");
|
|
|
|
|
Console.WriteLine($"{loc["MANAGER_VERSION_CURRENT"]} [v{Version.ToString("0.0")}-pr]");
|
2018-04-26 02:13:04 -04:00
|
|
|
|
Console.ForegroundColor = ConsoleColor.Gray;
|
2018-04-19 01:48:14 -04:00
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
Console.ForegroundColor = ConsoleColor.Green;
|
2018-04-22 16:04:18 -04:00
|
|
|
|
Console.WriteLine(loc["MANAGER_VERSION_SUCCESS"]);
|
2018-04-26 02:13:04 -04:00
|
|
|
|
Console.ForegroundColor = ConsoleColor.Gray;
|
2018-04-19 01:48:14 -04:00
|
|
|
|
}
|
|
|
|
|
|
2018-03-13 17:30:22 -04:00
|
|
|
|
ServerManager.Init().Wait();
|
2018-02-21 20:29:23 -05:00
|
|
|
|
|
2018-08-30 21:53:00 -04:00
|
|
|
|
var consoleTask = Task.Run(async () =>
|
2017-05-26 18:49:27 -04:00
|
|
|
|
{
|
|
|
|
|
String userInput;
|
2018-11-05 22:01:29 -05:00
|
|
|
|
var Origin = Utilities.IW4MAdminClient(ServerManager.Servers[0]);
|
2015-08-22 02:04:30 -04:00
|
|
|
|
|
2017-05-26 18:49:27 -04:00
|
|
|
|
do
|
|
|
|
|
{
|
|
|
|
|
userInput = Console.ReadLine();
|
2017-06-12 13:50:00 -04:00
|
|
|
|
|
2017-08-08 22:44:52 -04:00
|
|
|
|
if (userInput?.ToLower() == "quit")
|
2017-05-26 18:49:27 -04:00
|
|
|
|
ServerManager.Stop();
|
|
|
|
|
|
|
|
|
|
if (ServerManager.Servers.Count == 0)
|
2018-04-19 01:48:14 -04:00
|
|
|
|
{
|
2018-04-26 02:13:04 -04:00
|
|
|
|
Console.WriteLine(loc["MANAGER_CONSOLE_NOSERV"]);
|
2018-04-19 01:48:14 -04:00
|
|
|
|
continue;
|
|
|
|
|
}
|
2015-08-22 02:04:30 -04:00
|
|
|
|
|
2018-05-03 01:25:49 -04:00
|
|
|
|
if (userInput?.Length > 0)
|
|
|
|
|
{
|
2018-05-10 01:34:29 -04:00
|
|
|
|
GameEvent E = new GameEvent()
|
|
|
|
|
{
|
|
|
|
|
Type = GameEvent.EventType.Command,
|
|
|
|
|
Data = userInput,
|
|
|
|
|
Origin = Origin,
|
|
|
|
|
Owner = ServerManager.Servers[0]
|
|
|
|
|
};
|
|
|
|
|
|
2018-05-03 01:25:49 -04:00
|
|
|
|
ServerManager.GetEventHandler().AddEvent(E);
|
2018-09-06 14:25:58 -04:00
|
|
|
|
await E.WaitAsync(30 * 1000);
|
2018-05-03 01:25:49 -04:00
|
|
|
|
}
|
2017-05-26 18:49:27 -04:00
|
|
|
|
Console.Write('>');
|
|
|
|
|
|
2018-02-27 22:27:23 -05:00
|
|
|
|
} while (ServerManager.Running);
|
2018-04-16 16:31:14 -04:00
|
|
|
|
});
|
2017-05-26 18:49:27 -04:00
|
|
|
|
}
|
|
|
|
|
|
2017-11-25 20:29:58 -05:00
|
|
|
|
catch (Exception e)
|
2017-05-26 18:49:27 -04:00
|
|
|
|
{
|
2018-04-22 16:04:18 -04:00
|
|
|
|
Console.WriteLine(loc["MANAGER_INIT_FAIL"]);
|
2018-04-09 15:17:10 -04:00
|
|
|
|
while (e.InnerException != null)
|
2018-03-13 20:12:24 -04:00
|
|
|
|
{
|
|
|
|
|
e = e.InnerException;
|
|
|
|
|
}
|
2018-10-12 19:59:17 -04:00
|
|
|
|
Console.WriteLine(e.Message);
|
2018-04-22 16:04:18 -04:00
|
|
|
|
Console.WriteLine(loc["MANAGER_EXIT"]);
|
2017-05-26 18:49:27 -04:00
|
|
|
|
Console.ReadKey();
|
2018-05-14 13:55:10 -04:00
|
|
|
|
return;
|
2017-05-26 18:49:27 -04:00
|
|
|
|
}
|
2018-04-26 02:13:04 -04:00
|
|
|
|
|
2018-05-10 01:34:29 -04:00
|
|
|
|
if (ServerManager.GetApplicationSettings().Configuration().EnableWebFront)
|
|
|
|
|
{
|
|
|
|
|
Task.Run(() => WebfrontCore.Program.Init(ServerManager));
|
|
|
|
|
}
|
2018-04-26 02:13:04 -04:00
|
|
|
|
|
2018-05-10 01:34:29 -04:00
|
|
|
|
OnShutdownComplete.Reset();
|
2018-08-27 18:07:54 -04:00
|
|
|
|
ServerManager.Start();
|
2018-04-26 02:13:04 -04:00
|
|
|
|
ServerManager.Logger.WriteVerbose(loc["MANAGER_SHUTDOWN_SUCCESS"]);
|
2018-05-10 01:34:29 -04:00
|
|
|
|
OnShutdownComplete.Set();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static void OnCancelKey(object sender, ConsoleCancelEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
ServerManager.Stop();
|
2018-10-05 23:10:39 -04:00
|
|
|
|
OnShutdownComplete.Wait();
|
2015-03-09 00:28:57 -04:00
|
|
|
|
}
|
2015-03-09 16:11:09 -04:00
|
|
|
|
|
2017-05-26 18:49:27 -04:00
|
|
|
|
static void CheckDirectories()
|
2015-07-06 13:13:42 -04:00
|
|
|
|
{
|
2018-10-05 23:10:39 -04:00
|
|
|
|
if (!Directory.Exists(Path.Join(Utilities.OperatingDirectory, "Plugins")))
|
|
|
|
|
{
|
|
|
|
|
Directory.CreateDirectory(Path.Join(Utilities.OperatingDirectory, "Plugins"));
|
|
|
|
|
}
|
2015-07-06 13:13:42 -04:00
|
|
|
|
|
2018-10-05 23:10:39 -04:00
|
|
|
|
if (!Directory.Exists(Path.Join(Utilities.OperatingDirectory, "Database")))
|
|
|
|
|
{
|
|
|
|
|
Directory.CreateDirectory(Path.Join(Utilities.OperatingDirectory, "Database"));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!Directory.Exists(Path.Join(Utilities.OperatingDirectory, "Log")))
|
|
|
|
|
{
|
|
|
|
|
Directory.CreateDirectory(Path.Join(Utilities.OperatingDirectory, "Log"));
|
|
|
|
|
}
|
2015-08-17 16:38:42 -04:00
|
|
|
|
}
|
2015-03-08 17:20:10 -04:00
|
|
|
|
}
|
|
|
|
|
}
|