private void OnConnectComplete(object sender, ConnectCompleteEventArgs e) { // Check to see if we connected properly if (e.Message.ResultCode == ResultCode.Success) { connected = true; } else { connected = false; } }
/// <summary> /// Fired when a connect complete message is received from DirectPlay. Fire /// our event to notify the sample we've connected /// </summary> private void ConnectResult(object sender, ConnectCompleteEventArgs e) { if (e.Message.ResultCode == 0) { isConnected = true; } else { isConnected = false; } resultCode = e.Message.ResultCode; // Notify the timer that we've connected. connectEvent.Set(); }
private void ConnectComplete(object sender, ConnectCompleteEventArgs e) { // Did we really connect? if (e.Message.ResultCode != 0) { MessageBox.Show("The server does not exist, or is unavailable.", "Unavailable", MessageBoxButtons.OK, MessageBoxIcon.Information); } else { gConnected = true; } // Set off the connect event hConnect.Set(); }
/// <summary> /// Fired when a connect complete message is received from DirectPlay. Fire /// our event to notify the sample we've connected /// </summary> private void ConnectResult(object sender, ConnectCompleteEventArgs e) { if (e.Message.ResultCode == 0) { isConnected = true; } else isConnected = false; resultCode = e.Message.ResultCode; // Notify the timer that we've connected. connectEvent.Set(); }
private void onConnectComplete(object sender, ConnectCompleteEventArgs e) { timeoutTimer.Dispose(); if (status == NetworkStatus.Connecting) { if (e.Message.ResultCode == Microsoft.DirectX.DirectPlay.ResultCode.Success) { playerId = e.Message.LocalPlayerId; status = NetworkStatus.Connected; if (voiceSetupOk) { // start voice client voiceClient = new Microsoft.DirectX.DirectPlay.Voice.Client(client, new int[] { // message mask 0x0006, // RecordStarted 0x0007, // RecordStopped 0x0008, // ConnectResult 0x000A // InputLevel }); // Add event handlers voiceClient.ConnectResult += new ConnectResultEventHandler(onVoiceConnectResult); voiceClient.PlayerStarted += new PlayerStartedEventHandler(onPlayerStarted); // never raised, but necessary to allow for the calling of onRecordStarted voiceClient.PlayerStopped += new PlayerStoppedEventHandler(onPlayerStopped); // never raised, but necessary to allow for the calling of onRecordStopped voiceClient.RecordStarted += new RecordStartedEventHandler(onRecordStarted); voiceClient.RecordStopped += new RecordStoppedEventHandler(onRecordStopped); voiceClient.InputLevel += new InputLevelEventHandler(onInputLevel); SoundDeviceConfig soundConfig = new SoundDeviceConfig(); soundConfig.Flags = (audioManager.AudioProperties.DisableAutoconfiguration ? 0 : SoundConfigFlags.AutoSelect); /*SoundConfigFlags.HalfDuplex*/ if (audioManager.DirectSoundDevice != null) { soundConfig.PlaybackDevice = audioManager.DirectSoundDevice; } soundConfig.GuidPlaybackDevice = DSoundHelper.DefaultPlaybackDevice; soundConfig.GuidCaptureDevice = DSoundHelper.DefaultCaptureDevice; soundConfig.Window = voiceFocusWindow; soundConfig.MainBufferPriority = 0; updateClientConfig(); voiceStatus = VoiceStatus.Connecting; // Connect to the voice session try { voiceClient.Connect(soundConfig, clientConfig, 0 /*VoiceFlags.Sync*/); } catch (TransportNoPlayerException) { } catch (Exception exception) { voiceStatus = VoiceStatus.Disconnected; VoiceFailureCause cause = (exception is CompressionNotSupportedException ? VoiceFailureCause.CompressionNotSupported : (exception is IncompatibleVersionException ? VoiceFailureCause.IncompatibleVersion : (exception is NoVoiceSessionException ? VoiceFailureCause.NoVoiceSession : (exception is RunSetupException ? VoiceFailureCause.RunSetup : (exception is SoundInitializeFailureException ? VoiceFailureCause.SoundInitFailure : (exception is Microsoft.DirectX.DirectPlay.Voice.TimedOutException ? VoiceFailureCause.TimeOut : VoiceFailureCause.Other)))))); NetworkMessage errorMessage = new NetworkMessage(0, (byte)ReservedMessageType.VoiceConnectionFailed, new byte[1] { (byte)cause }); lock (networkMessages) { networkMessages.Enqueue(errorMessage); } return; } } else { NetworkMessage errorMessage = new NetworkMessage(0, (byte)ReservedMessageType.VoiceConnectionFailed, new byte[1] { (byte)VoiceFailureCause.RunSetup }); lock (networkMessages) { networkMessages.Enqueue(errorMessage); } } // add the new message to the message list NetworkMessage message = new NetworkMessage(0, (byte)ReservedMessageType.ConnectionEstablished, null); lock (networkMessages) { networkMessages.Enqueue(message); } } else { status = NetworkStatus.Disconnected; ConnectionFailureCause cause; switch (e.Message.ResultCode) { case Microsoft.DirectX.DirectPlay.ResultCode.HostRejectedConnection: cause = ConnectionFailureCause.HostRejectedConnection; break; case Microsoft.DirectX.DirectPlay.ResultCode.NoConnection: cause = ConnectionFailureCause.NoConnection; break; case Microsoft.DirectX.DirectPlay.ResultCode.NotHost: cause = ConnectionFailureCause.NotHost; break; case Microsoft.DirectX.DirectPlay.ResultCode.SessionFull: cause = ConnectionFailureCause.SessionFull; break; default: cause = ConnectionFailureCause.Other; break; } NetworkMessage message = new NetworkMessage(0, (byte)ReservedMessageType.ConnectionFailed, new byte[1] { (byte)cause }); lock (networkMessages) { networkMessages.Enqueue(message); } } } }