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();
}