Module protocol

Source
Expand description

The packet implementation of RakNet. This is a lower level implementation responsible for serializing and deserializing packets. Protocol implementation for RakNet. this module contains all of the necessary packets to communicate with RakNet servers.

§Example

Please note this example is not a copy-paste example, but rather a snippet of code that shows how to use the protocol module.

use rakrs::protocol::packet::RakPacket;
use binary_util::BinaryIo;

fn decode_packet(packet: &[u8]) {
    let packet = RakPacket::read_from_slice(packet).unwrap();

    match packet {
        RakPacket::Offline(packet) => match packet {
            OfflinePacket::UnconnectedPing(packet) => {
                println!("Received a ping packet! {:?}", packet);
            },
            _ => {}
        },
        _ => {}
    }
};

Modules§

frame
This is an internal module that contains the logic to implement the frame system within RakNet. This is also called the “Datagram” or “Encapsulated” packet in different implementations.
mcpe
This module contains the MCPE specific packets that are used within RakNet, this is guarded under the mcpe feature.
packet
This module contains all the packets that are used by the RakNet protocol. This module is split into two submodules:
reliability
Reliability types for packets. Each packet sent on the RakNet protocol has a reliability type, which determines how the packet should be handled.

Structs§

Magic
The magic packet is sent to the server to identify the client as offline. This is a special raknet header that uniquely identifies the protocol as raknet.

Constants§

MAX_FRAGS
The maximum amount of fragments that can be sent within a single frame. This constant is used to prevent a client from sending too many fragments, or from bad actors from sending too many fragments.
MAX_ORD_CHANS
The maximum amount of channels that can be used on a single connection. This is a raknet limitation, and is not configurable.
MTU_MAX
The maximum possible amount of bytes that can be sent within a single frame.
MTU_MIN
The minimum possible amount of bytes that can be sent within a single frame.
RAKNET_HEADER_FRAME_OVERHEAD
IP Header + UDP Header + RakNet Header + RakNet Frame Packet Header (MAX)
RAKNET_HEADER_OVERHEAD
IP Header + UDP Header + RakNet Header