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-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-02-21 20:29:23 -05:00
|
|
|
|
static public ApplicationManager ServerManager = ApplicationManager.GetInstance();
|
2018-03-06 02:22:19 -05:00
|
|
|
|
public static string OperatingDirectory = Path.GetDirectoryName(Assembly.GetEntryAssembly().Location) + Path.DirectorySeparatorChar;
|
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-02-21 20:29:23 -05:00
|
|
|
|
AppDomain.CurrentDomain.SetData("DataDirectory", OperatingDirectory);
|
2017-11-19 01:44:11 -05:00
|
|
|
|
System.Diagnostics.Process.GetCurrentProcess().PriorityClass = System.Diagnostics.ProcessPriorityClass.BelowNormal;
|
2018-04-22 16:04:18 -04:00
|
|
|
|
Localization.Configure.Initialize();
|
|
|
|
|
var loc = Utilities.CurrentLocalization.LocalizationSet;
|
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-04-08 17:50:58 -04:00
|
|
|
|
Version = Assembly.GetExecutingAssembly().GetName().Version.Major + Assembly.GetExecutingAssembly().GetName().Version.Minor / 10.0f;
|
2018-04-23 01:43:48 -04:00
|
|
|
|
Version = Math.Round(Version, 2);
|
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-04-19 01:48:14 -04:00
|
|
|
|
Console.WriteLine($" Version {Version.ToString("0.0")}");
|
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
|
|
|
|
|
2018-03-13 17:30:22 -04:00
|
|
|
|
ServerManager = ApplicationManager.GetInstance();
|
2018-04-19 01:48:14 -04:00
|
|
|
|
|
2018-04-26 20:19:42 -04:00
|
|
|
|
using (var db = new DatabaseContext(ServerManager.GetApplicationSettings().Configuration()?.ConnectionString))
|
2018-04-25 02:38:59 -04:00
|
|
|
|
new ContextSeed(db).Seed().Wait();
|
|
|
|
|
|
2018-04-19 01:48:14 -04:00
|
|
|
|
var api = API.Master.Endpoint.Get();
|
|
|
|
|
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-04-19 01:48:14 -04:00
|
|
|
|
var consoleTask = Task.Run(() =>
|
2017-05-26 18:49:27 -04:00
|
|
|
|
{
|
|
|
|
|
String userInput;
|
2017-11-25 20:29:58 -05:00
|
|
|
|
Player Origin = ServerManager.GetClientService().Get(1).Result.AsPlayer();
|
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
|
|
|
|
|
2017-11-25 20:29:58 -05:00
|
|
|
|
Origin.CurrentServer = ServerManager.Servers[0];
|
2018-04-19 01:48:14 -04:00
|
|
|
|
GameEvent E = new GameEvent(GameEvent.EventType.Say, userInput, Origin, null, ServerManager.Servers[0]);
|
2018-04-26 02:13:04 -04:00
|
|
|
|
ServerManager.GetEventHandler().AddEvent(E);
|
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
|
|
|
|
|
2018-04-16 16:31:14 -04:00
|
|
|
|
if (ServerManager.GetApplicationSettings().Configuration().EnableWebFront)
|
|
|
|
|
{
|
2018-04-28 01:22:18 -04:00
|
|
|
|
Task.Run(() =>
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
WebfrontCore.Program.Init(ServerManager);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
catch (Exception e)
|
|
|
|
|
{
|
|
|
|
|
ServerManager.Logger.WriteWarning("Webfront had unhandled exception");
|
|
|
|
|
ServerManager.Logger.WriteDebug(e.Message);
|
|
|
|
|
}
|
|
|
|
|
});
|
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-04-19 01:48:14 -04:00
|
|
|
|
Console.WriteLine($"Exception: {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-04-26 02:13:04 -04:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ServerManager.Start();
|
|
|
|
|
ServerManager.Logger.WriteVerbose(loc["MANAGER_SHUTDOWN_SUCCESS"]);
|
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-02-21 20:29:23 -05:00
|
|
|
|
string curDirectory = Path.GetDirectoryName(Assembly.GetEntryAssembly().Location) + Path.DirectorySeparatorChar;
|
2015-07-06 13:13:42 -04:00
|
|
|
|
|
2018-02-21 20:29:23 -05:00
|
|
|
|
if (!Directory.Exists($"{curDirectory}Plugins"))
|
|
|
|
|
Directory.CreateDirectory($"{curDirectory}Plugins");
|
2015-08-17 16:38:42 -04:00
|
|
|
|
}
|
2015-03-08 17:20:10 -04:00
|
|
|
|
}
|
|
|
|
|
}
|