/// <summary> /// Handler for a challenge response (incuding cancellation) /// </summary> private void OnChallengeResponse() { GameChallengeDataContainer.ChallengeResultType result = GameChallengeDataContainer.ChallengeResultType.CHALLENGE_UNKNOWN; bool challengeProceed = false; lock (gameChallengeMutex) { if (gameChallengeThreadExchangeData != null) { result = gameChallengeThreadExchangeData.ChallengeResult; gameChallengeThreadExchangeData = null; challengeProceed = true; } } if (waitDlg.Visible) { waitDlg.Close(); } if (challengeProceed) { switch (result) { case GameChallengeDataContainer.ChallengeResultType.CHALLENGE_FAILED: MessageBox.Show("Game Challenge Failed!", "Game Challenge", MessageBoxButtons.OK, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1); break; case GameChallengeDataContainer.ChallengeResultType.CHALLENGE_REJECTED: MessageBox.Show("Game Challenge Rejected!", "Game Challenge", MessageBoxButtons.OK, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button1); break; case GameChallengeDataContainer.ChallengeResultType.CHALLENGE_ACCEPTED: break; case GameChallengeDataContainer.ChallengeResultType.CHALLENGE_CANCELLED: break; default: MessageBox.Show("Game Challenge Error!", "Game Challenge", MessageBoxButtons.OK, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1); break; } if (result == GameChallengeDataContainer.ChallengeResultType.CHALLENGE_ACCEPTED) { this.DialogResult = DialogResult.OK; Hide(); } } }
private void m_playButton_Click(object sender, EventArgs e) { int curIndex = m_gameRoomPlayersListBox.SelectedIndex; if (curIndex >= 0) { NetworkBackgammonPlayer challengingPlayer = NetworkBackgammonClient.Instance.Player; NetworkBackgammonPlayer challengedPlayer = (NetworkBackgammonPlayer)m_gameRoomPlayersListBox.Items[curIndex]; string tempChallengingPlayer = String.Copy(challengingPlayer.PlayerName); string tempChallengedlayer = String.Copy(challengedPlayer.PlayerName); // Setup the wait dialog waitDlg = new NetworkBackgammonWaitDialog(new NetworkBackgammonWaitDialog.WaitButtonActionDelegate(OnChallengeCancelled)); waitDlg.WaitDialogLabel.Text = "Waiting for response from " + challengedPlayer.PlayerName; bool challengeProceed = true; lock (gameChallengeMutex) { // Only execute challenge if none is pending (i.e. if gameChallengeThreadExchangeData object exists) if (gameChallengeThreadExchangeData == null) { // Store challenged player name for thread access gameChallengeThreadExchangeData = new GameChallengeDataContainer(challengedPlayer.PlayerName); } else { challengeProceed = false; } } if (challengeProceed) { // Create the challenge thread challengeThread = new Thread(new ThreadStart(ChallengeThread)); // Start the thread challengeThread.Start(); // Start up the wait dialog waitDlg.ShowDialog(this); } } }