rak_rs/protocol/
mod.rs

1//! Protocol implementation for RakNet.
2//! this module contains all of the necessary packets to communicate with RakNet servers.
3//!
4//! ## Example
5//! Please note this example is not a copy-paste example, but rather a snippet of code
6//! that shows how to use the [`protocol`] module.
7//!
8//! ```rust ignore
9//! use rakrs::protocol::packet::RakPacket;
10//! use binary_util::BinaryIo;
11//!
12//! fn decode_packet(packet: &[u8]) {
13//!     let packet = RakPacket::read_from_slice(packet).unwrap();
14//!
15//!     match packet {
16//!         RakPacket::Offline(packet) => match packet {
17//!             OfflinePacket::UnconnectedPing(packet) => {
18//!                 println!("Received a ping packet! {:?}", packet);
19//!             },
20//!             _ => {}
21//!         },
22//!         _ => {}
23//!     }
24//! };
25//! ```
26/// This is an internal module that contains the logic to implement the Ack system within
27/// RakNet.
28pub(crate) mod ack;
29/// This is an internal module that contains the logic to implement the frame system within
30/// RakNet. This is also called the "Datagram" or "Encapsulated" packet in different implementations.
31///
32/// You can find the original implementation from RakNet [here](https://github.com/facebookarchive/RakNet/blob/1a169895a900c9fc4841c556e16514182b75faf8/Source/ReliabilityLayer.cpp#L110-L231)
33// pub(crate) mod frame;
34pub mod frame;
35/// This is the constant added to all offline packets to identify them as RakNet packets.
36pub(crate) mod magic;
37/// This module contains the MCPE specific packets that are used within RakNet, this is guarded
38/// under the `mcpe` feature.
39///
40/// To enable this feature, add the following to your `Cargo.toml`:
41/// ```toml
42/// [dependencies]
43/// rak-rs = { version = "0.1.0", features = [ "mcpe" ] }
44/// ```
45pub mod mcpe;
46pub mod packet;
47pub mod reliability;
48
49pub use magic::*;
50
51/// The maximum amount of fragments that can be sent within a single frame.
52/// This constant is used to prevent a client from sending too many fragments,
53/// or from bad actors from sending too many fragments.
54pub const MAX_FRAGS: u32 = 1024;
55/// The maximum amount of channels that can be used on a single connection.
56/// This is a raknet limitation, and is not configurable.
57pub const MAX_ORD_CHANS: u8 = 32;
58
59/// IP Header + UDP Header + RakNet Header + RakNet Frame Packet Header (MAX)
60pub const RAKNET_HEADER_FRAME_OVERHEAD: u16 = 20 + 8 + 8 + 4 + 20;
61/// IP Header + UDP Header + RakNet Header
62pub const RAKNET_HEADER_OVERHEAD: u16 = 20 + 8 + 8;
63
64/// The maximum possible amount of bytes that can be sent within a single frame.
65pub const MTU_MAX: u16 = 2400;
66/// The minimum possible amount of bytes that can be sent within a single frame.
67pub const MTU_MIN: u16 = 400;