rak_rs/
lib.rs

1//! # rak-rs
2//!
3//! A fully functional RakNet implementation in pure rust, asynchronously driven.
4//!
5//! ## Getting Started
6//!
7//! RakNet (rak-rs) is available on [crates.io](https://crates.io/crates/rak-rs), to use it, add the following to your `Cargo.toml`:
8//!
9//! ```toml
10//! [dependencies]
11//! rak-rs = "0.3.3"
12//! ```
13//!
14//! ## Features
15//!
16//! This RakNet implementation comes with 3 primary features, `async_std`, `async_tokio` and `mcpe`.  However, by default, only `async_std` is enabled, and `mcpe` requires you to modify your `Cargo.toml`.
17//!
18//! If you wish to use these features, add them to your `Cargo.toml` as seen below:
19//!
20//! ```toml
21//! [dependencies]
22//! rak-rs = { version = "0.3.3", default-features = false, features = [ "async_tokio", "mcpe" ] }
23//! ```
24//!
25//!
26//!
27//! rak-rs also provides the following modules:
28//!
29//! - [`rak_rs::client`](crate::client) - A client implementation of RakNet, allowing you to connect to a RakNet server.
30//! - [`rak_rs::connection`](crate::connection) - A bare-bones implementation of a Raknet peer, this is mainly used for types.
31//! - [`rak_rs::error`](crate::error) - A module with errors that both the Client and Server can respond with.
32//! - [`rak_rs::protocol`](crate::protocol) - A lower level implementation of RakNet, responsible for encoding and decoding packets.
33//! - [`rak_rs::server`](crate::server) - The base server implementation of RakNet.
34//! - [`rak_rs::util`](crate::util)  - General utilities used within `rak-rs`.
35//!
36//! # Client
37//!
38//! The `client` module provides a way for you to interact with RakNet servers with code.
39//!
40//! **Example:**
41//!
42//! ```ignore
43//! use rak_rs::client::{Client, DEFAULT_MTU};
44//! use std::net::ToSocketAddrs;
45//!
46//! #[async_std::main]
47//! async fn main() {
48//!     let version: u8 = 10;
49//!     let mut client = Client::new(version, DEFAULT_MTU);
50//!
51//!     client.connect("my_server.net:19132").await.unwrap();
52//!
53//!     // receive packets
54//!     loop {
55//!         let packet = client.recv().await.unwrap();
56//!
57//!         println!("Received a packet! {:?}", packet);
58//!
59//!         client.send_ord(vec![254, 0, 1, 1], Some(1));
60//!     }
61//! }
62//!
63//! ```
64//!
65//! # Server
66//!
67//! A RakNet server implementation in pure rust.
68//!
69//! **Example:**
70//!
71//! ```ignore
72//! use rakrs::connection::Connection;
73//! use rakrs::Listener;
74//! use rakrs::
75//!
76//! #[async_std::main]
77//! async fn main() {
78//!     let mut server = Listener::bind("0.0.0.0:19132").await.unwrap();
79//!     server.start().await.unwrap();
80//!
81//!     loop {
82//!         let conn = server.accept().await;
83//!         async_std::task::spawn(handle(conn.unwrap()));
84//!     }
85//! }
86//!
87//! async fn handle(mut conn: Connection) {
88//!     loop {
89//!         // keeping the connection alive
90//!         if conn.is_closed() {
91//!             println!("Connection closed!");
92//!             break;
93//!         }
94//!         if let Ok(pk) = conn.recv().await {
95//!             println!("Got a connection packet {:?} ", pk);
96//!         }
97//!     }
98//! }
99//! ```
100/// A client implementation of RakNet, allowing you to connect to a RakNet server.
101pub mod client;
102/// The connection implementation of RakNet, allowing you to send and receive packets.
103/// This is barebones, and you should use the client or server implementations instead, this is mainly
104/// used internally.
105pub mod connection;
106/// The error implementation of RakNet, allowing you to handle errors.
107pub mod error;
108/// The packet implementation of RakNet.
109/// This is a lower level implementation responsible for serializing and deserializing packets.
110pub mod protocol;
111/// The server implementation of RakNet, allowing you to create a RakNet server.
112pub mod server;
113/// Utilties for RakNet, like epoch time.
114pub mod util;
115
116pub use protocol::mcpe::{self, motd::Motd};
117pub use server::Listener;
118
119/// An internal module for notifying the connection of state updates.
120pub(crate) mod notify;