void StartDDD() { if (Properties.Settings.Default.RunDDDServer) { System.Diagnostics.ProcessStartInfo procInfo = new System.Diagnostics.ProcessStartInfo(); procInfo.FileName = dddExecutablePathTextBox.Text; procInfo.WorkingDirectory = Path.GetDirectoryName(dddExecutablePathTextBox.Text); procInfo.Arguments = Properties.Settings.Default.DDDPort.ToString(); procInfo.CreateNoWindow = true; procInfo.UseShellExecute = true; m_dddProcess = System.Diagnostics.Process.Start(procInfo); Thread.Sleep(1000); } m_ddd = new DDDServerConnection(); m_ddd.ConnectToServer(Properties.Settings.Default.DDDHostname, Properties.Settings.Default.DDDPort); m_ddd.DDDClientPath = Properties.Settings.Default.DDDClientPath; if (!m_ddd.ReadSimModel()) { MessageBox.Show(String.Format("Unable to read sim model")); return; } }
private void buttonConnect_Click(object sender, EventArgs e) { _dddHostname = textBoxHostname.Text; if (Int32.TryParse(textBoxPort.Text, out _dddPort) == false) { return; } try { if (_connection != null) { lock (_connection) { if (_connection.IsConnected()) { if (!DisconnectCurrentDDDSession(true)) { throw new Exception("Unable to disconnect from DDD Server"); } } } } _connection = new DDDServerConnection(); string remoteSimulationModel = String.Format(@"\\{0}\DDDClient\SimulationModel.xml", _dddHostname); lock (_connection) { bool simModelResult = _connection.ReadSimModel(remoteSimulationModel); if (!simModelResult) { MessageBox.Show(String.Format("Error in DDD Connection: Failed to read the simulation model at '{0}', please try again.", remoteSimulationModel), "DDD Connection Error"); //AD: Here we could also ask the user to point to a local copy of the sim model, then re-ReadSimModel. return; } if (!_connection.ConnectToServer(_dddHostname, _dddPort)) { throw new Exception("Connection to DDD failed"); } //need Login as DM? no? _connection.RequestPlayers(); List<string> decisionMakers = new List<string>(); while (decisionMakers.Count == 0) { decisionMakers = _connection.Players; _connection.ProcessEvents(); } string selectedDM = decisionMakers[0]; ; _connection.LoginPlayer(selectedDM, "OBSERVER"); _connection.GetDMView(selectedDM); //initialize view... // _connection.AddEventCallback("TimeTick", new DDDServerConnection.ProcessSimulationEvent(TimeTick)); _connection.AddEventCallback("ExternalApp_SimStart", new DDDServerConnection.ProcessSimulationEvent(ExternalApp_SimStart)); _connection.AddEventCallback("ExternalApp_SimStop", new DDDServerConnection.ProcessSimulationEvent(ExternalApp_SimStop)); _connection.AddEventCallback("GameSpeed", new DDDServerConnection.ProcessSimulationEvent(GameSpeed)); } try { //just in case _dddLoopThread.Abort(); _dddLoopThread = null; } catch (Exception ex) { } _dddLoopThread = new Thread(new ThreadStart(DDDLoop)); _dddLoopThread.Start(); } catch (Exception ex) { MessageBox.Show("Error connecting to DDD Server:\r\n" + ex.Message); return; } UpdateDDDConnectionStatus("CONNECTED"); ((Button)sender).Enabled = false; groupBox2.Enabled = true; groupBox3.Enabled = true; }