コード例 #1
0
 private void okButton_Click(object sender, EventArgs e)
 {
     if (m_serverConnection.IsConnected())
     {
         MessageBox.Show("Already connected!");
         DialogResult = DialogResult.OK;
     }
     if (!m_serverConnection.ConnectToServer(serverHostnameTextBox.Text, Int32.Parse(serverPortNumberTextBox.Text)))
     {
         MessageBox.Show(String.Format("Unable to connect to {0}:{1}", serverHostnameTextBox.Text, serverPortNumberTextBox.Text));
         return;
     }
     m_serverConnection.DDDClientPath = String.Format("\\\\{0}\\DDDClient", serverHostnameTextBox.Text);
     //String path = String.Format("\\\\{0}\\DDDClient\\SimulationModel.xml", serverHostnameTextBox.Text);
     if (!m_serverConnection.ReadSimModel())
     {
         MessageBox.Show(String.Format("Unable to read sim model"));
         return;
     }
     ServerHostname = serverHostnameTextBox.Text;
     DialogResult   = DialogResult.OK;
     //LoginDialog loginDialog = new LoginDialog(serverConnection);
     //Hide();
     //loginDialog.Show();
 }
コード例 #2
0
        public bool initialize()
        {
            if (!_connection.ConnectToServer(_hostname, _port))
            {
                MessageBox.Show(this, "Connection to server failed; Exiting...");
                return(false);
            }
            _connection.ReadSimModel(String.Format("\\\\{0}\\DDDClient\\SimulationModel.xml", _hostname));
            _connection.SetLocalPlayer(_actingDMName);
            // _connection.LoginPlayer(_actingDMName, "OBSERVER");
            this.Text = String.Format("QA Test Form (Connected to {0}:{1})", _hostname, _port);
            this.toolStripStatusLabelServerStatus.Text = "CONNECTED";

            return(true);
        }
コード例 #3
0
ファイル: MainWindow.cs プロジェクト: xiangnanyue/DDD
        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;
            }
        }
コード例 #4
0
ファイル: DDDAdapter.cs プロジェクト: vishalbelsare/DDD
        public void T_Connect(object p)
        {
            object[] param = p as object[];
            String   host  = "";
            int      port  = -1;

            try
            {
                host = param[0] as string;
                port = (int)param[1];
            }
            catch (Exception ex)
            {
                if (_connectCompleteCallback != null)
                {
                    _connectCompleteCallback(false, "Hostname or port invalid");
                }
            }

            bool result = false;

            lock (_dddLock)
            {
                result = _dddConnection.ConnectToServer(host, port);
                if (!result)
                {
                    goto end;
                }
                result = (result && _dddConnection.ReadSimModel());
                if (!result)
                {
                    goto end;
                }


                String myDM = "AgentDM";
                //PlayerLoginDialog dlg = new PlayerLoginDialog(ref _dddConnection);
                //dlg.ShowDialog();
                // if (dlg.DialogResult == System.Windows.Forms.DialogResult.Cancel)
                // {
                //    result = false;
                //    goto end;
                //}
                //myDM = _dddConnection.PlayerID;
                //event callbacks
                _dddConnection.AddEventCallback("TimeTick", new DDDServerConnection.ProcessSimulationEvent(TimeTick));
                _dddConnection.AddEventCallback("RevealObject", new DDDServerConnection.ProcessSimulationEvent(RevealObject));
                _dddConnection.AddEventCallback("AttackObject", new DDDServerConnection.ProcessSimulationEvent(AttackObject));
                _dddConnection.AddEventCallback("StateChange", new DDDServerConnection.ProcessSimulationEvent(StateChange));
                _dddConnection.AddEventCallback("SelfDefenseAttackStarted", new DDDServerConnection.ProcessSimulationEvent(SelfDefense));
                _dddConnection.AddEventCallback("TransferObject", new DDDServerConnection.ProcessSimulationEvent(TransferObject));
                _dddConnection.AddEventCallback("ViewProActiveRegionUpdate", new DDDServerConnection.ProcessSimulationEvent(ViewProActiveRegionUpdate));
                _dddConnection.AddEventCallback("NewObject", new DDDServerConnection.ProcessSimulationEvent(NewObject));
                _dddConnection.AddEventCallback("MoveObject", new DDDServerConnection.ProcessSimulationEvent(MoveObject));
                _dddConnection.AddEventCallback("MoveDone", new DDDServerConnection.ProcessSimulationEvent(MoveDone));
                _dddConnection.AddEventCallback("AttackSucceeded", new DDDServerConnection.ProcessSimulationEvent(AttackSucceeded));
                _dddConnection.RequestPlayers();
                while (_dddConnection.Players.Count == 0)
                {
                    Thread.Sleep(500);
                    _dddConnection.ProcessEvents();
                }
                _dddConnection.LoginPlayer(myDM, "OBSERVER");
                _dddConnection.GetDMView(myDM); //initializes DM View
            }



            _dddLoopThread = new Thread(new ThreadStart(StartDDDLoop));
            _dddLoopThread.Start();

end:
            String msg = "";

            if (result)
            {
                msg = "Connected to DDD";
            }
            else
            {
                msg = "Connection failed to DDD (host: " + host + ";port: " + port.ToString() + ")";
            }

            if (_connectCompleteCallback != null)
            {
                _connectCompleteCallback(result, msg);
            }
        }
コード例 #5
0
        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;
        }