public int GetTrackIndex(string track, string layout) { int index = -1; for (int i = 0; i < this.Sessions.Count; i++) { if (this.Sessions[i] is RaceSession) { RaceSession session = (RaceSession)this.Sessions[i]; if (session.Track == track && session.Layout == layout) { index = i; break; } } else if (this.Sessions[i] is RaceConfig) { if (this.Sessions[i].ToString() == track) { index = i; break; } } } return(index); }
public void StartServer() { this.StopServer(); if (this.HasCycle) { if (this.cycle >= this.Sessions.Count) { this.cycle = 0; } if (this.Sessions[this.cycle] is RaceSession) { RaceSession session = (RaceSession)this.Sessions[this.cycle]; StreamWriter sw = new StreamWriter(this.server_cfg); foreach (string line in this.iniLines) { string outLine = line; if (line.StartsWith("TRACK=", StringComparison.InvariantCultureIgnoreCase)) { outLine = "TRACK=" + session.Track; } if (line.StartsWith("CONFIG_TRACK=", StringComparison.InvariantCultureIgnoreCase)) { outLine = "CONFIG_TRACK=" + session.Layout; } if (line.StartsWith("LAPS=", StringComparison.InvariantCultureIgnoreCase)) { outLine = "LAPS=" + session.Laps; } sw.WriteLine(outLine); } sw.Dispose(); } else if (this.Sessions[this.cycle] is RaceConfig) { string cfgDir = ((RaceConfig)this.Sessions[this.cycle]).Directory; if (Directory.Exists(cfgDir)) { string newcfg = Path.Combine(cfgDir, "server_cfg.ini"); if (File.Exists(newcfg)) { File.Copy(newcfg, this.server_cfg, true); } string newentrylist = Path.Combine(cfgDir, "entry_list.ini"); if (File.Exists(newcfg)) { File.Copy(newentrylist, this.entry_list, true); } } } this.votes = new byte[this.Sessions.Count]; this.votedIds = new List <string>(); } string servername, track, layout; int laps; List <object> tmpS = new List <object>(); string[] tmpL; ReadCfg(this.PluginManager.Config, false, out servername, out track, out layout, out laps, ref tmpS, out tmpL); this.serverInstance = new Process(); this.serverInstance.StartInfo.FileName = Path.Combine(this.serverDirectory, this.serverExe); this.serverInstance.StartInfo.WorkingDirectory = this.serverDirectory; this.serverInstance.StartInfo.RedirectStandardError = true; this.serverInstance.StartInfo.RedirectStandardOutput = true; this.serverInstance.StartInfo.UseShellExecute = false; this.serverInstance.StartInfo.CreateNoWindow = !this.createServerWindow; this.serverInstance.OutputDataReceived += this.process_OutputDataReceived; this.serverInstance.ErrorDataReceived += this.process_OutputDataReceived; this.serverInstance.StartInfo.WindowStyle = ProcessWindowStyle.Minimized; this.serverInstance.Start(); this.serverInstance.BeginOutputReadLine(); this.serverInstance.BeginErrorReadLine(); if (this.PluginManager != null) { Thread.Sleep(1000); //this.pluginManager.MaxClients = maxClients; this.PluginManager.Connect(); } foreach (string additionalExe in this.additionalExes) { ProcessStartInfo startInfo = new ProcessStartInfo(additionalExe); startInfo.WindowStyle = ProcessWindowStyle.Minimized; this.additionalProcesses.Add(Process.Start(startInfo)); } }