bloop-protocol 1.0.0

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

use std::net::IpAddr;

use uuid::Uuid;

use crate::data_hash::DataHash;
use crate::nfc_uid::NfcUid;
use bloop_protocol_derive::{Decode, Encode, Payload};

/// Opens a session by negotiating the protocol version.
#[derive(Clone, Debug, Decode, Encode, Eq, Payload, PartialEq)]
#[bloop(opcode = 0x01)]
pub struct ClientHandshake {
    /// Minimum supported major version.
    pub min_version: u8,

    /// Maximum supported major version.
    pub max_version: u8,
}

/// Authenticates the client after the handshake.
#[derive(Clone, Debug, Decode, Encode, Eq, Payload, PartialEq)]
#[bloop(opcode = 0x03)]
pub struct Authentication {
    /// Client ID.
    pub client_id: String,

    /// Client secret.
    pub client_secret: String,

    /// Local IP address of the client.
    pub ip_address: IpAddr,
}

/// Keep-alive signal; the server answers with a pong.
#[derive(Clone, Debug, Decode, Encode, Eq, Payload, PartialEq)]
#[bloop(opcode = 0x05)]
pub struct Ping;

/// Announces that the client is about to close the connection.
#[derive(Clone, Debug, Decode, Encode, Eq, Payload, PartialEq)]
#[bloop(opcode = 0x07)]
pub struct Quit;

/// Asks the server to verify a scanned NFC UID.
#[derive(Clone, Debug, Decode, Encode, Eq, Payload, PartialEq)]
#[bloop(opcode = 0x08)]
pub struct Bloop {
    /// NFC UID scanned on the client.
    pub nfc_uid: NfcUid,
}

/// Requests the audio data for an achievement.
#[derive(Clone, Debug, Decode, Encode, Eq, Payload, PartialEq)]
#[bloop(opcode = 0x0a)]
pub struct RetrieveAudio {
    /// Unique ID of the achievement.
    pub achievement_id: Uuid,
}

/// Asks the server whether the cached audio assets are up to date.
#[derive(Clone, Debug, Decode, Encode, Eq, Payload, PartialEq)]
#[bloop(opcode = 0x0c)]
pub struct PreloadCheck {
    /// Stored audio manifest hash; absent when nothing is cached yet.
    pub audio_manifest_hash: Option<DataHash>,
}