-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
74 changed files
with
6,090 additions
and
3,021 deletions.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
## RakNet | ||
|
||
RakNet doesn't have a lot of resources on it's internal functionality, and to better understand it I've written these docs. | ||
|
||
RakNet is composed and derived of multiple parts, so for simplicity I've narrowed it down into the following parts: | ||
|
||
- [Protocol](./protocol/README.md) | ||
|
||
- [Connection Handshake](./protocol/handshake.md) | ||
|
||
- [Datagrams](./protocol/datagrams) | ||
|
||
- [Packet Reliability](./reliability.md) | ||
|
||
- [Congestion Control](./congestion.md) | ||
|
||
- [Plugins]() | ||
|
||
- [Server]() | ||
|
||
- [Client]() | ||
|
||
It's important to note that this documentation does conceptualize and take a different approach from the original RakNet implementation, however it does not deviate from the behavior of RakNet; rather providing a basis on how I believe it should be implemented. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
# RakNet Protocol |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
# Reliability | ||
|
||
Reliability within RakNet specifies when a packet should arrive and how it should be treated. The term "Reliability" within RakNet generally refers to the following possible states of a packet: | ||
|
||
- **Unreliable**. The packet sent is not reliable and not important. Later packets will make up for it's loss. This is the same as a regular UDP packet with the added benefit that duplicates are discarded. | ||
|
||
- **UnreliableSequenced**. This packet is not necessarily important, if it arrives later than another packet, you should discard it. Otherwise you can treat it normally. *This reliability is generally not used* | ||
|
||
- **Reliable**. The packet should be acknow |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,8 @@ | ||
.DS_Store | ||
target | ||
|
||
# Ignore lock files | ||
Cargo.lock | ||
|
||
*.old/ | ||
*.profraw |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,26 @@ | ||
[package] | ||
name = "rakrs" | ||
version = "0.3.0-rc.2" | ||
name = "rak-rs" | ||
version = "0.1.0" | ||
authors = ["Bavfalcon9 <olybear9@gmail.com>"] | ||
edition = "2021" | ||
|
||
[package.metadata.docs.rs] | ||
rustdoc-args = ["--html-in-header", "./resources/header.html"] | ||
|
||
[features] | ||
default = [ "async_tokio" ] | ||
default = [ "async_std" ] | ||
# default = ["async_tokio" ] | ||
mcpe = [] | ||
debug = [] | ||
debug_all = [] | ||
async_std = [ "async-std" ] | ||
async_tokio = [ "tokio" ] | ||
|
||
[dependencies] | ||
rand = "0.8.3" | ||
binary_utils = { git = "https://github.com/NetrexMC/BinaryUtil", tag = "v0.2.2" } | ||
netrex_events = { git = "https://github.com/NetrexMC/Events", branch = "master" } | ||
tokio = { version = "1.15.0", features = ["full"], optional = true } | ||
binary-util = "0.3.4" | ||
tokio = { version = "1.28.2", features = ["full"], optional = true } | ||
byteorder = "1.4.3" | ||
futures = "0.3.19" | ||
futures-executor = "0.3.19" | ||
async-std = { version = "1.10.0", optional = true } | ||
async-std = { version = "1.12.0", optional = true, features = [ "unstable" ] } |
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,100 @@ | ||
# RakNet | ||
# rak-rs | ||
|
||
A fully functional RakNet implementation in rust, asynchronously driven. | ||
A fully functional RakNet implementation in pure rust, asynchronously driven. | ||
|
||
## Getting Started | ||
|
||
RakNet (rak-rs) is available on [crates.io](), to use it, add the following to your `Cargo.toml`: | ||
|
||
```toml | ||
[dependencies] | ||
rak-rs = "0.1.0" | ||
``` | ||
|
||
## Features | ||
|
||
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`. | ||
|
||
If you wish to use these features, add them to your `Cargo.toml` as seen below: | ||
|
||
```toml | ||
[dependencies] | ||
rak-rs = { version = "0.1.0", default-features = false, features = [ "async_tokio", "mcpe" ] } | ||
``` | ||
|
||
|
||
|
||
rak-rs also provides the following modules: | ||
|
||
- [`rak_rs::client`](https://docs.rs/rak-rs/latest/rak-rs/client) - A client implementation of RakNet, allowing you to connect to a RakNet server. | ||
- [`rak_rs::connection`](https://docs.rs/rak-rs/latest/rak-rs/client) - A bare-bones implementation of a Raknet peer, this is mainly used for types. | ||
- [`rak_rs::error`](https://docs.rs/rak-rs/latest/rak-rs/error) - A module with errors that both the Client and Server can respond with. | ||
- [`rak_rs::protocol`](https://docs.rs/rak-rs/latest/rak-rs/protocol) - A lower level implementation of RakNet, responsible for encoding and decoding packets. | ||
- [`rak_rs::server`](https://docs.rs/rak-rs/latest/rak-rs/server) - The base server implementation of RakNet. | ||
- [`rak_rs::util`](https://docs.rs/rak-rs/latest/rak-rs/utils) - General utilities used within `rak-rs`. | ||
|
||
# Client | ||
|
||
The `client` module provides a way for you to interact with RakNet servers with code. | ||
|
||
**Example:** | ||
|
||
```rust | ||
use rak_rs::client::{Client, DEFAULT_MTU}; | ||
use std::net::ToSocketAddrs; | ||
|
||
#[async_std::main] | ||
async fn main() { | ||
let version: u8 = 10; | ||
let addr = "my_server.net:19132".to_socket_addrs().unwrap(); | ||
let mut client = Client::new(version, DEFAULT_MTU); | ||
|
||
client.connect(addr.next().unwrap()).await.unwrap(); | ||
|
||
// receive packets | ||
loop { | ||
let packet = client.recv().await.unwrap(); | ||
|
||
println!("Received a packet! {:?}", packet); | ||
|
||
client.send_ord(vec![254, 0, 1, 1], Some(1)); | ||
} | ||
} | ||
|
||
``` | ||
|
||
# Server | ||
|
||
A RakNet server implementation in pure rust. | ||
|
||
**Example:** | ||
|
||
```rust | ||
use rakrs::connection::Connection; | ||
use rakrs::Listener; | ||
use rakrs:: | ||
|
||
#[async_std::main] | ||
async fn main() { | ||
let mut server = Listener::bind("0.0.0.0:19132").await.unwrap(); | ||
server.start().await.unwrap(); | ||
|
||
loop { | ||
let conn = server.accept().await; | ||
async_std::task::spawn(handle(conn.unwrap())); | ||
} | ||
} | ||
|
||
async fn handle(mut conn: Connection) { | ||
loop { | ||
// keeping the connection alive | ||
if conn.is_closed() { | ||
println!("Connection closed!"); | ||
break; | ||
} | ||
if let Ok(pk) = conn.recv().await { | ||
println!("Got a connection packet {:?} ", pk); | ||
} | ||
} | ||
} | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import os | ||
os.system("CARGO_INCREMENTAL=0 RUSTFLAGS='-Cinstrument-coverage' LLVM_PROFILE_FILE='cargo-test-%p-%m.profraw' cargo test") | ||
os.system("gcov . --binary-path ./target/debug/deps -s . -t html --branch --ignore-not-existing --ignore ../* --ignore /* --ignore xtask/* --ignore */src/tests/* -o coverage/html") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
# Examples | ||
|
||
**async-std:** | ||
- [client](/examples/async-std/client) | ||
- [server](/examples/async-std/server) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
[package] | ||
name = "client" | ||
version = "0.1.0" | ||
edition = "2021" | ||
|
||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html | ||
|
||
[dependencies] | ||
async-std = { version = "1.12.0", features = [ "unstable", "attributes" ] } | ||
binary-util = "0.3.0" | ||
rak-rs = { path = "../../../", features = [ "debug", "debug_all", "async-std" ]} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
use rak_rs::client::{Client, DEFAULT_MTU}; | ||
use std::{net::ToSocketAddrs, vec}; | ||
|
||
#[async_std::main] | ||
async fn main() { | ||
let mut client = Client::new(10, DEFAULT_MTU); | ||
let mut addr = "zeqa.net:19132".to_socket_addrs().unwrap(); | ||
if let Err(_) = client.connect(addr.next().unwrap()).await { | ||
// here you could attempt to retry, but in this case, we'll just exit | ||
println!("Failed to connect to server!"); | ||
return; | ||
} | ||
|
||
loop { | ||
let pk = client.recv().await.unwrap(); | ||
println!("Received packet: {:?}", pk); | ||
client.send_ord(&vec![ 254, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00 ], 1).await.unwrap(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
[build] | ||
rustflags = ["--cfg", "tokio_unstable"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
[package] | ||
name = "raknet-server-async-std" | ||
version = "0.1.0" | ||
edition = "2021" | ||
|
||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html | ||
|
||
[dependencies] | ||
async-std = { version = "1.12.0", features = [ "attributes" ] } | ||
console-subscriber = "0.1.8" | ||
rak-rs = { path = "../../../", features = [ "debug", "debug_all", "mcpe" ] } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
use rak_rs::connection::Connection; | ||
use rak_rs::mcpe::motd::Gamemode; | ||
use rak_rs::Listener; | ||
|
||
#[async_std::main] | ||
async fn main() { | ||
// console_subscriber::init(); | ||
let mut server = Listener::bind("0.0.0.0:19133").await.unwrap(); | ||
server.motd.name = "RakNet Rust (async-std)!".to_string(); | ||
server.motd.gamemode = Gamemode::Survival; | ||
server.motd.player_count = 69420; | ||
server.motd.player_max = 69424; | ||
|
||
server.start().await.unwrap(); | ||
|
||
loop { | ||
let conn = server.accept().await; | ||
async_std::task::spawn(handle(conn.unwrap())); | ||
} | ||
} | ||
|
||
async fn handle(mut conn: Connection) { | ||
loop { | ||
// keeping the connection alive | ||
if conn.is_closed().await { | ||
println!("Connection closed!"); | ||
break; | ||
} | ||
if let Ok(pk) = conn.recv().await { | ||
println!("(RAKNET RECIEVE SIDE) Got a connection packet {:?} ", pk); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
[build] | ||
rustflags = ["--cfg", "tokio_unstable"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
[package] | ||
name = "raknet-test" | ||
version = "0.1.0" | ||
edition = "2021" | ||
|
||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html | ||
|
||
[dependencies] | ||
async-std = { version = "1.12.0", features = [ "attributes" ] } | ||
console-subscriber = "0.1.8" | ||
rak-rs = { path = "../../../", features = [ "debug", "debug_all", "mcpe", "async_tokio" ], default-features = false } | ||
tokio = "1.23.0" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
use rak_rs::Listener; | ||
use rak_rs::Motd; | ||
use rak_rs::connection::Connection; | ||
use rak_rs::mcpe; | ||
use rak_rs::mcpe::motd::Gamemode; | ||
use rak_rs::server::event::ServerEvent; | ||
use rak_rs::server::event::ServerEventResponse; | ||
|
||
|
||
#[tokio::main] | ||
async fn main() { | ||
console_subscriber::init(); | ||
let mut server = Listener::bind("0.0.0.0:19132").await.unwrap(); | ||
server.motd.name = "RakNet Rust (tokio)!".to_string(); | ||
server.motd.gamemode = Gamemode::Survival; | ||
|
||
server.start().await.unwrap(); | ||
|
||
loop { | ||
let conn = server.accept().await; | ||
tokio::task::spawn(handle(conn.unwrap())); | ||
} | ||
} | ||
|
||
async fn handle(mut conn: Connection) { | ||
loop { | ||
// keeping the connection alive | ||
if conn.is_closed().await { | ||
println!("Connection closed!"); | ||
break; | ||
} | ||
if let Ok(pk) = conn.recv().await { | ||
println!("(RAKNET RECIEVE SIDE) Got a connection packet {:?} ", pk); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
|
||
.warning-2 { | ||
background: rgba(255,240,76,0.34) !important; | ||
padding: 0.75em; | ||
border-left: 2px solid #fce811; | ||
} | ||
|
||
.warning-2 code { | ||
background: rgba(211,201,88,0.64) !important; | ||
} | ||
|
||
.notice-2 { | ||
background: rgba(76, 240, 255, 0.629) !important; | ||
padding: 0.75em; | ||
border-left: 2px solid #4c96ff; | ||
} | ||
|
||
.notice-2 code { | ||
background: rgba(88, 211, 255, 0.64) !important; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
<link rel="stylesheet" href="/resources/header.css"> |
Oops, something went wrong.