private void handleGetTopDiscardMessage(GetTopDiscardMessage m, ServerPlayer p) { if (!p.MyTurn) { p.Send(new ErrorMessage("ERROR: It is not your turn to get the top discard!")); return; //client sent invalid request! } if (_discard.ReadTopCard() == null) { SendAll(new ErrorMessage("Internal server error")); return; } if ((_discard.ReadTopCard().Number == CardNumber.Skip) && (!_firstDiscard))//skip card { p.Send(new ErrorMessage("ERROR: You asked for a skip card. This is an invalid move, and should have been caught by your client. Upgrade!")); return; //client sent invalid request } //remove card from discard Card c = _discard.RemoveTopCard(); p.PickedUpCard = true; p.GetHand().Add(c); CardCollection cc = new CardCollection(1); cc.Add(c); p.Send(new GotCardsMessage(cc)); SendAll(new UpdateDiscardMessage(_discard.ReadTopCard(), p, false)); SendAll(new GotDiscardMessage(p.PlayerID, c)); updateClientsStatuses(); }
public void AddMessageToProcess(ServerPlayer sp, byte [] b) { if (b.Length < 1) { PhazeXLog.LogError ( new Exception("Attempted to process 0 byte message!") , GameLibraryVersion.ProgramIdentifier , 0 ); } byte start = b[0]; try { Message msg = null; switch (start) { case (byte)pxMessages.Heartbeat: msg = new HeartBeatMessage(b); break; case (byte)pxMessages.SystemMessage: msg = new SystemMessage(b); break; case (byte)pxMessages.Chat: msg = new ChatMessage(b, this.getIDs()); break; case (byte)pxMessages.Ready: msg = new ReadyMessage(b, this.getIDs()); break; case (byte)pxMessages.ChangeName: msg = new ChangeNameMessage(b, this.getIDs()); break; case (byte)pxMessages.PlayOnGroup: msg = new PlayOnGroupMessage(b, this.rules); break; case (byte)pxMessages.Meld: msg = new MeldMessage(b, this.rules); break; case (byte)pxMessages.GetTopDiscard: msg = new GetTopDiscardMessage(b); break; case (byte)pxMessages.GetTopDeckCard: msg = new GetTopDeckCardMessage(b); break; case (byte)pxMessages.DiscardSkip: msg = new DiscardSkipMessage(b, this.getIDs(), this.rules); break; case (byte)pxMessages.Discard: msg = new DiscardMessage(b, this.rules); break; case (byte)pxMessages.RequestHand: msg = new RequestHandMessage(b); break; case (byte)pxMessages.RequestTable: msg = new RequestTableMessage(b); break; default: msg = new UnknownMessage(b); break; } lock (this) { _messagesToProcess.Add(new PlayerMessage(sp, msg)); } } catch (BadMessageException bme) { PhazeXLog.LogError ( bme , GameLibraryVersion.ProgramIdentifier , 109 ); string info = ""; foreach (byte tmp in b) { info += ((int)tmp).ToString() + " "; } PhazeXLog.LogInformation(info, pid); } }