Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

v3 Stable Release #35

Merged
merged 79 commits into from
Aug 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
79 commits
Select commit Hold shift + click to select a range
4b409e8
feat: v3 begins
john-bv Oct 23, 2022
884de38
feat: Add queues, states and the cache store
john-bv Oct 23, 2022
92bbf42
chore: Add existing packets from previous version
john-bv Oct 31, 2022
fe3c63c
fmt: cargo fmt
john-bv Oct 31, 2022
1700f37
feat: Start working on recovery queues
john-bv Nov 13, 2022
84c3d1c
feat(server): Server will now (sort of) handle connections (lol)
john-bv Dec 11, 2022
f61341a
fmt: Run formatter
john-bv Dec 11, 2022
f83898e
update(readme.md): Fix api
john-bv Dec 11, 2022
980ba73
feat: Unconnected pong
john-bv Dec 11, 2022
726b1c9
feat: Add connection handshake -skip
john-bv Dec 12, 2022
a4c1ebd
chore(README.md): Fix packaged name in example -skip
john-bv Dec 12, 2022
da51459
feat: Add ability to close server through sephamores and notifiers
john-bv Dec 12, 2022
bbec344
chore: Format proj
john-bv Dec 12, 2022
8fac407
chore: Add some debug logging + some additions to server & conn
john-bv Dec 25, 2022
804acb6
fmt: Run formatter
john-bv Dec 25, 2022
56e9ecc
bulk: Fix up some thing with debug and finished up connection hanshak…
john-bv Dec 26, 2022
67cb769
chore: update readme
john-bv Jan 1, 2023
5b4b3e1
chore: update readme
john-bv Jan 1, 2023
66f9168
bulk: Finishing up v3
john-bv Jan 3, 2023
a63fdbf
feat: Async-std
john-bv Jan 9, 2023
406179e
chore: Add moreee stufffff
john-bv Jan 9, 2023
5c37da9
feat: nasty hacks for both tokio and async std :)
john-bv Jan 9, 2023
7f716da
chore: fmt
john-bv Jan 9, 2023
40f8bba
chore: Stablize both async-std and tokio features (tokio still remain…
john-bv Jan 9, 2023
0abb6cd
🚀 feat: Async std
john-bv Jan 9, 2023
cd6153e
chore: Fix features
john-bv Jan 9, 2023
c60b39e
chore: Update readme
john-bv Jan 9, 2023
1ac4966
feat: Finishing up for a release?
john-bv Jan 11, 2023
4610a4d
chore: fmt, try to fix a dumb bug on win10
john-bv Jan 12, 2023
9a6144e
chore: locales
john-bv Jan 12, 2023
4c17c60
chore: locales
john-bv Jan 12, 2023
c96e26f
chore: fmt
john-bv Jan 12, 2023
38cb9f5
chore: Fix tests
john-bv Jan 14, 2023
426747f
chore(fmt)
john-bv Jan 14, 2023
162189e
chore: Bump version [ci skip]
john-bv Jan 14, 2023
c5ff04a
fuck you vscode
john-bv Jan 14, 2023
27a2139
feat: Fix tokio
john-bv Jan 14, 2023
ddb4e7a
feat: Client init [ci skip]
john-bv Jun 11, 2023
cc3f3b3
fmt(src/client/mod.rs): Format command [ci skip]
john-bv Jun 11, 2023
29e9de4
feat: Handshake
john-bv Jun 11, 2023
bc166d9
feat: client base completed
john-bv Jun 12, 2023
3fe357f
fmt: Run cargo fmt
john-bv Jun 12, 2023
de075a4
chore: Fix tokio
john-bv Jun 12, 2023
75c13fe
chore: Fix async std
john-bv Jun 12, 2023
8492dce
feat: client fixes
john-bv Jun 12, 2023
a449104
feat: client fixes and format [ci skip]
john-bv Jun 12, 2023
f61f51d
chore: fix NewIncomingConnection, breaks openconnectrequest, (fix next)
john-bv Jun 16, 2023
4d10ef7
feat: fix client
john-bv Jun 16, 2023
7189861
chore: bump version & prepare release v3 [ci skip]
john-bv Jun 17, 2023
87ad1ef
feat: Client connections, closing: #39, #40
john-bv Jun 17, 2023
41cf4ac
chore: fix head
john-bv Jun 17, 2023
117f400
chore: fix name [ci skip]
john-bv Jun 17, 2023
226e53b
chore: locales
john-bv Jun 19, 2023
549aa9b
client/mod.rs: Remove unecessary &mut receivers
AndreasHGK Jul 4, 2023
ac7c272
client/mod.rs: Remove unnecessary &mut receivers
john-bv Jul 4, 2023
9c64dc7
chore: attempt to fix nightly tests
john-bv Jul 4, 2023
4f500a5
chore(connection/mod.rs): remove mutability requirement
john-bv Jul 4, 2023
7f3b616
fmt(client/mod.rs): run format
john-bv Jul 4, 2023
4b993a6
feat: Minor improvements & timeouts
john-bv Jul 4, 2023
0ef6897
fmt(client/handshake): Formatting
john-bv Jul 4, 2023
5747b0b
chore: update dependencies
john-bv Jul 4, 2023
17d605f
chore: update dependencies [ci skip]
john-bv Jul 4, 2023
021145e
feat(notifiers): Fixes #44 only for async_std
john-bv Aug 9, 2023
5d5be75
chore(fmt): Format files using cargo
john-bv Aug 9, 2023
8476650
chore(fmt): Remove warnings [ci skip]
john-bv Aug 9, 2023
d7c856a
feat(src/notify): Add notifiers for tokio & cleanup conditional imports
john-bv Aug 10, 2023
c1b9a41
chore(fmt): Run cargo format
john-bv Aug 10, 2023
155d917
feat(notifiers): Actuall add the files...
john-bv Aug 10, 2023
4f7d949
chore: Modify protocol and update to bin-util v3 (pt 1)
john-bv Aug 10, 2023
76645ba
chore: more updates [ci skip]
john-bv Aug 10, 2023
8b5c90e
fix(notifiers): They now work on both async and tokio
john-bv Aug 11, 2023
fb0fcec
feat: binary_utils v3!
john-bv Aug 12, 2023
e03b054
merge(feat): update/binary-utils
john-bv Aug 12, 2023
a5f580d
chore: only debug this error, cause the reciever may not be listening…
john-bv Aug 13, 2023
63e7e2c
bug(server killing): Server will now kill clients properly
john-bv Aug 13, 2023
635ab1e
feat: start mtu discovery
john-bv Aug 13, 2023
fa30a2c
update resource
john-bv Aug 20, 2023
1d2ac3b
doc: Add documentation
john-bv Aug 21, 2023
af5dfba
doc(README.md): Update readme to contain right info
john-bv Aug 21, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added .github/resources/img/Connection Handshake.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
23 changes: 23 additions & 0 deletions .github/resources/mddoc/Raknet.md
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.
1 change: 1 addition & 0 deletions .github/resources/mddoc/protocol/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# RakNet Protocol
9 changes: 9 additions & 0 deletions .github/resources/mddoc/reliability.md
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
22 changes: 0 additions & 22 deletions .github/workflows/devskim-analysis.yml

This file was deleted.

2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
.DS_Store
target

# Ignore lock files
Cargo.lock

*.old/
*.profraw
11 changes: 0 additions & 11 deletions .vscode/settings.json

This file was deleted.

18 changes: 11 additions & 7 deletions Cargo.toml
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" ] }
352 changes: 178 additions & 174 deletions LICENSE.md

Large diffs are not rendered by default.

101 changes: 99 additions & 2 deletions README.md
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);
}
}
}
```
3 changes: 3 additions & 0 deletions coverage.py
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")
5 changes: 5 additions & 0 deletions examples/README.md
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)
11 changes: 11 additions & 0 deletions examples/async-std/client/Cargo.toml
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" ]}
19 changes: 19 additions & 0 deletions examples/async-std/client/src/main.rs
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();
}
}
2 changes: 2 additions & 0 deletions examples/async-std/server/.cargo/config.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[build]
rustflags = ["--cfg", "tokio_unstable"]
11 changes: 11 additions & 0 deletions examples/async-std/server/Cargo.toml
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" ] }
33 changes: 33 additions & 0 deletions examples/async-std/server/src/main.rs
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);
}
}
}
2 changes: 2 additions & 0 deletions examples/tokio/server/.cargo/config.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[build]
rustflags = ["--cfg", "tokio_unstable"]
12 changes: 12 additions & 0 deletions examples/tokio/server/Cargo.toml
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"
36 changes: 36 additions & 0 deletions examples/tokio/server/src/main.rs
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);
}
}
}
20 changes: 20 additions & 0 deletions resources/header.css
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;
}
1 change: 1 addition & 0 deletions resources/header.html
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<link rel="stylesheet" href="/resources/header.css">
Loading
Loading