コード例 #1
0
 protected override void OnException(Exception e) => ExceptionHandler.GenerateExceptionLog(e);
コード例 #2
0
        /// <summary>
        /// Program Entry Point
        /// </summary>
        /// <param name="args"></param>
        static void Main(string[] args)
        {
            // Create our version string
            string version = String.Concat(Version.Major, ".", Version.Minor, ".", Version.Build);

            // Setup the console
            Console.Title = $"Battlelog Master Gamespy Emulator v{version}";
            Console.WriteLine(@"__________         __    __  .__           _________             ");
            Console.WriteLine(@"\______   \_____ _/  |__/  |_|  |   ____  /   _____/_____ ___.__.");
            Console.WriteLine(@" |    |  _/\__  \\   __\   __\  | _/ __ \ \_____  \\____ <   |  |");
            Console.WriteLine(@" |    |   \ / __ \|  |  |  | |  |_\  ___/ /        \  |_> >___  |");
            Console.WriteLine(@" |______  /(____  /__|  |__| |____/\___  >_______  /   __// ____|");
            Console.WriteLine(@"        \/      \/                     \/        \/|__|   \/     ");
            Console.WriteLine();
            Console.WriteLine("--------------------------------------------------");
            Console.WriteLine("Battlefield 2 Master Gamespy Server Emulator v" + version);
            Console.WriteLine("Created for Battlelog.co by Wilson212");
            Console.WriteLine();

            // Start login servers
            try
            {
                // Make sure Logs dir is created
                if (!Directory.Exists(Path.Combine(RootPath, "Logs")))
                {
                    Directory.CreateDirectory(Path.Combine(RootPath, "Logs"));
                }

                // Wrap error log into a writer
                ErrorLog = new LogWriter(Path.Combine(RootPath, "Logs", "Error.log"), false);

                // Setup Exception Handle
                AppDomain.CurrentDomain.UnhandledException += ExceptionHandler.OnUnhandledException;
                Application.ThreadException += ExceptionHandler.OnThreadException;

                // Start the Gamespy Servers
                ServerManager.StartServers();
                Console.WriteLine();
                Console.Write("Cmd > ");
            }
            catch (Exception e)
            {
                // Display error
                Console.WriteLine(e.Message);
                Console.WriteLine(" *** An exception will be logged *** ");
                Console.WriteLine();
                Console.Write("Press any key to close...");

                // Create exception log and wait for key input
                ExceptionHandler.GenerateExceptionLog(e);
                Console.ReadLine();
                return;
            }

            // Main program loop
            while (IsRunning)
            {
                CheckInput();
            }

            // Shut login servers down
            Console.WriteLine("Shutting down local Gamespy sockets...");
            ServerManager.Shutdown();
        }