1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
mod identifiers;
use std::net::Ipv4Addr;

use bstr::BStr;
pub use identifiers::ID;

use crate::{BitStreamRead, RakNetTime, Result, SystemAddress};

pub trait Parse: Sized {
    fn from_bit_stream(bs: &mut BitStreamRead) -> Result<Self>;
}

#[derive(Debug)]
pub struct ConnectionRequest<'a> {
    /// The password sent by the user
    pub password: &'a BStr,
}

#[derive(Debug)]
pub struct NewIncomingConnection {
    pub local: SystemAddress,
    pub remote: SystemAddress,
}

impl Parse for NewIncomingConnection {
    fn from_bit_stream(bs: &mut BitStreamRead) -> Result<Self> {
        Ok(Self {
            local: SystemAddress::new(Ipv4Addr::from(bs.read::<u32>()?), bs.read()?),
            remote: SystemAddress::new(Ipv4Addr::from(bs.read::<u32>()?), bs.read()?),
        })
    }
}

#[derive(Debug)]
pub struct InternalPing {
    pub send_ping_time: RakNetTime,
}

impl Parse for InternalPing {
    fn from_bit_stream(bs: &mut BitStreamRead) -> Result<Self> {
        Ok(Self {
            send_ping_time: bs.read()?,
        })
    }
}