Ejemplo n.º 1
0
    public static PacketType ClientDeserialize(List <Snapshot> interpolationBuffer, PlayerJoined playerJoined, BitBuffer buffer,
                                               int displaySeq, CommandsList clientCommands, int cmdSeq, List <Shot> shots, int shotSeq,
                                               ShotBroadcast shotBroadcast, out int commandSnapshotAck, out int playerDisconnect)
    {
        commandSnapshotAck = -1;
        var messageType = buffer.GetByte();

        playerDisconnect = -1;
        if (messageType == (byte)PacketType.UPDATE_MESSAGE)
        {
            ClientDeserializeUpdate(interpolationBuffer, buffer, displaySeq, clientCommands, out commandSnapshotAck);
            return(PacketType.UPDATE_MESSAGE);
        }
        if (messageType == (byte)PacketType.PLAYER_JOINED)
        {
            PlayerJoinedDeserialize(playerJoined, buffer);
            return(PacketType.PLAYER_JOINED);
        }
        if (messageType == (byte)PacketType.COMMANDS_ACK_MESSAGE)
        {
            int receivedAckSequence = ClientDeserializeAck(buffer);
            clientCommands.Ack(receivedAckSequence);
            return(PacketType.COMMANDS_ACK_MESSAGE);
        }
        if (messageType == (byte)PacketType.SHOT_ACK)
        {
            int receivedShotAckSeq = ClientDeserializeShotAck(buffer);
            int count = 0;
            foreach (var shot in shots)
            {
                if (shot.Seq <= receivedShotAckSeq)
                {
                    count++;
                }
            }
            shots.RemoveRange(0, count);
            return(PacketType.SHOT_ACK);
        }

        if (messageType == (byte)PacketType.SHOT_BROADCAST)
        {
            DeserializeShotBroadcast(buffer, shotBroadcast);
            return(PacketType.SHOT_BROADCAST);
        }

        if (messageType == (byte)PacketType.PLAYER_DISCONNECT)
        {
            playerDisconnect = PlayerDisconnectDeserialize(buffer);
        }
        return(PacketType.PLAYER_DISCONNECT);
    }