/// <summary> /// Constructor /// </summary> public CreateJoinForm(Peer peerObject, Address addressObject, ConnectWizard connectionWizard) { // // Required for Windows Form Designer support // InitializeComponent(); peer = peerObject; this.connectionWizard = connectionWizard; this.Text = connectionWizard.SampleName + " - " + this.Text; deviceAddress = addressObject; //Set up the event handlers peer.FindHostResponse += new FindHostResponseEventHandler(FindHostResponseMessage); peer.ConnectComplete += new ConnectCompleteEventHandler(ConnectResult); peer.AsyncOperationComplete += new AsyncOperationCompleteEventHandler(CancelAsync); //Set up our timer updateListTimer = new System.Timers.Timer(300); // A 300 ms interval updateListTimer.Elapsed += new System.Timers.ElapsedEventHandler(this.UpdateTimer); updateListTimer.SynchronizingObject = this; updateListTimer.Start(); //Set up our connect timer connectTimer = new System.Timers.Timer(100); // A 100ms interval connectTimer.Elapsed += new System.Timers.ElapsedEventHandler(this.ConnectTimer); connectTimer.SynchronizingObject = this; // Set up our connect event connectEvent = new ManualResetEvent(false); }
/// <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> /// Constructor /// </summary> public ChooseServiceProviderForm(Peer peerObject, ConnectWizard connectionWizard) { // // Required for Windows Form Designer support // InitializeComponent(); peer = peerObject; this.connectionWizard = connectionWizard; this.Text = connectionWizard.SampleName + " - " + this.Text; // Fill up our listbox with the service providers ServiceProviderInformation[] serviceProviders = peer.GetServiceProviders(false); foreach (ServiceProviderInformation info in serviceProviders) { lstSP.Items.Add(info); } txtUser.Text = null; //Get the default username from the registry if it exists Microsoft.Win32.RegistryKey regKey = Microsoft.Win32.Registry.CurrentUser.OpenSubKey("Software\\Microsoft\\DirectX\\SDK\\csDPlay"); if (regKey != null) { try { txtUser.Text = (string)regKey.GetValue("DirectPlayUserName", null); lstSP.SelectedIndex = (int)regKey.GetValue("DirectPlaySPIndex", 0); regKey.Close(); } catch { txtUser.Text = null; lstSP.SelectedIndex = 0; } } else { lstSP.SelectedIndex = 0; } if ((txtUser.Text == null) || (txtUser.Text == "")) { txtUser.Text = SystemInformation.UserName; } }
public NETPlayer(NetLayer netlayer) { // // TODO: Add constructor logic here // layer = netlayer; peerObject = new Peer(); peerObject.PlayerCreated += new PlayerCreatedEventHandler(layer.PlayerCreated); peerObject.PlayerDestroyed += new PlayerDestroyedEventHandler(layer.PlayerDestroyed); peerObject.Receive += new ReceiveEventHandler(layer.DataReceived); peerObject.SessionTerminated += new SessionTerminatedEventHandler(SessionTerminated); Connect = new ConnectWizard(peerObject, AppGuid, "Helikopter"); Connect.StartWizard(); inSession = Connect.InSession; if (inSession) { isHost = Connect.IsHost; } }
/// <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); } } }