Example #1
0
        private void handlePlayOnGroupMessage(PlayOnGroupMessage m, ServerPlayer p)
        {
            if (!p.MyTurn)
            {
                p.Send(new ErrorMessage("It is not your turn to play on the table!"));
                p.Send(new HandMessage(p.GetHand(), false));
                return;                 //client sent invalid request!
            }

            if (p.GetHand().RemoveCardWithId(m.CardObj.Id) == null)
            {
                //invalid request
                //send cards back, biotches!
                //todo:: error message
                p.Send(new ErrorMessage("You do not have that card in your hand to play on the table. Returning card. [" + m.CardObj.Id + "]"));
                p.Send(new HandMessage(p.GetHand(), true));
                return;
            }

            if (p.GetHand().Count == 0)
            {
                //invalid request!
                p.Send(new ErrorMessage("You must discard your last card! Returning card."));
                p.GetHand().Add(m.CardObj);
                p.Send(new HandMessage(p.GetHand(), true));
                return;
            }

            //find group on table with correct ID
            Group g = _table.FindGroup(m.GroupId);

            if (g == null)             //invalid request
            {
                //send cards back, biotches!
                p.GetHand().Add(m.CardObj);
                p.Send(new ErrorMessage("Group ID does not exist. Returning card."));
                p.Send(new HandMessage(p.GetHand(), true));
                p.Send(new TableMessage(_table));
            }
            else if (!g.CheckWith(m.CardObj))
            {
                //send cards back, biotches!
                p.GetHand().Add(m.CardObj);
                p.Send(new ErrorMessage("Card (" + m.CardObj.ToString() + ") does not fit into group (" + g.Id + "). Returning card."));
                p.Send(new HandMessage(p.GetHand(), false));
            }
            else
            {
                _table.PlayCard(m.CardObj, m.GroupId);
                SendAll(new PlayedCardOnTableMessage(p.PlayerID, _table.ReadGroup(m.GroupId), m.CardObj));
                SendAll(new TableMessage(_table));
                updateClientsStatuses();
            }
        }
Example #2
0
        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);
            }
        }