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

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

                MemoryStream memoryStream = new MemoryStream(bytes);

                message.msgId  = ReadMessageId(memoryStream);
                message.convId = ReadMessageId(memoryStream);
                ReadShort(memoryStream);
                message.GameId          = ReadShort(memoryStream);
                message.CurrentPlayerId = ReadShort(memoryStream);
                // TODO: ReadShort to AvailableResources
                message.PlayerPoints       = ReadShortArray(memoryStream);
                message.PlayerCardsAmounts = ReadShortArray(memoryStream);
                message.BoardLayout        = ReadShortArray(memoryStream);
                message.PlayerWithLR       = ReadShort(memoryStream);
                message.LastMove           = ReadString(memoryStream);
            }

            return(message);
        }
예제 #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);
            }
        }