Esempio n. 1
0
        public void ProcessHandMessage(HandMessage m)
        {
            if (_Client == null)
            {
                return;
            }
            int hand_cards = _Client.GameRules.HandCards;

            if (_Client._MyTurn)
            {
                hand_cards += 1;
            }

            lock (typeof(Client))
            {
                //create new hand object
                if ((m.HandObj == null) || (_Client._Hand == null) || (m.Replacement))
                {
                    _Client._Hand = m.HandObj;
                }
                else
                {
                    //determine which cards to remove (are no longer in the new hand)
                    List <Card> remove = new List <Card>();
                    foreach (Card c in _Client._Hand)
                    {
                        if (!m.HandObj.HasCardWithId(c.Id))
                        {
                            remove.Add(c);
                        }
                    }
                    //remove cards
                    foreach (Card cd in remove)
                    {
                        _Client._Hand.RemoveCardWithId(cd.Id);
                    }

                    //determine which cards to add
                    List <Card> add = new List <Card>();
                    foreach (Card c in m.HandObj)
                    {
                        if (!_Client._Hand.HasCardWithId(c.Id))
                        {
                            add.Add(c);
                        }
                    }
                    //add cards
                    foreach (Card cd in add)
                    {
                        _Client._Hand.Add(cd);
                    }
                }
            }
            if (_HandMessageDelegate != null)
            {
                _HandMessageDelegate(m.Replacement);
            }
        }
Esempio n. 2
0
        protected Message getMessage()
        {
            byte[] b;
            int    avail;

            try
            {
                //while we're here, look for data in the buffer
                avail = _sock.Available;
                if (avail > 0)
                {
                    buffer.ReadFromSocket(_sock, avail);

                    this.BytesReceived += avail;
                }

                //first see if we can actually decode something
                if (buffer.CanDecode())
                {
                    b = buffer.Decode();
                }
                else
                {
                    return(null);
                }
            }
            catch (Exception ex)
            {
                PhazeXLog.LogError(ex, GameLibraryVersion.VersionString, 104);
                _connected = false;
                return(null);
            }



            Message m = null;

            if (b.Length == 0)
            {
                return(m);
            }
            else if (b[0] == (byte)pxMessages.Heartbeat)
            {
                m = new HeartBeatMessage(b);
            }
            else if (b[0] == (byte)pxMessages.ChangeName)
            {
                m = new ChangeNameMessage(b, this.GetPlayerIDs());
            }
            else if (b[0] == (byte)pxMessages.ChangeNameReject)
            {
                m = new ChangeNameRejectMessage(b);
            }
            else if (b[0] == (byte)pxMessages.Chat)
            {
                m = new ChatMessage(b, this.GetPlayerIDs());
            }
            else if (b[0] == (byte)pxMessages.CompletedPhaze)
            {
                m = new CompletedPhazeMessage(b, this.GetPlayerIDs());
            }
            else if (b[0] == (byte)pxMessages.CurrentPhaze)
            {
                m = new CurrentPhazeMessage(b, this.GameRules);
            }
            else if (b[0] == (byte)pxMessages.DiscardSkip)
            {
                m = new DiscardSkipMessage(b, this.GetPlayerIDs(), this.GameRules);
            }
            else if (b[0] == (byte)pxMessages.DialogMessage)
            {
                m = new DialogMessage(b);
            }
            else if (b[0] == (byte)pxMessages.ErrorMessage)
            {
                m = new ErrorMessage(b);
            }
            else if (b[0] == (byte)pxMessages.GameOver)
            {
                m = new GameOverMessage(b);
            }
            else if (b[0] == (byte)pxMessages.GameRules)
            {
                m = new GameRulesMessage(b);
            }
            else if (b[0] == (byte)pxMessages.GameStarting)
            {
                m = new GameStartingMessage(b);
            }
            else if (b[0] == (byte)pxMessages.Goodbye)
            {
                m = new GoodbyeMessage(b);
            }
            else if (b[0] == (byte)pxMessages.GotCards)
            {
                m = new GotCardsMessage(b, this.GameRules);
            }
            else if (b[0] == (byte)pxMessages.GotDeckCard)
            {
                m = new GotDeckCardMessage(b, this.GetPlayerIDs());
            }
            else if (b[0] == (byte)pxMessages.GotDiscard)
            {
                m = new GotDiscardMessage(b, this.GetPlayerIDs(), this.GameRules);
            }
            else if (b[0] == (byte)pxMessages.Hand)
            {
                m = new HandMessage(b, this.GameRules);
            }
            else if (b[0] == (byte)pxMessages.Login)
            {
                m = new LoginMessage(b);
            }
            else if (b[0] == (byte)pxMessages.LoginAcknowledgment)
            {
                m = new LoginAckMessage(b);
            }
            else if (b[0] == (byte)pxMessages.LogOff)
            {
                m = new LogOffMessage(b, this.GetPlayerIDs());
            }
            else if (b[0] == (byte)pxMessages.NewHand)
            {
                m = new NewHandMessage(b);
            }
            else if (b[0] == (byte)pxMessages.PlayedCardOnTable)
            {
                m = new PlayedCardOnTableMessage(b, this.GetPlayerIDs(), this.GameRules);
            }
            else if (b[0] == (byte)pxMessages.Ready)
            {
                m = new ReadyMessage(b, this.GetPlayerIDs());
            }
            else if (b[0] == (byte)pxMessages.Scoreboard)
            {
                m = new ScoreboardMessage(b, this.GetPlayerIDs(), this.GameRules);
            }
            else if (b[0] == (byte)pxMessages.SkipNotification)
            {
                m = new SkipNotificationMessage(b, this.GetPlayerIDs());
            }
            else if (b[0] == (byte)pxMessages.StartGameTimer)
            {
                m = new StartGameTimerMessage(b);
            }
            else if (b[0] == (byte)pxMessages.Status)
            {
                m = new StatusMessage(b, this.GetPlayerIDs(), this.GameRules);
            }
            else if (b[0] == (byte)pxMessages.SystemMessage)
            {
                m = new SystemMessage(b);
            }
            else if (b[0] == (byte)pxMessages.Table)
            {
                m = new TableMessage(b, this.GameRules);
            }
            else if (b[0] == (byte)pxMessages.TurnEnd)
            {
                m = new TurnEndMessage(b, this.GetPlayerIDs());
            }
            else if (b[0] == (byte)pxMessages.TurnStart)
            {
                m = new TurnStartMessage(b, this.GetPlayerIDs());
            }
            else if (b[0] == (byte)pxMessages.UpdateDiscard)
            {
                m = new UpdateDiscardMessage(b, this.GetPlayerIDs(), this.GameRules);
            }
            else if (b[0] == (byte)pxMessages.WentOut)
            {
                m = new WentOutMessage(b, this.GetPlayerIDs());
            }
            else if (b[0] == (byte)pxMessages.Won)
            {
                m = new WonMessage(b, this.GetPlayerIDs());
            }
            else
            {
                m = new UnknownMessage(b);
            }

            return(m);
        }