Esempio n. 1
0
 /// <summary>
 /// event callback executed when the control + c combination is detected
 /// gracefully stops the server manager and waits for all tasks to finish
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private static async void OnCancelKey(object sender, ConsoleCancelEventArgs e)
 {
     ServerManager?.Stop();
     if (ApplicationTask != null)
     {
         await ApplicationTask;
     }
 }
Esempio n. 2
0
        public static void Main(string[] args)
        {
            AppDomain.CurrentDomain.SetData("DataDirectory", Utilities.OperatingDirectory);
            Console.OutputEncoding  = Encoding.UTF8;
            Console.ForegroundColor = ConsoleColor.Gray;

            Version = Utilities.GetVersionAsDouble();

            Console.WriteLine("=====================================================");
            Console.WriteLine(" IW4M ADMIN");
            Console.WriteLine(" by RaidMax ");
            Console.WriteLine($" Version {Utilities.GetVersionAsString()}");
            Console.WriteLine("=====================================================");

            Index loc = null;

            try
            {
                ServerManager = ApplicationManager.GetInstance();
                var configuration = ServerManager.GetApplicationSettings().Configuration();

                if (configuration != null)
                {
                    Localization.Configure.Initialize(configuration.EnableCustomLocale ? (configuration.CustomLocale ?? "windows-1252") : "windows-1252");
                }

                else
                {
                    Localization.Configure.Initialize();
                }

                loc = Utilities.CurrentLocalization.LocalizationIndex;
                Console.CancelKeyPress += new ConsoleCancelEventHandler(OnCancelKey);

                CheckDirectories();
                // do any needed migrations
                // todo: move out
                ConfigurationMigration.MoveConfigFolder10518(null);

                ServerManager.Logger.WriteInfo($"Version is {Version}");

                var api = API.Master.Endpoint.Get();

                var version = new API.Master.VersionInfo()
                {
                    CurrentVersionStable = 99.99f
                };

                try
                {
                    version = api.GetVersion().Result;
                }

                catch (Exception e)
                {
                    ServerManager.Logger.WriteWarning(loc["MANAGER_VERSION_FAIL"]);
                    while (e.InnerException != null)
                    {
                        e = e.InnerException;
                    }

                    ServerManager.Logger.WriteDebug(e.Message);
                }

                if (version.CurrentVersionStable == 99.99f)
                {
                    Console.ForegroundColor = ConsoleColor.Red;
                    Console.WriteLine(loc["MANAGER_VERSION_FAIL"]);
                    Console.ForegroundColor = ConsoleColor.Gray;
                }

#if !PRERELEASE
                else if (version.CurrentVersionStable > Version)
                {
                    Console.ForegroundColor = ConsoleColor.DarkYellow;
                    Console.WriteLine($"IW4MAdmin {loc["MANAGER_VERSION_UPDATE"]} [v{version.CurrentVersionStable.ToString("0.0")}]");
                    Console.WriteLine(loc["MANAGER_VERSION_CURRENT"].FormatExt($"[v{Version.ToString("0.0")}]"));
                    Console.ForegroundColor = ConsoleColor.Gray;
                }
#else
                else if (version.CurrentVersionPrerelease > Version)
                {
                    Console.ForegroundColor = ConsoleColor.DarkYellow;
                    Console.WriteLine($"IW4MAdmin-Prerelease {loc["MANAGER_VERSION_UPDATE"]} [v{version.CurrentVersionPrerelease.ToString("0.0")}-pr]");
                    Console.WriteLine(loc["MANAGER_VERSION_CURRENT"].FormatExt($"[v{Version.ToString("0.0")}-pr]"));
                    Console.ForegroundColor = ConsoleColor.Gray;
                }
#endif
                else
                {
                    Console.ForegroundColor = ConsoleColor.Green;
                    Console.WriteLine(loc["MANAGER_VERSION_SUCCESS"]);
                    Console.ForegroundColor = ConsoleColor.Gray;
                }

                ServerManager.Init().Wait();

                var consoleTask = Task.Run(async() =>
                {
                    string userInput;
                    var Origin = Utilities.IW4MAdminClient(ServerManager.Servers[0]);

                    do
                    {
                        userInput = Console.ReadLine();

                        if (userInput?.ToLower() == "quit")
                        {
                            ServerManager.Stop();
                        }

                        if (ServerManager.Servers.Count == 0)
                        {
                            Console.WriteLine(loc["MANAGER_CONSOLE_NOSERV"]);
                            continue;
                        }

                        if (userInput?.Length > 0)
                        {
                            GameEvent E = new GameEvent()
                            {
                                Type   = GameEvent.EventType.Command,
                                Data   = userInput,
                                Origin = Origin,
                                Owner  = ServerManager.Servers[0]
                            };

                            ServerManager.GetEventHandler().AddEvent(E);
                            await E.WaitAsync(30 * 1000);
                        }
                        Console.Write('>');
                    } while (ServerManager.Running);
                });
            }

            catch (Exception e)
            {
                string failMessage = loc == null ? "Failed to initalize IW4MAdmin" : loc["MANAGER_INIT_FAIL"];
                string exitMessage = loc == null ? "Press any key to exit..." : loc["MANAGER_EXIT"];

                Console.WriteLine(failMessage);
                while (e.InnerException != null)
                {
                    e = e.InnerException;
                }
                Console.WriteLine(e.Message);
                Console.WriteLine(exitMessage);
                Console.ReadKey();
                return;
            }

            if (ServerManager.GetApplicationSettings().Configuration().EnableWebFront)
            {
                Task.Run(() => WebfrontCore.Program.Init(ServerManager));
            }

            OnShutdownComplete.Reset();
            ServerManager.Start();
            ServerManager.Logger.WriteVerbose(loc["MANAGER_SHUTDOWN_SUCCESS"]);
            OnShutdownComplete.Set();
        }
Esempio n. 3
0
 private static void OnCancelKey(object sender, ConsoleCancelEventArgs e)
 {
     ServerManager.Stop();
     OnShutdownComplete.Wait();
 }
Esempio n. 4
0
        public static void Main(string[] args)
        {
            AppDomain.CurrentDomain.SetData("DataDirectory", OperatingDirectory);
            System.Diagnostics.Process.GetCurrentProcess().PriorityClass = System.Diagnostics.ProcessPriorityClass.BelowNormal;
            Localization.Configure.Initialize();
            var loc = Utilities.CurrentLocalization.LocalizationSet;

            Console.OutputEncoding = Encoding.UTF8;

            Version = Assembly.GetExecutingAssembly().GetName().Version.Major + Assembly.GetExecutingAssembly().GetName().Version.Minor / 10.0f;
            Version = Math.Round(Version, 2);

            Console.WriteLine("=====================================================");
            Console.WriteLine(" IW4M ADMIN");
            Console.WriteLine(" by RaidMax ");
            Console.WriteLine($" Version {Version.ToString("0.0")}");
            Console.WriteLine("=====================================================");

            try
            {
                using (var db = new DatabaseContext())
                    new ContextSeed(db).Seed().Wait();

                CheckDirectories();

                ServerManager = ApplicationManager.GetInstance();

                var api     = API.Master.Endpoint.Get();
                var version = new API.Master.VersionInfo()
                {
                    CurrentVersionStable = 99.99f
                };

                try
                {
                    version = api.GetVersion().Result;
                }

                catch (Exception e)
                {
                    ServerManager.Logger.WriteWarning(loc["MANAGER_VERSION_FAIL"]);
                    while (e.InnerException != null)
                    {
                        e = e.InnerException;
                    }

                    ServerManager.Logger.WriteDebug(e.Message);
                }

                if (version.CurrentVersionStable == 99.99f)
                {
                    Console.ForegroundColor = ConsoleColor.Red;
                    Console.WriteLine(loc["MANAGER_VERSION_FAIL"]);
                    Console.ForegroundColor = ConsoleColor.White;
                }

#if !PRERELEASE
                else if (version.CurrentVersionStable > Version)
                {
                    Console.ForegroundColor = ConsoleColor.DarkYellow;
                    Console.WriteLine($"IW4MAdmin {loc["MANAGER_VERSION_UPDATE"]} [v{version.CurrentVersionStable.ToString("0.0")}]");
                    Console.WriteLine($"{loc["MANAGER_VERSION_CURRENT"]} [v{Version.ToString("0.0")}]");
                    Console.ForegroundColor = ConsoleColor.White;
                }
#else
                else if (version.CurrentVersionPrerelease > Version)
                {
                    Console.ForegroundColor = ConsoleColor.DarkYellow;
                    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]");
                    Console.ForegroundColor = ConsoleColor.White;
                }
#endif
                else
                {
                    Console.ForegroundColor = ConsoleColor.Green;
                    Console.WriteLine(loc["MANAGER_VERSION_SUCCESS"]);
                    Console.ForegroundColor = ConsoleColor.White;
                }

                ServerManager.Init().Wait();

                var consoleTask = Task.Run(() =>
                {
                    String userInput;
                    Player Origin = ServerManager.GetClientService().Get(1).Result.AsPlayer();

                    do
                    {
                        userInput = Console.ReadLine();

                        if (userInput?.ToLower() == "quit")
                        {
                            ServerManager.Stop();
                        }

                        if (ServerManager.Servers.Count == 0)
                        {
                            Console.WriteLine("No servers are currently being monitored");
                            continue;
                        }

                        Origin.CurrentServer = ServerManager.Servers[0];
                        GameEvent E          = new GameEvent(GameEvent.EventType.Say, userInput, Origin, null, ServerManager.Servers[0]);
                        ServerManager.Servers[0].ExecuteEvent(E);
                        Console.Write('>');
                    } while (ServerManager.Running);
                });

                if (ServerManager.GetApplicationSettings().Configuration().EnableWebFront)
                {
                    Task.Run(() => WebfrontCore.Program.Init(ServerManager));
                }

                ServerManager.Start();
                ServerManager.Logger.WriteVerbose("Shutdown complete");
            }

            catch (Exception e)
            {
                Console.WriteLine(loc["MANAGER_INIT_FAIL"]);
                while (e.InnerException != null)
                {
                    e = e.InnerException;
                }
                Console.WriteLine($"Exception: {e.Message}");
                Console.WriteLine(loc["MANAGER_EXIT"]);
                Console.ReadKey();
            }
        }