generated from tipragot/rust
Simplify the relay server code (#41)
All checks were successful
Rust Checks / checks (push) Successful in 1m6s
All checks were successful
Rust Checks / checks (push) Successful in 1m6s
Reviewed-on: corentin/border-wars#41 Reviewed-by: Corentin <solois.corentin@gmail.com> Co-authored-by: Tipragot <contact@tipragot.fr> Co-committed-by: Tipragot <contact@tipragot.fr>
This commit is contained in:
parent
c0caed7622
commit
c2ace46c20
24
Cargo.lock
generated
24
Cargo.lock
generated
|
@ -475,18 +475,6 @@ dependencies = [
|
|||
"local-ip-address",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "bevnet-relay"
|
||||
version = "0.2.0"
|
||||
dependencies = [
|
||||
"axum",
|
||||
"dashmap",
|
||||
"futures",
|
||||
"lazy_static",
|
||||
"rand",
|
||||
"tokio",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "bevy"
|
||||
version = "0.12.1"
|
||||
|
@ -3617,6 +3605,18 @@ version = "0.8.2"
|
|||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "c08c74e62047bb2de4ff487b251e4a92e24f48745648451635cec7d591162d9f"
|
||||
|
||||
[[package]]
|
||||
name = "relay-server"
|
||||
version = "0.2.0"
|
||||
dependencies = [
|
||||
"axum",
|
||||
"dashmap",
|
||||
"futures",
|
||||
"lazy_static",
|
||||
"rand",
|
||||
"tokio",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "renderdoc-sys"
|
||||
version = "1.0.0"
|
||||
|
|
|
@ -1,38 +0,0 @@
|
|||
[package]
|
||||
name = "bevnet-relay"
|
||||
version = "0.2.0"
|
||||
edition = "2021"
|
||||
license = "GPL-3.0-or-later"
|
||||
description = "A relay server for bevnet."
|
||||
authors = ["Tipragot <contact@tipragot.fr>"]
|
||||
keywords = ["bevy", "network", "game"]
|
||||
categories = ["network-programming", "game-development"]
|
||||
|
||||
[lints]
|
||||
workspace = true
|
||||
|
||||
[dependencies]
|
||||
tokio = { version = "1.36.0", features = [
|
||||
"macros",
|
||||
"rt-multi-thread",
|
||||
], optional = true }
|
||||
axum = { version = "0.7.4", features = ["ws"], optional = true }
|
||||
lazy_static = { version = "1.4.0", optional = true }
|
||||
futures = { version = "0.3.30", optional = true }
|
||||
dashmap = { version = "5.5.3", optional = true }
|
||||
rand = { version = "0.8.5", optional = true }
|
||||
|
||||
[features]
|
||||
default = []
|
||||
server = [
|
||||
"dep:tokio",
|
||||
"dep:axum",
|
||||
"dep:lazy_static",
|
||||
"dep:futures",
|
||||
"dep:dashmap",
|
||||
"dep:rand",
|
||||
]
|
||||
|
||||
[[bin]]
|
||||
name = "server"
|
||||
required-features = ["server"]
|
20
crates/relay-server/Cargo.toml
Normal file
20
crates/relay-server/Cargo.toml
Normal file
|
@ -0,0 +1,20 @@
|
|||
[package]
|
||||
name = "relay-server"
|
||||
version = "0.2.0"
|
||||
edition = "2021"
|
||||
license = "GPL-3.0-or-later"
|
||||
description = "A relay server for bevnet."
|
||||
authors = ["Tipragot <contact@tipragot.fr>"]
|
||||
keywords = ["bevy", "network", "game"]
|
||||
categories = ["network-programming", "game-development"]
|
||||
|
||||
[lints]
|
||||
workspace = true
|
||||
|
||||
[dependencies]
|
||||
tokio = { version = "1.36.0", features = ["macros", "rt-multi-thread"] }
|
||||
axum = { version = "0.7.4", features = ["ws"] }
|
||||
lazy_static = "1.4.0"
|
||||
futures = "0.3.30"
|
||||
dashmap = "5.5.3"
|
||||
rand = "0.8.5"
|
|
@ -10,7 +10,6 @@ use lazy_static::lazy_static;
|
|||
use rand::Rng;
|
||||
use tokio::sync::mpsc::{channel, Receiver, Sender};
|
||||
use tokio::task::JoinHandle;
|
||||
use uuid::Uuid;
|
||||
|
||||
lazy_static! {
|
||||
static ref CLIENTS: DashMap<u32, Sender<Vec<u8>>> = DashMap::new();
|
||||
|
@ -19,7 +18,7 @@ lazy_static! {
|
|||
#[tokio::main]
|
||||
async fn main() {
|
||||
let app = Router::new().route(
|
||||
"/relay",
|
||||
"/",
|
||||
get(|ws: WebSocketUpgrade| async { ws.on_upgrade(handle) }),
|
||||
);
|
||||
let listener = tokio::net::TcpListener::bind("0.0.0.0:80")
|
Loading…
Reference in a new issue