/// <summary> /// Constructor /// </summary> public CreateSessionForm(Peer peerObject, Address addressObject, ConnectWizard connectionWizard) { // // Required for Windows Form Designer support // InitializeComponent(); peer = peerObject; this.connectionWizard = connectionWizard; deviceAddress = addressObject; txtSession.Text = null; this.Text = connectionWizard.SampleName + " - " + this.Text; //Get the default session from the registry if it exists Microsoft.Win32.RegistryKey regKey = Microsoft.Win32.Registry.CurrentUser.OpenSubKey("Software\\Microsoft\\DirectX\\SDK\\csDPlay"); if (regKey != null) { // Get session name txtSession.Text = (string)regKey.GetValue("DirectPlaySessionName", null); // Get host migration option if (regKey.GetValue("DirectPlayMigrateHost", null) != null) { migrateHostCheckBox.Checked = ((int)regKey.GetValue("DirectPlayMigrateHost", 1) == 1); } // Get session signing option if (regKey.GetValue("DirectPlaySessionSigning", null) != null) { if ("Full" == (string)regKey.GetValue("DirectPlaySessionSigning", null)) { fullSignedRadio.Checked = true; } else if ("Fast" == (string)regKey.GetValue("DirectPlaySessionSigning", null)) { fastSignedRadio.Checked = true; } else { notSignedRadio.Checked = true; } } regKey.Close(); } // Set default port value and hide port UI if provider doesn't use them Port = connectionWizard.DefaultPort; if (!ConnectWizard.ProviderRequiresPort(deviceAddress.ServiceProvider)) { localPortTextBox.Hide(); localPortLabel.Hide(); } }
/// <summary> /// We are ready to create a session. Ensure the data is valid /// then create the session /// </summary> private void btnOK_Click(object sender, System.EventArgs e) { ApplicationDescription dpApp; if ((txtSession.Text == null) || (txtSession.Text == "")) { MessageBox.Show(this,"Please enter a session name before clicking OK.","No sessionname",MessageBoxButtons.OK,MessageBoxIcon.Information); return; } Microsoft.Win32.RegistryKey regKey = Microsoft.Win32.Registry.CurrentUser.CreateSubKey("Software\\Microsoft\\DirectX\\SDK\\csDPlay"); if (regKey != null) { regKey.SetValue("DirectPlaySessionName", txtSession.Text); if (migrateHostCheckBox.Checked) regKey.SetValue("DirectPlayMigrateHost",1); else regKey.SetValue("DirectPlayMigrateHost",0); if (fastSignedRadio.Checked) regKey.SetValue("DirectPlaySessionSigning","Fast"); else if (fullSignedRadio.Checked) regKey.SetValue("DirectPlaySessionSigning","Full"); else regKey.SetValue("DirectPlaySessionSigning","Disabled"); regKey.Close(); } dpApp = new ApplicationDescription(); dpApp.GuidApplication = connectionWizard.ApplicationGuid; dpApp.SessionName = txtSession.Text; dpApp.Flags = 0; if (migrateHostCheckBox.Checked) dpApp.Flags |= SessionFlags.MigrateHost; if (!useDPNSVRCheckBox.Checked) dpApp.Flags |= SessionFlags.NoDpnServer; if (fastSignedRadio.Checked) dpApp.Flags |= SessionFlags.FastSigned; else if (fullSignedRadio.Checked) dpApp.Flags |= SessionFlags.FullSigned; // Specify the port number if available if (ConnectWizard.ProviderRequiresPort(deviceAddress.ServiceProvider)) { if (Port > 0) deviceAddress.AddComponent(Address.KeyPort, Port); } connectionWizard.SetUserInfo(); // Host a game on deviceAddress as described by dpApp // HostFlags.OkToQueryForAddressing allows DirectPlay to prompt the user // using a dialog box for any device address information that is missing peer.Host(dpApp,deviceAddress,HostFlags.OkToQueryForAddressing); this.DialogResult = DialogResult.OK; }
/// <summary> /// We either want to start or stop searching /// </summary> private void btnSearch_Click(object sender, System.EventArgs e) { if (!isSearching) { if (hostAddress != null) { hostAddress.Dispose(); } hostAddress = new Address(); hostAddress.ServiceProvider = deviceAddress.ServiceProvider; // See if we should prompt the user for the remote address if (ConnectWizard.ProviderRequiresPort(hostAddress.ServiceProvider)) { AddressForm addressDialog = new AddressForm(connectionWizard.DefaultPort); addressDialog.ShowDialog(this); // If the user cancelled the address form, abort the search if (addressDialog.DialogResult != DialogResult.OK) { return; } // If a port was specified, add the component if (addressDialog.Hostname != "") { hostAddress.AddComponent(Address.KeyHostname, addressDialog.Hostname); } // If a hostname was specified, add the component if (addressDialog.Port > 0) { hostAddress.AddComponent(Address.KeyPort, addressDialog.Port); } } //Time to enum our hosts ApplicationDescription desc = new ApplicationDescription(); desc.GuidApplication = connectionWizard.ApplicationGuid; // If the user was not already asked for address information, DirectPlay // should prompt with native UI FindHostsFlags flags = 0; if (!ConnectWizard.ProviderRequiresPort(deviceAddress.ServiceProvider)) { flags = FindHostsFlags.OkToQueryForAddressing; } peer.FindHosts(desc, hostAddress, deviceAddress, null, Timeout.Infinite, 0, Timeout.Infinite, flags, out findHostHandle); isSearching = true; btnCreate.Enabled = false; btnSearch.Text = "Stop Search"; } else { btnSearch.Text = "Stopping..."; btnSearch.Enabled = false; if (findHostHandle != 0) { peer.CancelAsyncOperation(findHostHandle); } } }