-
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.
Browse files
Browse the repository at this point in the history
- Loading branch information
Showing
23 changed files
with
1,343 additions
and
16 deletions.
There are no files selected for viewing
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 |
---|---|---|
|
@@ -5,6 +5,4 @@ target | |
Cargo.lock | ||
|
||
*.old/ | ||
*.profraw | ||
|
||
raknet-test/ | ||
*.profraw |
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
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_utils = { git = "https://github.com/NetrexMC/BinaryUtil", tag = "v0.2.2" } | ||
rakrs = { 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,14 @@ | ||
use rakrs::client::{Client, DEFAULT_MTU}; | ||
use std::net::ToSocketAddrs; | ||
|
||
#[async_std::main] | ||
async fn main() { | ||
let mut client = Client::new(10, DEFAULT_MTU); | ||
let mut addr = "zeqa.net:19132".to_socket_addrs().unwrap(); | ||
client.connect(addr.next().unwrap()).await.unwrap(); | ||
|
||
loop { | ||
let pk = client.recv().await.unwrap(); | ||
println!("Received 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,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" | ||
rakrs = { 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,31 @@ | ||
use rakrs::connection::Connection; | ||
use rakrs::mcpe::motd::Gamemode; | ||
use rakrs::Listener; | ||
|
||
#[async_std::main] | ||
async fn main() { | ||
// console_subscriber::init(); | ||
let mut server = Listener::bind("0.0.0.0:19132").await.unwrap(); | ||
server.motd.name = "RakNet Rust!".to_string(); | ||
server.motd.gamemode = Gamemode::Survival; | ||
|
||
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!("(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" | ||
rakrs = { 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,69 @@ | ||
use rakrs::Listener; | ||
use rakrs::Motd; | ||
use rakrs::connection::Connection; | ||
use rakrs::mcpe; | ||
use rakrs::mcpe::motd::Gamemode; | ||
use rakrs::server::event::ServerEvent; | ||
use rakrs::server::event::ServerEventResponse; | ||
|
||
|
||
#[tokio::main] | ||
async fn main() { | ||
console_subscriber::init(); | ||
let mut server = Listener::bind("0.0.0.0:19132").await.unwrap(); | ||
// let inner = server.recv_evnt.clone(); | ||
server.motd.name = "RakNet Rust!".to_string(); | ||
server.motd.gamemode = Gamemode::Survival; | ||
|
||
server.start().await.unwrap(); | ||
|
||
loop { | ||
// let mut recvr = inner.lock().await; | ||
// tokio::select! { | ||
// ev = recvr.recv() => { | ||
// match ev { | ||
// Some((event, shoot)) => { | ||
// match event { | ||
// ServerEvent::RefreshMotdRequest(_addr, mut motd) => { | ||
// // force update the motd!!! | ||
// motd.name = "You are a loser!!!!!!!!!".to_string(); | ||
// motd.player_max = 14_903; | ||
// motd.player_count = 0; | ||
// shoot.send(ServerEventResponse::RefreshMotd(motd)).unwrap(); | ||
// }, | ||
// _ => { | ||
// println!("Got a response!"); | ||
// // YOU NEED TO ALWAYS REPLY TO EVENTS | ||
// shoot.send(ServerEventResponse::Acknowledged); | ||
// } | ||
// } | ||
// }, | ||
// None => { | ||
// println!("Error!"); | ||
// break; | ||
// } | ||
// } | ||
// }, | ||
// connection = server.accept() => { | ||
// tokio::task::spawn(handle(connection.unwrap())); | ||
// } | ||
|
||
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!("(RAKNET RECIEVE SIDE) Got a connection packet {:?} ", pk); | ||
} | ||
// conn.tick().await; | ||
} | ||
} |
Oops, something went wrong.