private void handleDiscardMessage(DiscardMessage m, ServerPlayer p) { if (!p.MyTurn) { //invalid request! p.Send(new ErrorMessage("It is not your turn to discard!")); return; //client sent invalid request! } if (!p.PickedUpCard) { //invalid request p.Send(new ErrorMessage("You did not yet pick up a card from the discard pile or deck!")); return; } if (p.GetHand().RemoveCardWithId(m.CardObj.Id) == null) { //invalid request //send cards back, biotches! p.AddHandCard(m.CardObj); p.Send(new ErrorMessage("You do not have the discard in your hand. Returning card. [" + m.CardObj.Id + "]")); p.Send(new HandMessage(p.GetHand(), true)); return; } //make sure we can't pick any skip cards up _firstDiscard = false; if (p.GetHand().Count == 0) { endTurn(p, false); SendAll(new WentOutMessage(p.PlayerID)); EndHand(p, m.CardObj); return; } _discard.AddTopCard(m.CardObj); SendAll(new UpdateDiscardMessage(m.CardObj, p, true)); updateClientsStatuses(); Thread.Sleep(TimingDefinitions.pxcpArtificalWait); endTurn(p, true); }
private void handleDiscardSkipMessage(DiscardSkipMessage m, ServerPlayer p) { if (!p.MyTurn) { //invalid request p.Send(new ErrorMessage("It is not your turn to discard a skip card!")); return; } if (!p.PickedUpCard) { //invalid request p.Send(new ErrorMessage("You did not yet pick up a card from the discard pile or deck!")); return; } if (p.GetHand().RemoveCardWithId(m.CardObj.Id) == null) { //invalid request //send cards back, biotches! p.Send(new ErrorMessage("You do not have the skip card in your hand. Returning card. [" + m.CardObj.Id + "]")); p.Send(new HandMessage(p.GetHand(), true)); return; } if (p.GetHand().Count == 0) { endTurn(p, false); SendAll(new WentOutMessage(p.PlayerID)); EndHand(p, m.CardObj); return; } ServerPlayer playerToSkip = findPlayer(m.PlayerId); if (playerToSkip == null) { //logError("No player with specified ID!"); p.Send(new ErrorMessage("No player with specified ID! (" + m.PlayerId + ")")); p.AddHandCard(m.CardObj); p.Send(new HandMessage(p.GetHand(), false)); return; //invalid request! } if (!playerToSkip.Connected) { p.AddHandCard(m.CardObj); p.Send(new ErrorMessage("Unable to skip player; player is no longer playing.")); p.Send(new HandMessage(p.GetHand(), false)); return; //invalid request } //make sure we can't pick any skip cards up _firstDiscard = false; _discard.AddTopCard(m.CardObj); SendAll(new UpdateDiscardMessage(m.CardObj, p, true)); playerToSkip.SkippedBy(p); p.Skip(playerToSkip); SendAll(new DiscardSkipMessage(m.CardObj, playerToSkip.PlayerID)); updateClientsStatuses(); //update scoreboards! updateClientsScoreboards(); Thread.Sleep(TimingDefinitions.pxcpArtificalWait); endTurn(p, true); }