BF2Statistics.BF2Server.Start C# (CSharp) Method

Start() public static method

Starts the Battlefield 2 Server application
public static Start ( BF2Mod Mod, string ExtraArgs, bool ShowConsole, bool MinConsole ) : void
Mod BF2Mod The battlefield 2 mod that the server is to use
ExtraArgs string Any arguments to be past to the application on startup
ShowConsole bool If false, a console will not be created
MinConsole bool If is enabled, true will start the console minimized
return void
        public static void Start(BF2Mod Mod, string ExtraArgs, bool ShowConsole, bool MinConsole)
        {
            // Make sure the server isnt running already
            if (IsRunning)
                throw new Exception("The Battlefield 2 server is already running!");

            // Make sure the mod is supported!
            if (!Mods.Contains(Mod))
                throw new Exception("The battlefield 2 mod cannot be located in the mods folder");

            // Start new BF2 proccess
            ProcessStartInfo Info = new ProcessStartInfo();
            Info.Arguments = String.Format(" +modPath mods/{0}", Mod.Name.ToLower());
            if (!String.IsNullOrEmpty(ExtraArgs))
                Info.Arguments += " " + ExtraArgs;

            // Hide window if user specifies this...
            if (!ShowConsole)
                Info.WindowStyle = ProcessWindowStyle.Hidden;
            else if (MinConsole)
                Info.WindowStyle = ProcessWindowStyle.Minimized;

            // Start process. Set working directory so we dont get errors!
            Info.FileName = "bf2_w32ded.exe";
            Info.WorkingDirectory = RootPath;
            ServerProcess = Process.Start(Info);

            // Hook into the proccess so we know when its running, and register a closing event
            ServerProcess.EnableRaisingEvents = true;
            ServerProcess.Exited += ServerProcess_Exited;

            // Call event
            if (Started != null)
                Started();
        }