bloop-protocol 1.1.0

Core implementation of the Bloop wire protocol
//! Standard server-to-client messages.

use crate::capabilities::Capabilities;
use crate::data_hash::DataHash;
use crate::message::record::AchievementRecord;
use bloop_protocol_derive::{Decode, Encode, Payload};

/// Accepts the handshake and declares the server's capabilities.
#[derive(Clone, Debug, Decode, Encode, Eq, Payload, PartialEq)]
#[bloop(opcode = 0x02)]
pub struct ServerHandshake {
    /// The accepted version based on the requested version range.
    pub accepted_version: u8,

    /// Bitmask of capabilities supported by the server.
    pub capabilities: Capabilities,
}

/// Confirms successful authentication.
#[derive(Clone, Debug, Decode, Encode, Eq, Payload, PartialEq)]
#[bloop(opcode = 0x04)]
pub struct AuthenticationAccepted;

/// Answers a ping.
#[derive(Clone, Debug, Decode, Encode, Eq, Payload, PartialEq)]
#[bloop(opcode = 0x06)]
pub struct Pong;

/// Accepts a bloop and lists the achievements it awarded.
#[derive(Clone, Debug, Decode, Encode, Eq, Payload, PartialEq)]
#[bloop(opcode = 0x09)]
pub struct BloopAccepted {
    /// Awarded achievements.
    #[bloop(count = u8)]
    pub achievements: Vec<AchievementRecord>,
}

/// Carries the audio data for a requested achievement.
#[derive(Clone, Debug, Decode, Encode, Eq, Payload, PartialEq)]
#[bloop(opcode = 0x0b)]
pub struct AudioData {
    /// MP3 audio data.
    #[bloop(count = u32)]
    pub data: Vec<u8>,
}

/// Confirms that the client's cached audio assets are up to date.
#[derive(Clone, Debug, Decode, Encode, Eq, Payload, PartialEq)]
#[bloop(opcode = 0x0d)]
pub struct PreloadMatch;

/// Reports an outdated audio manifest along with the current asset list.
#[derive(Clone, Debug, Decode, Encode, Eq, Payload, PartialEq)]
#[bloop(opcode = 0x0e)]
pub struct PreloadMismatch {
    /// New audio manifest hash.
    pub audio_manifest_hash: DataHash,

    /// All achievements with audio data.
    #[bloop(count = u32)]
    pub achievements: Vec<AchievementRecord>,
}