コード例 #1
0
        /// <summary>
        /// Parses the response received from the server.
        /// </summary>
        protected override void UnpackResponse()
        {
            base.UnpackResponse();

            // Create the streams we will be reading from.
            MemoryStream responseStream = new MemoryStream(m_responsePayload);
            BinaryReader responseReader = new BinaryReader(responseStream, Encoding.Unicode);

            // Check the response length.
            if (responseStream.Length < MinResponseMessageLength)
            {
                throw new MessageWrongSizeException("Get Game Cards");
            }

            // Try to unpack the data.
            try
            {
                // Seek past return code.
                responseReader.BaseStream.Seek(sizeof(int), SeekOrigin.Begin);

                // Same Cards
                m_sameCards = responseReader.ReadBoolean();

                // Consecutive Cards
                m_consecutiveCards = responseReader.ReadBoolean();

                // Get the count of games.
                ushort gameCount = responseReader.ReadUInt16();

                // Clear any existing games.
                m_games.Clear();

                // Read all the game data.
                for (ushort currentGame = 0; currentGame < gameCount; currentGame++)
                {
                    BingoGame game = new BingoGame();

                    // Game Number
                    game.LinearNumber = responseReader.ReadInt32();

                    // Display Game Number
                    game.DisplayNumber = responseReader.ReadInt32();

                    // Game Type Id
                    game.Type = (GameType)responseReader.ReadInt32();

                    // Set whether this game has consecutive cards.
                    game.ConsecutiveCards = m_consecutiveCards;

                    // Get the count of card types.
                    ushort cardTypeCount = responseReader.ReadUInt16();

                    for (ushort currentType = 0; currentType < cardTypeCount; currentType++)
                    {
                        // Card Type Id
                        CardType cardType = (CardType)responseReader.ReadInt32();

                        // Rally DE2312 - Selling CBB cards returns an error.
                        CardMedia mediaType = (CardMedia)responseReader.ReadInt32();

                        // Get the count of levels.
                        ushort levelCount = responseReader.ReadUInt16();

                        for (ushort currentLevel = 0; currentLevel < levelCount; currentLevel++)
                        {
                            // Card Level Id
                            int cardLevelId = responseReader.ReadInt32();

                            // Rally US505
                            CardLevel level = null;

                            if (game.Type != GameType.CrystalBall && game.Type != GameType.PickYurPlatter) // Rally TA6385
                            {
                                // Try to find the level in the array we have.
                                if (m_levels == null || m_levels.Length == 0)
                                {
                                    throw new ModuleException(Resources.UnknownCardLevel);
                                }

                                foreach (CardLevel lvl in m_levels)
                                {
                                    if (lvl.Id == cardLevelId)
                                    {
                                        level = lvl;
                                        break;
                                    }
                                }

                                // Rally US229 & US505
                                if (level == null)
                                {
                                    throw new ModuleException(Resources.UnknownCardLevel);
                                }
                            }

                            // Get the count of cards.
                            ushort cardCount = responseReader.ReadUInt16();

                            for (ushort currentCard = 0; currentCard < cardCount; currentCard++)
                            {
                                BingoCard card = null;

                                // Rally TA5749
                                // First Card
                                bool firstCard = responseReader.ReadBoolean();

                                // Card Number
                                int cardNum = responseReader.ReadInt32();

                                // PDTS 1098
                                // Rally DE2312
                                // Create the card.
                                card                = BingoCardFactory.CreateBingoCard(game.Type, cardType, mediaType);
                                card.Number         = cardNum;
                                card.Level          = level;
                                card.IsStartingCard = firstCard;
                                // END: TA5749

                                // Rally US505
                                // Rally TA6385
                                if (m_getFaces || game.Type == GameType.CrystalBall || game.Type == GameType.PickYurPlatter)
                                {
                                    // Rally US498
                                    card.ParseFaceData(responseReader);
                                }

                                game.AddCard(card);
                            }
                        }
                    }

                    m_games.Add(game);
                }
            }
            catch (EndOfStreamException e)
            {
                throw new MessageWrongSizeException("Get Game Cards", e);
            }
            catch (Exception e)
            {
                throw new ServerException("Get Game Cards", e);
            }

            // Close the streams.
            responseReader.Close();
        }