示例#1
0
        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();
        }
示例#2
0
        public void LoginPlayer(ServerPlayer p, LoginMessage lm)
        {
            lock (this)
            {
                p.Name             = lm.Username;
                p.ComputerPlayer   = lm.ComputerPlayer;
                p.Release          = lm.Major;
                p.Revision         = lm.Minor;
                p.Build            = lm.Build;
                p.LibRelease       = lm.Lib_Major;
                p.LibRevision      = lm.Lib_Minor;
                p.LibBuild         = lm.Lib_Build;
                p.FrameworkVersion = lm.Framework;
                p.OSVersion        = lm.Os;
                p.ClientTitle      = lm.Title;

                p.PlayerID = _unusedPlayerID;
                _unusedPlayerID++;
                _players.Add(p);

                p.Send(new LoginAckMessage(p.PlayerID));

                p.Send(new GameRulesMessage(this.rules));

                //let the player know who all is here already
                foreach (object o in _players)
                {
                    if (p != (ServerPlayer)o)
                    {
                        ServerPlayer sp = (ServerPlayer)o;
                        p.Send(new LoginMessage(
                                   sp.Name
                                   , sp.PlayerID
                                   , sp.ReadyToPlay
                                   , sp.ComputerPlayer
                                   , false
                                   , sp.Release
                                   , sp.Revision
                                   , sp.Build
                                   , sp.ClientTitle
                                   , sp.FrameworkVersion
                                   , sp.OSVersion
                                   , sp.LibRelease
                                   , sp.LibRevision
                                   , sp.LibBuild));
                    }
                }
                this.SendAll(new LoginMessage(p.Name, p.PlayerID, p.ReadyToPlay, p.ComputerPlayer
                                              , true, p.Release, p.Revision, p.Build, p.ClientTitle, p.FrameworkVersion
                                              , p.OSVersion, p.LibRelease, p.LibRevision, p.LibBuild), p);
            }
        }
示例#3
0
        private void handleGetTopDeckCardMessage(GetTopDeckCardMessage m, ServerPlayer p)
        {
            if (!p.MyTurn)
            {
                return;                        //client sent invalid request!
            }
            //remove card from deck
            Card c = _deck.RemoveCard();

            //check to see if top deck card is null!
            if (_deck.IsTopCardNull())
            {
                _deck.ShuffleAndAddUnused(_discard.RemoveAllButTopCard());
            }

            //add to hand of client
            p.PickedUpCard = true;
            p.GetHand().Add(c);
            CardCollection cc = new CardCollection(1);

            cc.Add(c);
            p.Send(new GotCardsMessage(cc));

            //notify the users
            SendAll(new GotDeckCardMessage(p.PlayerID));
            updateClientsStatuses();
        }
示例#4
0
        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);
        }
示例#5
0
 public void SendAll(Message msg, ServerPlayer p)
 {
     lock (this)
     {
         foreach (object o in _players)
         {
             if (o.Equals(p))
             {
                 continue;              //don't send to the player specified
             }
             ServerPlayer sp = (ServerPlayer)o;
             sp.Send(msg);
         }
     }
 }
示例#6
0
 private void handleChangeNameMessage(ChangeNameMessage m, ServerPlayer p)
 {
     //handle what happens if player
     //has already changed their name
     if (p.ChangedName)
     {
         p.Send(new ChangeNameRejectMessage());
     }
     else
     {
         SendAll(new ChangeNameMessage(
                     p.PlayerID
                     , m.NewName
                     , p.Name));
         lock (this)
         {
             p.Name        = m.NewName;
             p.ChangedName = true;
         }
     }
 }
示例#7
0
        public virtual void Cancel()
        {
            lock (this)
            {
                _process     = false;
                _gameStarted = false;

                foreach (object o in _players)
                {
                    ServerPlayer p = (ServerPlayer)o;
                    if (p.Connected)
                    {
                        p.Send(new GoodbyeMessage());
                        p.Disconnect();
                    }
                }
                _rulesServer.Stop();

                _connServer.Stop();

                _shutdown = true;
            }
        }
示例#8
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();
            }
        }
示例#9
0
        private void handleMeldMessage(MeldMessage m, ServerPlayer p)
        {
            if (!p.MyTurn)
            {
                p.Send(new ErrorMessage("It is not your turn to meld! Returning cards."));
                p.Send(new HandMessage(p.GetHand(), true));
                return;                 //client sent invalid request!
            }
            if (p.CompletedPhaze)
            {
                p.Send(new ErrorMessage("You have already completed your phaze! Returning cards."));
                p.Send(new HandMessage(p.GetHand(), true));
                return;                 //client sent invalid request!
            }

            List <Group> lg = m.Groups;

            //check that this doesn't use ALL of the player's cards!
            int num_cards = 0;

            foreach (Group g in lg)
            {
                num_cards += g.Count;
            }
            if (num_cards > this.rules.HandCards)
            {
                //invalid request!
                p.Send(new ErrorMessage("You cannot meld with ALL of the cards in your hand! You must keep one card to discard with!"));
                p.Send(new HandMessage(p.GetHand(), true));
                return;
            }


            //check that all cards are from the user's hand
            //string card_data = "";
            bool okay    = true;
            bool correct = true;

            foreach (Group g in lg)
            {
                foreach (Card c in g)
                {
                    if (!p.GetHand().HasCardWithId(c.Id))
                    {
                        okay = false;
                    }
                    if (!g.Check())
                    {
                        correct = false;
                    }
                    if ((!okay) || (!correct))
                    {
                        break;
                    }
                }
                if ((!okay) || (!correct))
                {
                    break;
                }
            }
            if (!okay)
            {
                //invalid request
                p.Send(new ErrorMessage("You do not own any of the cards you are trying to play! Returning all cards."));
                p.Send(new HandMessage(p.GetHand(), true));
                return;
            }
            if (!correct)
            {
                //invalid request

                p.Send(new ErrorMessage("Meld is invalid! Returning all cards."));
                p.Send(new HandMessage(p.GetHand(), true));
                return;
            }


            //if we've reached here, we can officially remove all cards
            //and add the groups to the table
            foreach (Group g in lg)
            {
                foreach (Card c in g)
                {
                    p.GetHand().RemoveCardWithId(c.Id);
                }
                _table.AddGroup(g);
            }

            p.CompletedPhaze = true;
            p.Send(new HandMessage(p.GetHand(), false));
            SendAll(new CompletedPhazeMessage(p.PlayerID));
            SendAll(new TableMessage(_table));
            updateClientsStatuses();
        }
示例#10
0
        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);
        }
示例#11
0
 private void handleRequestTableMessage(RequestTableMessage m, ServerPlayer p)
 {
     p.Send(new TableMessage(_table));
 }
示例#12
0
 private void handleRequestHandMessage(RequestHandMessage m, ServerPlayer p)
 {
     p.Send(new HandMessage(p.GetHand(), true));
 }