public static TradeRequestMessage Decode(byte[] bytes)
        {
            TradeRequestMessage message = null;

            if (bytes != null)
            {
                message = new TradeRequestMessage();

                MemoryStream memoryStream = new MemoryStream(bytes);

                message.msgId  = ReadMessageId(memoryStream);
                message.convId = ReadMessageId(memoryStream);
                ReadShort(memoryStream);
                message.GameId          = ReadShort(memoryStream);
                message.TradeId         = ReadShort(memoryStream);
                message.CurrentPlayerId = ReadShort(memoryStream);
                message.PlayerToTradeId = ReadShort(memoryStream);
                message.CardsToTrade    = ReadShortArray(memoryStream);
            }

            return(message);
        }
Example #2
0
        public static Message DecodeMessage(byte[] messageByteStream)
        {
            MemoryStream memoryStream = new MemoryStream(messageByteStream);
            Message      message      = null;

            ReadMessageId(memoryStream);
            ReadMessageId(memoryStream);

            short messageType = ReadShort(memoryStream);

            try
            {
                switch (messageType)
                {
                case REQUEST_GAME:
                    message = RequestGameMessage.Decode(messageByteStream);
                    break;

                case GAME_INFO:
                    message = GameInfoMessage.Decode(messageByteStream);
                    break;

                case START_GAME:
                    message = StartGameMessage.Decode(messageByteStream);
                    break;

                case GAME_STATE_UPDATE:
                    message = GameStateUpdateMessage.Decode(messageByteStream);
                    break;

                case ROLL:
                    message = RollMessage.Decode(messageByteStream);
                    break;

                case TRADE_REQUEST:
                    message = TradeRequestMessage.Decode(messageByteStream);
                    break;

                case TRADE_REPLY:
                    message = TradeReplyMessage.Decode(messageByteStream);
                    break;

                case BUY:
                    message = BuyMessage.Decode(messageByteStream);
                    break;

                case END_TURN:
                    message = EndTurnMessage.Decode(messageByteStream);
                    break;

                case END_GAME:
                    message = EndGameMessage.Decode(messageByteStream);
                    break;

                case ACK:
                    message = AckMessage.Decode(messageByteStream);
                    break;

                case ERROR:
                    message = ErrorMessage.Decode(messageByteStream);
                    break;

                default:

                    break;
                }

                return(message);
            }
            catch
            {
                return(null);
            }
        }