Exemple #1
0
        public static void Main(string[] args)
        {
            AppDomain.CurrentDomain.ProcessExit        += new EventHandler(CurrentDomain_ProcessExit);
            AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(CurrentDomain_UnhandledException);

            // Migrate settings from previous version if available
            if (MasterServer.Settings.SettingsUpgradeRequired)
            {
                Console.WriteLine("Migrating application settings...");

                MasterServer.Settings.Upgrade();
                MasterServer.Settings.SettingsUpgradeRequired = false;
                MasterServer.Settings.Save();
            }

            // Bind default listen ports if not configured
            if (MasterServer.Settings.ListenPorts == null || MasterServer.Settings.ListenPorts.Count == 0)
            {
                Console.WriteLine("Configuring default listen port...");

                MasterServer.Settings.ListenPorts = new List <ushort>();
                MasterServer.Settings.ListenPorts.Add(Constants.DEFAULT_LISTEN_PORT);
                MasterServer.Settings.Save();
            }

            MasterServer.ListenPorts = "-";

            switch ((args.Length > 0) ? args[0] : null)
            {
            case "console":
                MasterServer.ConsoleMain(args);
                break;

            case "gui":
                MasterServer.GUIMain(args);
                break;

            case "install":
                MasterServerService.InstallService();
                break;

            case "uninstall":
                MasterServerService.UninstallService();
                break;

            default:
                if (ConsoleUtilities.InConsoleSession())
                {
                    MasterServer.ConsoleMain(args);
                }
                else
                {
                    service = new MasterServerService();
                    MasterServerService.ServiceMain(service, args);
                }

                break;
            }
        }
Exemple #2
0
        /// <summary>
        /// Get configured modules from the module manager
        /// </summary>
        /// <param name="gameStats">GameStats module will be returned in this variable</param>
        /// <param name="cdKeyValidator">CD Key Validator module will be returned in this variable</param>
        /// <returns>True if all modules were loaded correctly</returns>
        private static bool LoadConfiguredModules(out IGameStatsLog gameStats, out ICDKeyValidator cdKeyValidator)
        {
            Console.WriteLine("Initialising log writer module...");
            logWriter = ModuleManager.GetModule <ILogWriter>();

            ConsoleColor oldColour = Console.ForegroundColor;

            // Warn if the CD key validator module was not loaded
            if (logWriter == null)
            {
                Console.ForegroundColor = ConsoleColor.Red;
                Console.WriteLine("Configuration error: the specified log writer module was not loaded");
                Console.ForegroundColor = oldColour;

                MasterServer.Log("Configuration error: the specified log writer module was not loaded");

                if (!ConsoleUtilities.InConsoleSession())
                {
                    WinForms.MessageBox.Show("Configuration error: the specified log writer module was not loaded", "Configuration error", WinForms.MessageBoxButtons.OK);
                }
            }

            Console.WriteLine("Initialising GameStats module...");
            gameStats = ModuleManager.GetModule <IGameStatsLog>();

            // Warn if the GameStats module was not loaded
            if (gameStats == null)
            {
                Console.ForegroundColor = ConsoleColor.Red;
                Console.WriteLine("Configuration error: the specified gamestats module was not loaded");
                Console.ForegroundColor = oldColour;

                MasterServer.Log("Configuration error: the specified gamestats module was not loaded");

                if (!ConsoleUtilities.InConsoleSession())
                {
                    WinForms.MessageBox.Show("Configuration error: the specified gamestats module was not loaded", "Configuration error", WinForms.MessageBoxButtons.OK);
                }
            }

            Console.WriteLine("Initialising CD key validator module...");
            cdKeyValidator = ModuleManager.GetModule <ICDKeyValidator>();

            // Can't continue without a CD key validator module
            if (cdKeyValidator == null)
            {
                Console.ForegroundColor = ConsoleColor.Red;
                Console.WriteLine("Configuration error: the specified CD key validator module was not loaded");
                Console.WriteLine("Critical. Master server shutting down");
                Console.ForegroundColor = oldColour;

                if (!ConsoleUtilities.InConsoleSession())
                {
                    WinForms.MessageBox.Show("Configuration error: the specified CD key validator module was not loaded", "Critical error", WinForms.MessageBoxButtons.OK);
                }

                ReleaseModules();
                return(false);
            }

            Console.WriteLine();

            return(true);
        }